I'm trying to decode an Aztec barcode using the following script:
import zxing
reader = zxing.BarCodeReader()
barcode = reader.decode("test.png")
print(barcode)
Here is the input image:
Following is the output:
BarCode(raw=None, parsed=None, path='/Users/dhiwatdg/Desktop/test.png', format=None, type=None, points=None)
I'm sure it a valid Aztec barcode. Not the script is not able to decode.
The barcode is not detected because there is a strong "ringing" artifact around the black bars (could be result of "defocus" issue).
We may apply binary threshold for getting higher contrast between black and while.
Finding the correct threshold is difficult...
For finding the correct threshold, we may start with the automatic threshold value returned by
cv2.THRESH_OTSU
, and increasing the threshold until the barcode is detected.(Note that need to increase [and not decrease] the threshold is specific to the image above).
Note:
Other solution I tried, like sharpening were not working...
Code sample:
Last value of
thresh
=164
.Last
bw
image: