1

I am trying to read datamatrix code by rasp using python.

I'm using pylibdmtx to read the code, but it only works on my notebook. When I put the same code on the raspberry it can't read the code. At the moment my raspberry is reading only qrcode and barcode.

I have two rasp one with raspbian and the other with ubuntu core, neither of which worked.

An example code below

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)
Vega
  • 27,856
  • 27
  • 95
  • 103

3 Answers3

0

pylibdmtx is just a wrapper for libdmtx. To make it work, you have to install the native library first.

The .whl file has already contained the .DLL file for Windows:

enter image description here

As for macOS and Linux, you can install the library via command-line tools.

Mac OS X:

brew install libdmtx

Linux:

sudo apt-get install libdmtx0a

I suppose there's no pre-built library for Raspberry Pi. So you can build it by yourself. Here is the source code:

https://github.com/dmtx/libdmtx

Take 3 steps to build and install the libdmtx library:

  $ ./configure
  $ make
  $ sudo make install

After installing the libdmtx library, your Python code should work.

yushulx
  • 11,695
  • 8
  • 37
  • 64
  • Thanks for the feedback, however I already discovered the problem, it was a bit complex to find but I managed, inside the wrapper.py of pylibdmtx the class DmtxTime was in trouble, after correcting the rasp started reading the codes. – Fillipi Nascimento Feb 15 '20 at 20:26
0
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)
0
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)