Barcode Processor is a collection of Java classes that will perform basic image recognition on a barcode image. It will take that image and convert it into a datastructure representing the bars, spaces, and their widths. You are then free to perform whatever additional translations you want on this datastructure (for example, recognizing it as a 3 of 9 code and turning it into text).
There are a lot of caveats. Remember, this is development-level source code that is fairly new and had little Quality Assurance testing. Its practical uses are very limited at this point in time.
The barcode processor can be invoked using its public functions. An example of this follows:
BarcodeImageProcessor processor = new BarcodeImageProcessor(); processor.setImageFilename("/Users/enigma/Desktop/barcode.gif"); processor.setUseFuzzyPixelMatching(false); processor.setBarColor(0, 0, 0); processor.setSpaceColor(1, 0, 0); processor.setDebug(false); processor.guessWidths(); System.out.println("Wide areas are " + processor.getWideElementPixels() + " pixels"); System.out.println("Narrow areas are " + processor.getNarrowElementPixels() + " pixels"); BarcodeData data = processor.translate(); System.out.println(data);
An example input file should look something like this. Note that it is a crisp, computer-generated image, and not a scan or photograph. The edges are sharp, the corners are square, and it has not been anti-aliased. Additionally, the colors are distict and the bars go to the edge of the image--that is, there are no left and right margins.
[Wide barcode image; click to view] Figure 1: Input Barcode |
The output is in the form of a datastructure. You can do whatever you want with this data (such as parse it as a particular barcode format), but the two included output options simply display width and bar data as plaintext.
1b 2s 1b 1s 2b 1s 2b 1s 1b 1s 1b 1s 2b 1s 1b 1s 2b 2s 1b 1s 1b 1s 2b 1s 2b 1s 1b 2s 1b 1s 1b 1s 2b 1s 1b 2s 2b 1s 1b 1s 1b 1s 1b 1s 2b 2s 1b 1s 2b 1s 2b 1s 1b 1s 2b 2s 1b 1s 1b 1s 2b 1s 1b 1s 1b 1s 2b 2s 1b 1s 2b 1s 1b 1s 1b 1s 2b 2s 1b 1s 2b 1s 1b 1s 2b 2s 1b 1s 1b 1s 1b 1s 2b 1s 1b 1s 2b 2s 1b 1s 2b 1s 1b 1s 2b 2s 1b 1s 1b 1s 2b 1s 1b 1s 1b 2s 1b 1s 2b 1s 2b 1s 1b 1s 1b 1s 2b 2s 1b 1s 2b 1s 2b 1s 1b 2s 1b 1s 1b 1s 2b 1s 1b 1s 1b 2s 2b 1s 1b 1s 2b 2s 1b 1s 1b 1s 2b 1s 1b 1s 2b 1s 2b 1s 1b 2s 1b 1s 1b 1s 2b 1s 1b 1s 2b 1s 1b 2s 1b 1s 2b 1s 2b 1s 1b 1s 1b 2s 1b 1s 1b 1s 2b 1s 2b 1s 1b 2s 1b 1s 1b 2s 1b 1s 2b 1s 2b 1s 1b
In this case, 1b = narrow bar, 1s = narrow space, 2b = wide bar, 2s = wide space Figure 2: Output Format 1 |
.-..-.-.....-...--....-.-..-....-..--.......--..-.-...-- | | | | | | | | | | | | | | | | | | | | | | | | | | | | ....-.....--..-.....--..-...--......-...--..-...--....-. | | | | | | | | | | | | | | | | | | | | | | | | | | | | ...-..-.-.....--..-.-..-....-....--...--....-...-.-..-.. | | | | | | | | | | | | | | | | | | | | | | | | | | | | ..-...-..-..-.-....-....-.-..-...-..-.-.. | | | | | | | | | | | | | | | | | | | | | In this case, the second row contains "|" is a bar and " " is a space. The first row contains "." for narrow and "-" for wide. Figure 3: Output Format 2 |