Earlier blogs on the barcode library can be found here.
The next task I set for myself for the OpenNETCF.Barcode library was detecting the bounds of a barcode. My initial thought on how to achieve this was to use a Fast Fourier Transform, or FFT of the horizontal luminance lines I was already extracting. The general idea would eb that I'd get an initial line across the middle of the image and make the assumption that this line crosses the barcode. I then run an FFT for this data and look at the power spectrum (basically looking at what the highest frequencies are).
The actual frequencies returned are not relevant. My idea was that I could then "move" up and down from that line, say at 10 pixel spacings, and do an FFT on these lines. If those FFTs lead to similar spectra, then we're still on the barcode. If the spectra changes dramatically, we've left the barcode.
Fortunately I'd done an FFT algorithm port for the SDF ages ago though this is the first real-world use of the class. I had to add a bit of code to generate a power spectrum, but once that was done I was a bit surprised to see how well the code worked. I updated the test UI to display both the current Y position used for decoding (in green) and a red box for the "detected" bounds on the barcode, then ran it against several new images I'd taken.






As you can see, the bounds detection is pretty good. Next up will be figuring out how to actually use this information.