2

I wanted to know how I can read data matrix bar code using openCV in python

I've found How to locate and read Data Matrix code with python but this is still unclear for me. I would like to show the result of reading bar code to output.

trieser
  • 111
  • 2
  • 6
  • you sample data? What you've tried? What's error message? – Sixiang.Hu Feb 08 '18 at 13:40
  • Sample data image.png I tried to decode data matrix, I get only result 5 pictures like this guy on second post. I would like to decode data matrix, but I have no Idea how i can do that. Do you know some tutorial to do this? – trieser Feb 09 '18 at 07:16

2 Answers2

7

Ok after few days I've found resolution:

import cv2
from pylibdmtx.pylibdmtx import decode
import ctypes  

def Mbox(title, text, style):
    return ctypes.windll.user32.MessageBoxW(0, text, title, style)

# Read file using OpenCV
Mbox('Data Matrix', str(decode(cv2.imread('C:/Users/User/Desktop/Zdjecia_QrCode/again2.png'))), 1)

But I would like to know how I can improve reading because I cannot read every datamatrix. Do you have any idea?

trieser
  • 111
  • 2
  • 6
  • Have you finally found a solution? I am facing similar issues. I can read some Data Matrix, but not all of them! I would appreciate if you can share your experience. – TwinPenguins Aug 22 '19 at 13:58
2
import numpy as np
import cv2
from pylibdmtx import pylibdmtx

if __name__ == '__main__':

    image = cv2.imread('datamatrix_sample1_130x116.png', cv2.IMREAD_UNCHANGED);

    gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    ret,thresh = cv2.threshold(gray, 0, 255, cv2.THRESH_BINARY | cv2.THRESH_OTSU)

    msg = pylibdmtx.decode(thresh)
    print(msg)
Suraj Rao
  • 29,388
  • 11
  • 94
  • 103
Anand Raj
  • 41
  • 3