python-pillow / Pillow

Python Imaging Library (Fork)
https://python-pillow.org
Other
12.2k stars 2.22k forks source link

barcode recognition #1537

Closed vashek closed 8 years ago

vashek commented 8 years ago

In a project that already processes images using Pillow (using Python 2.7 on Windows, for now), I now need to implement barcode recognition (for now at least simple 1D barcodes, but apparently a request for QR codes will come later, too). Just wondering, does anyone have any experience or at least a good idea how to do this reliably and efficiently? I am aware of zbar an zxing, but in both cases (AFAIK) I basically have to call a separate .exe and pass it an image file. I wonder if there is a more straightforward solution. Thanks.

wiredfool commented 8 years ago

There are at least a couple of ways. I've done it in pure python + PIL (in 2006!?) for at least one symbology: http://www.wiredfool.com/2006/07/04/barcode-recognition/ . That's not the most robust solution, nor is it likely the fastest, but it's been pretty successful in the application that's it's been used for.

I've also done some interfacing with pydmtx for 2d barcodes. IIRC, it's pretty straight forward.

vashek commented 8 years ago

Wow, thanks! I was considering trying to do a pure-Python implementation but assumed it would be too slow and/or difficult. I have enhanced your code to find the Code 39 barcode anywhere in the image (even if there is other stuff next to it on the scan line). That does make it much slower when it searches a whole page in vain, but hopefully still acceptable for my purpose. I'm sure there are much more efficient ways to do it, mine is pretty naive. If anyone's interested, I'll be happy to provide the code.