Join 3,374 readers in helping fund MetaFilter (Hide)

Open-source library to decode barcodes?
December 3, 2008 11:24 AM   Subscribe

Is there a free library that will decode/read a barcode from an image?

I am looking for a library that, when given an image of a barcode (not from a barcode scanner) as an argument, will return the barcode number. I would prefer if it was in Python or Ruby, but other languages are ok too.
posted by Maia to Computers & Internet (5 answers total) 4 users marked this as a favorite
Zebra Crossing is a Java library for doing just that.
posted by jedicus at 11:34 AM on December 3, 2008

BarBara. Works with the .NOT framework, even! Does it really have to be open source? There are a lot of shareware barcode readers that work very well, have been around a long time and can integrate with whatever. What are you trying to do?
posted by ostranenie at 11:46 AM on December 3, 2008

Oh, you're right, it doesn't have to be open-source.
posted by Maia at 11:47 AM on December 3, 2008

Oh, dang, I wrote one of these in Python. It wasn't fast, as it scanned the entire image, but it worked, for the most part.

I'll look for it, but you can probably make it yourself. ... Can't find it.

Off the top of my head, import PIL, read in the image, every so many lines, take the red channel (I figured most barcodes were designed to reflect red light as "on") intensities, with above some threshhold as "line" and below some as "gap".

There are guide bars on UPC bar code blocks that signal the smallest width of any line. Look for those patterns as a signal to start trying there, and as a signal of how wide the lines are. Use that with some fuzziness to read the next so many 1s/0s as some length of bar or gap. Decode a segment, verify the checksum, and if it checks, return it as success. If you read for so may contiguous pixels without a change, then you're not in a barcode, so abort to the higher loop.

I remember making a dictionary of something like { (2, 3, 1, 2): 4 }, that is, empty for 2, bar for 3, empty for 1, bar for 2 == digit 4 -- or something like that. Wikipedia was my pal for decoding.

I also made the various parameters to me parameters to the scan function, so if it failed for white/black threshold=80%, then I could try again for 70%.

The only hard part is dealing with fuzziness and bar/gap changes in the middle of pixels. Good luck.
posted by cmiller at 11:48 AM on December 3, 2008

I found a handful just by googling...
posted by dmd at 3:40 PM on December 3, 2008

« Older What are some good screencast ...   |  What famous/interesting things... Newer »
This thread is closed to new comments.