[英]Pyzbar recognizes EAN-13 barcode as PDF417?
I'm trying to build a realtime barcode reader using pyzbar.我正在尝试使用 pyzbar 构建实时条形码阅读器。 I have only EAN-13 barcodes and some of them are read properly but some are recognized as PDF417 and I get this message: WARNING: .\zbar\decoder\pdf417.c:89: : Assertion "g[0] >= 0 && g[1] >= 0 && g[2] >= 0" failed How to increase efficiency?
我只有 EAN-13 条形码,其中一些被正确读取,但有些被识别为 PDF417,我收到以下消息: WARNING: .\zbar\decoder\pdf417.c:89: : Assertion "g[0] >= 0 && g[1] >= 0 && g[2] >= 0" failed如何提高效率? Maybe there is another python library which I can use?
也许我可以使用另一个 python 库?
This is my code:这是我的代码:
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
If you only have EAN-13, you could specify that so pyzbar would only check for EAN-13.如果你只有 EAN-13,你可以指定这样 pyzbar 只会检查 EAN-13。 You can specify the desired codes in a list to the parameter
symbols
when calling decode(...)
.您可以在调用
decode(...)
时在参数symbols
列表中指定所需的代码。
from pyzbar.pyzbar import decode, ZBarSymbol
import cv2
image = cv2.imread("testImage.png")
decode(image, symbols=[ZBarSymbol.ZBAR_EAN13])
(Code written from memory, sorry if eg the symbol isn't exactly right) (从 memory 编写的代码,抱歉,如果符号不完全正确)
Another library to test would be zxing .另一个要测试的库是zxing 。 In my tests zxing was much slower than zbar but got better results.
在我的测试中,zxing 比 zbar 慢得多,但得到了更好的结果。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.