类型错误:无法解包非可迭代的NoneType对象Zbar树莓派pi

2024-05-16 23:53:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我知道这已经被问过了,但我仍然不能让它在我的代码工作。。。我试图让我的树莓皮QRcode选择器为学校项目,当我运行我的代码

from pyzbar import pyzbar
import argparse
import cv2

#code
ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", required=True,
    help="chemin de l'image")
args = vars(ap.parse_args())

#load l'image
image=cv2.imread(args["image"])

#trouver lesQR/barcode dans l'image puisles decoder
barcodes=pyzbar.decode(image)

#loop barcode
for barcode in barcodes:
    #extraire les box des coins et faire un carre rouge autour du
    #barcode reconnu
    (x,y,w,h)=barcode.rect
    cv2.rectangle(image, (x,y),(x+w,y+h),(0,0,255), 2)

    #barcode est un byte donc besoin convertir en string en premier
    barcodeData=barcode.data.decode("utf=8")
    barcodeType=barcode.type

    #dessiner data barcode et ecrire sur image
    text="{}({})".format(barcodeData,barcodeType)
    cv2.putText(image,text,(x,y-10),cv2.FONT_HERSHEY_SIMPLEX,
        0.5, (0,0,255),2)

    print("[INFO] {} code, contenu: {}".format(barcodeType,barcodeData))

#montrer output
cv2.imshow("Image",image)
cv2.waitKey(0)

但当我运行“python条形码扫描器”_图片.py--图像测试.png,我得到的只是一个错误

       File "barcode_scanner_image.py", line 16, in <module>
              barcodes=pyzbar.decode(image)
       File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/pyzbar/pyzbar.py", line 181, in decode
              pixels, width, height = _pixel_data(image)
       File "/home/pi/.virtualenvs/cv/lib/python3.7/site-packages/pyzbar/pyzbar.py", line 147, in _pixel_data
              pixels, width, height = image
TypeError: Cannot unpack non-iterable NoneType object

请帮忙


Tags: inpyimageimportdataargscv2barcode
1条回答
网友
1楼 · 发布于 2024-05-16 23:53:00

所以我没有完整的答案-但是这里的一个评论是正确的。你知道吗

如果使用实际路径image=cv2.imread('/home/pi/foo/bar')

它起作用了(或者至少对我起作用了)。你知道吗

希望这有帮助!你知道吗

相关问题 更多 >