我正在尝试使用python通过rasp读取datamatrix代码。
我使用pylibdmtx来读取代码,但它只适用于我的笔记本电脑。当我把同样的代码放在树莓上时,它无法读取代码。目前,我的树莓只能读取qrcode和barcode。
我有两个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)发布于 2020-02-10 11:45:51
pylibdmtx只是libdmtx的一个包装器。要使其正常工作,您必须首先安装本地库。
.whl文件已经包含了适用于Windows的.DLL文件:

对于macOS和Linux,您可以通过命令行工具安装库。
Mac OS X
brew install libdmtxLinux
sudo apt-get install libdmtx0a我想没有为Raspberry Pi预构建库。因此,您可以自己构建它。源代码如下:
https://github.com/dmtx/libdmtx
执行3个步骤来构建和安装libdmtx库:
$ ./configure
$ make
$ sudo make install安装libdmtx库之后,Python代码应该可以工作了。
发布于 2021-06-24 13:55:59
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)发布于 2021-06-28 12:46:50
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)https://stackoverflow.com/questions/59989893
复制相似问题