Depends on the quality of the scans. If you have low-res scans with lots of artefacts and other graphic or text around the bar code and the bar code tilted, then you have a major project on your hand. If possible find a free bar code scan utility. Also there lots of different bar code standards, if you need to parse more than one it gets really difficult

If you have non of the above problems, you might do something like this (this is theoretical, never done this in practice):

1) Store lets say 20 or 40 horizontal lines from the vertical middle of the image bitmap to an array of arrays

2) Find out the blackest and the whitest value from a block in the horizontal middle of these lines and subtract some error margin to get the thresholds or simple take the mean value as transition value

3) Calculate for each of these lines black-to-white and white-to-black transitions based on the thresholds or the transition value

4) Average those transitions that occur in more than 80% of the lines at the same horizontal place plus minus an error value

5) Collect all the widths of black lines (difference of the white-to-black to the next black-to-white transition). You should get values the raster of the bar code out of this after some averaging.

6) Take the first white-to-black transition as starting point. If you find the start code, good. If it doesn't work out, take the next white-to-black transition,...


In reply to Re: Barcode Recognition by jethro
in thread Barcode Recognition by avo

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.