Pyzbar 将 EAN-13 条码识别为 PDF417?
Pyzbar recognizes EAN-13 barcode as PDF417?
我正在尝试使用 pyzbar 构建实时条形码 reader。我只有 EAN-13 条形码,其中一些条形码被正确读取,但有些被识别为 PDF417,我收到此消息:
警告:.\zbar\decoder\pdf417.c:89::断言“g[0] >= 0 && g[1] >= 0 && g[2] >= 0”失败
如何提高效率?也许我可以使用另一个 python 库?
这是我的代码:
import cv2
import numpy as np
from pyzbar.pyzbar import decode
def decoder(image):
imgGray = cv2.cvtColor(image,0)
barcodes = decode(imgGray)
for barcode in barcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(imgGray, (x-10, y-10),
(x + w+10, y + h+10),
(255, 0, 0), 2)
if barcode.data!="":
print("Barcode: ", barcode.data)
print(barcode.type)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
decoder(frame)
cv2.imshow('Image', frame)
code = cv2.waitKey(10)
if code == ord('q'):
break
如果你只有 EAN-13,你可以指定这样 pyzbar 将只检查 EAN-13。您可以在调用 decode(...)
.
时将列表中的所需代码指定给参数 symbols
from pyzbar.pyzbar import decode, ZBarSymbol
import cv2
image = cv2.imread("testImage.png")
decode(image, symbols=[ZBarSymbol.ZBAR_EAN13])
(凭记忆写的代码,如果符号不完全正确,请见谅)
另一个要测试的库是 zxing。在我的测试中,zxing 比 zbar 慢得多,但得到了更好的结果。
我正在尝试使用 pyzbar 构建实时条形码 reader。我只有 EAN-13 条形码,其中一些条形码被正确读取,但有些被识别为 PDF417,我收到此消息: 警告:.\zbar\decoder\pdf417.c:89::断言“g[0] >= 0 && g[1] >= 0 && g[2] >= 0”失败 如何提高效率?也许我可以使用另一个 python 库?
这是我的代码:
import cv2
import numpy as np
from pyzbar.pyzbar import decode
def decoder(image):
imgGray = cv2.cvtColor(image,0)
barcodes = decode(imgGray)
for barcode in barcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(imgGray, (x-10, y-10),
(x + w+10, y + h+10),
(255, 0, 0), 2)
if barcode.data!="":
print("Barcode: ", barcode.data)
print(barcode.type)
cap = cv2.VideoCapture(0)
while True:
ret, frame = cap.read()
decoder(frame)
cv2.imshow('Image', frame)
code = cv2.waitKey(10)
if code == ord('q'):
break
如果你只有 EAN-13,你可以指定这样 pyzbar 将只检查 EAN-13。您可以在调用 decode(...)
.
symbols
from pyzbar.pyzbar import decode, ZBarSymbol
import cv2
image = cv2.imread("testImage.png")
decode(image, symbols=[ZBarSymbol.ZBAR_EAN13])
(凭记忆写的代码,如果符号不完全正确,请见谅)
另一个要测试的库是 zxing。在我的测试中,zxing 比 zbar 慢得多,但得到了更好的结果。