Polyconseil / zbarlight

A simple wrapper for zbar
BSD 3-Clause "New" or "Revised" License
163 stars 37 forks source link

QR code image coule not be decode #13

Open mengyyy opened 7 years ago

mengyyy commented 7 years ago

System: Ubuntu 16.04.3 LTS Python: Python 3.5.2 zbarlight==1.2 Pillow==4.2.1 lib: libzbar-dev/xenial,now 0.10+doc-10ubuntu1 amd64 [installed] libzbar0/xenial,now 0.10+doc-10ubuntu1 amd64 [installed]

First: I meet a strange image coule not be decoded. But i use telegram to send this image ,and use my bot to get it .It convert to jpeg by the telegram client and it could be decode success. So I try to convert the raw png to jpeg by image.convert('RGB'), but this jpeg image fail decode .

The raw png image file: (failed decode) qr_code_for_mobile_english_wikipedia svg Convert by telegram Android client jpg file:(success decode) photo_2017-08-09_14-25-22

Second: I also found a image decode failed without any process, but after i use image.thumbnail() it could be decode success. qrcode

Part of my code:

remote_image = requests.get(url)
image_file = io.BytesIO(remote_image.content)
image = Image.open(image_file)
image.load()
zbarlight.scan_codes('qrcode', image)
image.thumbnail((int(image.size[0]/8), int(image.size[1]/8)))
zbarlight.scan_codes('qrcode', image)
fbochu commented 7 years ago

Hi, thanks for the report.

I reproduce the issue with the two files. I have create PR #14 to investigate the issues.

For the first file, I believe that the problem is due to the gray scale conversion which in this case set the background to black (setting the background color to white resolve the issue, see the test_need_conversion_to_jpg_sample test). For the second one, I do not have any idea.

mengyyy commented 7 years ago

Thank you solve the first one. For the second one,i found whne its sise >(600,600) decode fail, but when its size turn to (599,599) or less, decode success.

fbochu commented 7 years ago

When adding a black border of 5px around the QR Code, the code is correctly decoded. But when adding a white border even a 1000px one, the code can not be read... This is surprising !

It's seem to be a bug or misusage of the Zbar library, but I have not find anything relative to this issue in the documentation or in the bug tracker. Unfortunately it's seem that there are not activity on the Zbar library since October 2012 (5 years ago).

This bug is beyond my expertise, I sorry that I can not help you more.

AndreMiras commented 5 years ago

What about the forks? That one seems maintained for instance https://github.com/mchehab/zbar Edit 1: to give more context I saw it here https://github.com/ZBar/ZBar/pull/17 Edit 2: I saw that you guys started taking a look, that's awesome 9496c4ee7183c14d1b073b42d423207bb81a1ca8 keep up the good work :beer: