如何在Python中读取数据矩阵代码?

时间:2018-02-08 13:25:34

标签: python opencv datamatrix

我想知道如何在python中使用openCV读取数据矩阵条形码

我发现了How to locate and read Data Matrix code with python,但这对我来说仍然不清楚。我想显示读取条形码的结果输出。

2 个答案:

答案 0 :(得分:5)

好几天后我找到了解决方案:

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)

但我想知道如何改进阅读,因为我无法阅读每一个数据矩阵。你有什么想法吗?

答案 1 :(得分:0)

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)