[英]pyzbar not detecting Code93 barcodes
I'm trying to use the library to decode Code93 barcodes but the library is not being able to detect it.我正在尝试使用该库来解码 Code93 条形码,但该库无法检测到它。 I looked at the source code and apparently it's able to scan this type of barcode.
我查看了源代码,显然它能够扫描这种类型的条形码。 Is there something wrong with my environment or the way I'm using the library?
我的环境或我使用图书馆的方式有问题吗?
I am using the version 0.1.8 of pyzbar along with python 3.7.3 and load using:我正在使用 pyzbar 的 0.1.8 版本和 python 3.7.3 并使用以下方式加载:
from pyzbar import pyzbar
from pyzbar.pyzbar import ZBarSymbol
barcodes = pyzbar.decode(cv2.imread(pic_path), symbols=[ZBarSymbol.CODE93])
The image I am using:我正在使用的图像:
I know this is detectable because this website can read normally.我知道这是可以检测到的,因为该网站可以正常阅读。
You're using the library OK, but your image needs some pre-processing to make the bar-code readable.您正在使用库,但您的图像需要一些预处理才能使条形码可读。 You need to increase the contrast between the black and white bars, which can be done using a threshold filter to binarize the image before passing it to pyzbar.
您需要增加黑白条之间的对比度,这可以在将图像传递给 pyzbar 之前使用阈值过滤器对图像进行二值化来完成。 This example, using the OpenCV library, worked for me with your sample image:
此示例使用 OpenCV 库,对我使用您的示例图像:
import cv2
from pyzbar.pyzbar import decode
from pyzbar.pyzbar import ZBarSymbol
pic_path = "UNENg.png"
# preprocessing using opencv
im = cv2.imread(pic_path, cv2.IMREAD_GRAYSCALE)
ret, bw_im = cv2.threshold(im, 127, 255, cv2.THRESH_BINARY)
# zbar
barcodes = decode(bw_im, symbols=[ZBarSymbol.CODE93])
There are some alternative pre-processing methods in the answer to Preprocessing images for QR detection in python which might also be helpful. 在 Python 中预处理图像以进行 QR 检测的答案中有一些替代的预处理方法,这也可能会有所帮助。
For QR codes using ZBarSymbol works the same principle对于使用ZBarSymbol 的二维码,原理相同
img = cv2.imread(img_fn,cv2.IMREAD_GRAYSCALE)
ret, bw_im = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
barcodes = pyzbar.decode(bw_im, symbols=[ZBarSymbol.QRCODE])
I have a problem whith my Code39 Barcode.我的 Code39 条码有问题。
I try to modify threshold, colors, size.我尝试修改阈值、颜色、大小。 I also try to reconstruct the barcode.
我也尝试重建条形码。
On https://wabr.inliteresearch.com/ , it's ok.在https://wabr.inliteresearch.com/ 上,没关系。 but not with Pyzbar.
但不是与 Pyzbar。
My CodeBar is not recognized by Pyzbar. Pyzbar 无法识别我的 CodeBar。
Anyone could say why ?任何人都可以说为什么?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.