NaturalHistoryMuseum / pyzbar

Read one-dimensional barcodes and QR codes from Python 2 and 3.
MIT License
718 stars 175 forks source link

Inconsistent dimensions while using ByteIO as Image Object #132

Open schui95 opened 2 years ago

schui95 commented 2 years ago

Hello everyone!

My raspberry pi with the library picamera is creating a lot of pictures and stores them as ByteIO objects. Next step would be to decode those objects with this library pyzbar to get the qr code content. Unfortunately the dimension is always wrong and I don't know how to fix that issue. The pictures have the correct dimension and I guess the transformation/conversion is not correct?

My code:

`stream = BytesIO() camera = PiCamera() camera.resolution = (300, 300) camera.start_preview() camera.capture(stream, 'jpeg')

image = (stream.getbuffer(), 300, 300) barcodes = pyzbar.decode(image, symbols=[ZBarSymbol.QRCODE]) `

Error mesage: raise PyZbarError(pyzbar.pyzbar_error.PyZbarError: Inconsistent dimensions: image data of 4124 bytes is not divisible by (width x height = 90000)

I hope there is a solution for this problem. I assumed that pyzbar can handle this type of object, because 'raw bytes' are like ByteIO objects. A simple example on how to use this library pyzbar with raw bytes would be awesome!

Thanks for any advice or clarification!