Win 10 x64,Python 2.7,Spyder IDE
我正在使用Adrian Rosebrock的OpenCV博客中的一些代码...
import pyzbar
import cv2
# load the input image
image = cv2.imread("barcode_example.png")
# find the barcodes in the image and decode each of the barcodes
barcodes = pyzbar.pyzbar.decode(image)
# loop over the detected barcodes
for barcode in barcodes:
# extract the bounding box location of the barcode and draw the
# bounding box surrounding the barcode on the image
(x, y, w, h) = barcode.rect
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 0, 255), 2)
# the barcode data is a bytes object so if we want to draw it on
# our output image we need to convert it to a string first
barcodeData = barcode.data.decode("utf-8")
barcodeType = barcode.type
# draw the barcode data and barcode type on the image
text = "{} ({})".format(barcodeData, barcodeType)
cv2.putText(image, text, (x, y - 10), cv2.FONT_HERSHEY_SIMPLEX,
0.5, (0, 0, 255), 2)
# show the output image
cv2.imshow("Image", image)
cv2.waitKey(0)
我不断收到以下错误信息...
AttributeError: 'module' object has no attribute 'pyzbar'
但是,当我在Spyder中检查模块时,确实确实说到了artifute ...
我尝试从命令行运行,结果相同。
我还检查了我的zbar安装是否正常并且没有问题
这是Python绑定问题还是真的很明显?
答案 0 :(得分:0)
尝试:
import pyzbar.pyzbar as pyzbar
为我工作。