【问题标题】:Datamatrix with raspberry带有覆盆子的数据矩阵
【发布时间】:2020-01-30 15:59:05
【问题描述】:

我正在尝试使用 python 通过 rasp 读取数据矩阵代码。

我正在使用 pylibdmtx 来阅读代码,但它只适用于我的笔记本。当我将相同的代码放在覆盆子上时,它无法读取代码。目前我的树莓派只能读取二维码和条形码。

我有两个 rasp 一个用 raspbian 另一个用 ubuntu 内核,这两个都不起作用。

下面的示例代码

import cv2
import time
from pylibdmtx.pylibdmtx import decode


data = None

video = cv2.VideoCapture(0)
video.set(cv2.CAP_PROP_FPS, 19)

while video.isOpened():
    time.sleep(1/9)
    ret, frame = video.read()
    if ret is False:
        break

    decodeObjects = decode(frame,
                           timeout=1000,
                           max_count=1,
                           corrections=3)

    for obj in decodeObjects:
        if obj.data:
            data = obj

    if data:
        break

video.release()
cv2.destroyAllWindows()
print(data)

【问题讨论】:

    标签: python-3.x opencv raspberry-pi3 qr-code datamatrix


    【解决方案1】:

    pylibdmtx 只是 libdmtx 的包装器。要使其工作,您必须先安装本机库。

    .whl 文件已包含适用于 Windows 的 .DLL 文件:

    对于 macOS 和 Linux,您可以通过命令行工具安装该库。

    Mac OS X

    brew install libdmtx
    

    Linux

    sudo apt-get install libdmtx0a
    

    我想 Raspberry Pi 没有预构建的库。所以你可以自己构建它。以下是源代码:

    https://github.com/dmtx/libdmtx

    通过 3 个步骤构建和安装 libdmtx 库:

      $ ./configure
      $ make
      $ sudo make install
    

    安装 libdmtx 库后,您的 Python 代码应该可以工作了。

    【讨论】:

    • 感谢您的反馈,但是我已经发现了问题,找到它有点复杂,但我管理,在 pylibdmtx 的 wrapper.py 中,类 DmtxTime 在更正 rasp 后出现了问题开始阅读代码。
    【解决方案2】:
    import cv2
    import time
    from pylibdmtx.pylibdmtx import decode
    
    data = None
    
    video = cv2.VideoCapture(0)
    video.set(cv2.CAP_PROP_FPS, 19)
    
    # Add
    saveFilename = "./liveImage.jpg"
    
    while video.isOpened():
        time.sleep(1/9)
        ret, frame = video.read()
        if ret is False:
            break
    
        # Add - save Live Image
        liveImage = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imwrite(saveFilename, liveImage)
        
        # Add - open File
        loadImage = cv2.imread(saveFilename)    
        
        # Modify
        decodeObjects = decode(loadImage,
                               timeout=1000,
                               max_count=1,
                               corrections=3)
    
        for obj in decodeObjects:
            if obj.data:
                data = obj
    
        if data:
            break
    
    video.release()
    cv2.destroyAllWindows()
    print(data)
    

    【讨论】:

    • 您能总结一下您所做的不同之处并提供参考文档吗?
    【解决方案3】:
    import cv2
    import time
    from pylibdmtx.pylibdmtx import decode
    
    data = None
    
    video = cv2.VideoCapture(0)
    video.set(cv2.CAP_PROP_FPS, 19)
    
    # Add
    saveFilename = "./liveImage.jpg"
    
    while video.isOpened():
        time.sleep(1/9)
        ret, frame = video.read()
        if ret is False:
            break
    
        # Add - save Live Image
        liveImage = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
        cv2.imwrite(saveFilename, liveImage)
        
        # Add - open File
        loadImage = cv2.imread(saveFilename)    
        
        # Modify
        decodeObjects = decode(loadImage,
                      # Delete timeout=1000, 
                               max_count=1,
                               corrections=3)
    
        for obj in decodeObjects:
            if obj.data:
                data = obj
    
        if data:
            break
    
    video.release()
    cv2.destroyAllWindows()
    print(data)
    

    【讨论】:

      猜你喜欢
      • 2012-03-16
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 2017-08-18
      • 2015-02-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多