提问人:Zaryab Ali 提问时间:11/7/2023 最后编辑:Christoph RackwitzZaryab Ali 更新时间:11/7/2023 访问量:70
在python中解码pdf417条形码
Decoding pdf417 barcode in python
问:
我在浏览器上搜索了很多,以找到一些在 python 中读取/解码 pdf417 条形码的方法 - 但没有任何效果。
首先,我尝试了简单的模块“pyzbar”:
import cv2
from pyzbar.pyzbar import decode
imagePath = '/home/zaryab/Downloads/barcode.png'
img = cv2.imread(imagePath)
detectedBarcodes = decode(img)
if not detectedBarcodes:
print("Barcode Not Detected or your barcode is blank/corrupted!")
else:
for barcode in detectedBarcodes:
(x, y, w, h) = barcode.rect
cv2.rectangle(img, (x-10, y-10),
(x + w+10, y + h+10),
(255, 0, 0), 2)
if barcode.data!="":
print(barcode.data)
print(barcode.type)
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
上面的代码适用于 code128 类型的条形码,但不适用于 pdf417 条形码。
然后我尝试了模块'pdf417decoder:
from PIL import Image as PIL
from pdf417decoder import PDF417Decoder
imagePath = '/home/zaryab/Downloads/barcode.png'
image = PIL.open(imagePath)
decoder = PDF417Decoder(image)
if (decoder.decode() > 0):
decoded = decoder.barcode_data_index_to_string(0)
print(decoded)
else:
print("No Barcode Found!")
这也不起作用,总是进入其他部分并打印“未找到条形码!
我应该怎么做才能解码 pdf417 条形码?
答: 暂无答案
评论