i am making a barcode reader with pyzbar and opencv but when i use decode function from pyzbar.pyzbar i get this error:
Traceback (most recent call last):
File "c:\Users\galax\Documents\barcodeScanner\barcodeReader.py", line 44, in <module>
BarcodeReader(image)
File "c:\Users\galax\Documents\barcodeScanner\barcodeReader.py", line 12, in BarcodeReader
detectedBarcodes = decode(img)
File "C:\Users\galax\AppData\Local\Programs\Python\Python310\lib\site-packages\pyzbar\pyzbar.py", line 207, in decode
pixels, width, height = _pixel_data(image)
File "C:\Users\galax\AppData\Local\Programs\Python\Python310\lib\site-packages\pyzbar\pyzbar.py", line 173, in _pixel_data
pixels, width, height = image
TypeError: cannot unpack non-iterable NoneType object
this is my code:
# Importing library
import cv2
from pyzbar.pyzbar import decode
# Make one method to decode the barcode
def BarcodeReader(image):
# read the image in numpy array using cv2
img = cv2.imread(image)
# Decode the barcode image
detectedBarcodes = decode(img)
# If not detected then print the message
if not detectedBarcodes:
print("Barcode Not Detected or your barcode is blank/corrupted!")
else:
# Traverse through all the detected barcodes in image
for barcode in detectedBarcodes:
# Locate the barcode position in image
(x, y, w, h) = barcode.rect
# Put the rectangle in image using
# cv2 to highlight the barcode
cv2.rectangle(img, (x-10, y-10),
(x + w+10, y + h+10),
(255, 0, 0), 2)
if barcode.data!="":
# Print the barcode data
print(barcode.data)
print(barcode.type)
#Display the image
cv2.imshow("Image", img)
cv2.waitKey(0)
cv2.destroyAllWindows()
if __name__ == "__main__":
# Take the image from user
image="barcode.png"
BarcodeReader(image)
i have already tried uninstalling and installing pyzbar, but i didnt had any succes either...
any help would be appreciated
