detect barcodes in images and draw a border with a custom color around them
$ python3 barcode-detector.py --path example.tif --color "255:0:255"
usage: barcode-detector.py [-h] -p PATH [-c COLOR]
options:
-h, --help show this help message and exit
-p PATH, --path PATH Path to the input image
-c COLOR, --color COLOR Color of the border, fmt: r:g:b
The barcode detector works by applying several filters to an image and extracting the contours of the barcodes. If a barcode could not be detected consider tweaking constants in the source file.
The algorithm is made up of the following filters and stages:
- sharr gradient in x and y direction
- subtract y from x gradient for finding barcode region
- blur and threshold
- Closing kernel
- Series of dilations and erosions
- Largest contour should be the barcode