Jun Fang
Jun Fang

Reputation: 351

How to efficiently detect bar code target in an image

I have two questions:

Firstly, how to detect the area of bar code target in an image (like the sample images), which may have a few noises.

Secondly, how to efficiently do the detection, for instance, in 1/30 seconds.

enter image description here

enter image description here

Upvotes: 1

Views: 90

Answers (1)

Mark Setchell
Mark Setchell

Reputation: 207660

Squash (resize) the image till it is only 1 pixel tall, then normalise it to the full range of 0-255 and threshold. I am using ImageMagick at the command-line here - it is installed on most Linux distros and is available for OSX and Windows also with Python, PHP, Ruby, C/C++ bindings.

convert barcode.png -resize x1! -scale x10! -normalize -threshold 50% result.png

enter image description here

I have then scaled it to 10 pixels tall so you can actually see it on here - but you would keep the original width and have a height of one pixel. Then just find the first white pixel in your single row of pixels.

Your recently added, smaller barcode gives this:

enter image description here

Upvotes: 1

Related Questions