Barcodescanner in pure processing

Nikolaus Gradwohl2009-09-22T05:53:00+02:00

I always considered barcode scanners as a pice of rocketscience that mere mortals like me aren't able to build. But this weekend megalomania hit me and i wrote one in processing. I didn't use any libraries beside GSVideo (on my linux box) or processing.video (wherever quicktime is available)

My barcodescanner is able to decode a subset of the code128 barcode. it shows all printable characters and it supports all three charsets, but i didn't include all those Bell, Stx, Enq, .. character. feel free to add support for them if you need it :-)

barcodescanner in action

The program assumes that the barcode is placed in the middle of the camera image. It takes the middle row of pixels and converts it to black and white. then it calculates the width of the black and white bars and searches for a barcode startsequence. if it finds one it tries to match the next six bars with the code128 patterns and adds the value of the character that has the highest match to a stringbuffer.

when a stop character is found it calculates the checksum and if that matches it returns the found string (minus the checksum char).

sounds a lot more complicated than it actually is. the hardest part was turning the row of pixels into an array of black and white values.

The code is not really beautifull and it is a bit long because of the big char tables.

click here to download the code.

Tweet This! submit to reddit Digg!   Tags: | 4 comments | no trackbacks

See also:

random walk
little pictureframe is watching you again
hexagonal patterns in processing
tree layers in processing
papercut flower

Trackbacks

Comments

Leave a response

  1. Luis M 2009-09-29T22:27:35+02:00

    Hi, I'm trying to implement this for a school project on a mac, but I haven't been able to read any codes. Processing isn't giving me any errors. The camera activates and I can se the red row but it just doesn't do a thing

    do you have any ideas??

  2. Luis M 2009-09-29T22:49:48+02:00

    Ups, I wasn't using code128 Works great. Excellent job!

  3. MrFMFT71 2012-01-15T13:03:19+01:00

    Where can I get a compiled version to use on Ubuntu or Windows?

    If so, let me know and I will give it a try

    My email is fmft71 at yahoo dot es

  4. gimsech 2014-04-15T22:15:02+02:00

    On a Mac: You have to comment the lines: //GSCapture cam; and //cam = new GSCapture(this, 640, 480, "v4l2src", parName, parValue);

    uncomment: import processing.video.*; Capture cam;

    and

    cam = new Capture( this, 640, 480);

    IMPORTANT: There is a spelling error: Capture and Caputre

    And you have to add: cam.start(); after: cam = new Capture( this, 640, 480);

    cheers

Leave a comment