Jump to content
  • Advertisement
Sign in to follow this  
Jonny_S

Reading a barcode?

This topic is 3044 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi all,

The conundrum of reading a barcode, coupled with my boredom has caused me attempt to write a simple barcode reader in C#. I'm pretty new to image processing as a whole but I thought starting with simple barcode. I could build on some fundamentals and keep going until I get bored.

My first attempt was to read pixels from left to right until I reached a black pixel. The first bar of a barcode should always be the width of one bit (or so I thought) so if I could get the width of that one bar, I could then loop through getting the values for all bars based on colour (i.e 1 for black, 0 for white). However, it seems from the examples I've been using, bar widths are fairly inconsistent and so I'm wondering what another approach could be?

I was wondering if anyone is pretty savvy in the image processing world or knows how actual photographic scanners work could give me any advice?

Thanks,

Jon

[edit]
I've finished uni, I'm jobless I am actually this bored...

Share this post


Link to post
Share on other sites
Advertisement
Do you get a perfect bar code (i.e. a bitmap with the bars perfectly pixel aligned) or is it a photograph from a real world bar code?

If the latter, it might be worth looking into Fourier Transformations: http://homepages.inf.ed.ac.uk/rbf/HIPR2/fourier.htm. I haven't worked with it in software yet, but it's a good technique to either retrieve the bar code or to sharpen / rotate the image so you can read it more accurately.

Share this post


Link to post
Share on other sites
I was starting with a perfect barcode, just an example I grabbed off wikipedia. However, I was hoping to move on to actual photos once I'd perfected the algorithm, so I'll look into the fourier transform.

My current issue comes from working out how many bars are in a block, which is sort of shown here.

I thought if I could get the width of 1 bar, such as the start bar (which is always 1 bar) I could then split up blocks of bars easily. However it turns out bar widths aren't always exact, so I was wondering if I should continue down this line of thought or if there is a better way to do it.

Hope that makes sense,

Share this post


Link to post
Share on other sites
Which kind of barcode are you trying to read? There are dozens of different types? I'd recommend trying to read an "Interleaved 2 of 5".
For that, you could scan across the image to find out:

the widest black bar
the narrowest black bar
the widest white bar
the narrowest white bar

Next, you pick a cut-off value such as half way between the widest and narrowest and scan across the image again. anything that is wider than the cutoff counts as a wide bar, and the rest are not.

Share this post


Link to post
Share on other sites
FFT's and image scanning sounds like overkill to me. If you have the right barcode reader hardware, it will convert a barcode into ascii text. Back when I worked on political campaigns (about 10 years ago), we would use a barcode font to print voter ids right onto the address lists we would give to volunteers. At the end of the day, after they'd finished canvassing, we would take the lists and use a barcode scanner to immediately look up the voters who had been contacted to flag their record in our database depending on if they wanted a yard sign or what not (and to avoid canvassing them a second time as well). I suppose today this would all be managed through smart phones and the like.

At any rate, if your goal is to investigate image processing using barcodes, you ought to be able to find free barcode fonts on the internet that you can use with Photoshop or what not to build the images that you'll later try to take apart.

Share this post


Link to post
Share on other sites
Thanks for the responses, I was trying to read a UPC barcode and I think I'm on the path to success.

I've scanned through and found the minimum bar width and the minimum space width. I've then scanned through each bar, got the bar size and divided it by the minimum size to see how many "bits" are in the bar. If the division has a remainder I round up or down which takes care of any left over pixel due to inconsistent bar sizes.

Seems to be working at the moment, I'm collecting a lot of barcodes to do a thorough test.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!