zplab / zbar-py

Simple python 2 and 3 compatible interface to the zbar barcode-reading library
MIT License
82 stars 30 forks source link

`scanner.scan(image)` ValueError: too many values to unpack #5

Closed moin18 closed 5 years ago

moin18 commented 7 years ago

On OS X, with python 2.7 I am getting below error while running scanner.scan(...) function

>>> import cv2
>>> image = cv2.imread("/Users/mquadri/Desktop/pepsi_barcode.jpeg")
>>> import zbar

>>> scanner = zbar.Scanner()

>> results = scanner.scan(image)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/mquadri/workspace/yolovenv/lib/python2.7/site-packages/zbar/zbar.py", line 191, in scan
    height, width = image.shape
ValueError: too many values to unpack
>>> image.shape
(183, 275, 3)

Any idea on how to fix it?

PS: On using the imread() function from the example code, it is working fine

GuganVignesh commented 7 years ago

zbar-py does accept only the grayscale images read into 2d-array :100:

so use the following to read the image im = cv2.imread('/Users/mquadri/Desktop/pepsi_barcode.jpeg', cv2.CV_LOAD_IMAGE_GRAYSCALE)

mujeeb91 commented 5 years ago

CV_LOAD_IMAGE_GRAYSCALE has been replaced with IMREAD_GRAYSCALE