Barcodes

BlitzMax Forums/Brucey's Modules/Barcodes

Brucey(Posted 2010) [#1]
Have you ever seen a zebra crossing?
It looks a bit like a barcode... (if you squint your eyes and stand on your head)

Anyway, I've wrapped the ZXing library, to provide the ability for BlitzMax to read barcodes :-)
Codes include :
* UPC-A and UPC-E
* EAN-8 and EAN-13
* Code 39
* Code 128
* QR Code (only on non-Windows for now, I'm afraid).

Since the library is not written for Windows, I had a bit of trouble getting it working on that platform. I think I have everything except support for QR working (which is a 2D barcode). Hopefully, if I throw the issues at the ZXing list they'll come up with a fix.
On the Windows side, it also requires libiconv, which is a character-set translation engine. So I added another module, BaH.libiconv to help out with that. It's LGPL, and therefore comes in DLL form only. (which you would need to include for your Win32 binary).
I've not, yet, implemented the iconv API, but I might do that too, at some point, so you nice folks can play with that library too, if you wish. (iconv is on Mac and Linux by default)

Here's an example of some code to get the barcode "text" from an image :
SuperStrict

Framework BaH.Barcode
Import BRL.JPGLoader
Import BRL.StandardIO

Local pix:TPixmap = LoadPixmap("media/code39_01.jpg")

Local barcode:TBCResult = decodeBarcode(pix)

If Not barcode.error Then
	Print "Text : " + barcode.getText()
Else
	Print "Error : " + barcode.error
End If


I tried to make the interface simple - there's only one function to call : decodeBarcode()
which takes a TPixmap as a parameter.

This leaves you free to use whichever Image module you want, and any TStream functionality too.
For now, the pixmap should be RGB or RGBA.

For those interested in generating barcodes, wxMax includes some functionality for that.

The new modules are currently available in the maxmods Google SVN repository. (BaH.Barcode, BaH.libiconv).


Glenn Dodd(Posted 2010) [#2]
I work for a Courier Company so barcodes are our life blood.
Fascinating !!!

Data Matrix is the 2d variant we use.
Any chance of getting that going?

Cheers
Glenn


Brucey(Posted 2010) [#3]
Data Matrix is the 2d variant we use.
Any chance of getting that going?


Reading the ZXing list, it looks like they are looking into a C++ port of a reader for that format.
Once it's added to the library, it will be available here too.


Armitage 1982(Posted 2010) [#4]
Is this those kind of Japanese square bar-code you see on every product from there ?
I think it could be something very interesting to play with.


Glenn Dodd(Posted 2010) [#5]
There are different variants but yes they typically look like a bunch of small square formed into a bigger square.


xlsior(Posted 2010) [#6]
Hm, I wonder if one could combine this with either Brucey's ofx module, or the ESCAPI dll thing to get your PC to read barcodes through any webcam... :-?


Brucey(Posted 2010) [#7]
I wonder if one could combine this with either Brucey's ofx module


More or less...



This is the interesting bit of the code :
		vidGrabber.grabFrame()
		
		pix = CreateStaticPixmap(vidGrabber.getPixels(), 320, 240, 320 * 3,PF_RGB888)
		bcResult = decodeBarcode(pix)

The detected points are retrieved from the result, and drawn over the image.

Focus and resolution appear to be rather important here, given the closeness and definition of the lines in the barcode.
A dedicated barcode reader of course generally only requires a "strip" image to interpret, and therefore can scan many more times a second than your typical webcam.

But interesting, I think :-)


DavidDC(Posted 2010) [#8]
Nice one Brucey!


xlsior(Posted 2010) [#9]
Hehe... Yeah, looks like that one works pretty well, although I had much better luck in 640x480 than 320x240.

(At first it didn't recognize *anything*, until I realized that I had my webcam configured to capture in mirror mode... Doh!)

Biggest issue definitely is focus though, it takes my webcam a moment to get a clear image, but once it does it works great.

I did notice this on every run, though: (win7 x64)


Warning: .drectve `/DEFAULTLIB:"LIBC" /DEFAULTLIB:"OLDNAMES" ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:uuid.lib ' unrecognized
Warning: .drectve `-defaultlib:uuid.lib ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized
Warning: .drectve `-defaultlib:LIBCMT ' unrecognized
Warning: .drectve `-defaultlib:OLDNAMES ' unrecognized



but despite the warnings, it runs OK...

For those interested in UPC codes: there's a free online lookup database at http://www.upcdatabase.com/itemform.asp , which has well over a million UPC codes in it.