An attempt to evaluate barcodes that have lost some fidelity due to image compression. Works by:
- Grayscale the barcode
- Taking the first row of the barcode image's pixels
- Converting to hex values for numeric comparisons
- Find local maxima (white) and minima (black) and make them actual black/white in the corrected barcode
- Between local minima and maxima, find the midpoint of the gradient and split evenly left/right for white/black.
This is an approximation, it is not perfect.
- Install dependencies:
pip install -r requirements.txt - Run
python main.pyto see the generated barcode. The image will also be saved ascorrected_barcode.pngand an image of the analysis will be saved asbarcode_analysis.png.
A sample barcode.png is included, which is the image I was trying to fix when building this utility.