我正在尝试使用python通过rasp读取datamatrix代码。
我正在使用pylibdmtx读取代码,但是它只能在我的笔记本上使用。当我在覆盆子上放置相同的代码时,它无法读取该代码。目前,我的树莓只读取qrcode和条形码。
我有两个锉刀,一个是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)
答案 0 :(得分:0)
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代码应该可以使用。
答案 1 :(得分: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)
答案 2 :(得分: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)