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.
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.
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?
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)