mchehab / zbar

ZBar is an open source software suite for reading bar codes from various sources, including webcams. As its development stopped in 2012, I took the task of keeping it updated with the V4L2 API. This is the main repository for it. There's a clone at at LinuxTV.org, and another one at gitlab.
https://linuxtv.org/downloads/zbar/
GNU Lesser General Public License v2.1
951 stars 201 forks source link

ZBar is too sensible to image rotation #21

Open mchehab opened 5 years ago

mchehab commented 5 years ago

Currently, ZBar is too sensible to image rotation, as can be shown with this small script:

$ mkdir rotated; cd examples
$ for i in code-128.png; do for j in $(seq 1 359); do n=${i/.png/-$j.png}; convert -rotate $j $i ../rotated/$n;done; done
$ for i in ../rotated/*.png; do if [ "$(zbarimg $i 2>/dev/null|grep CODE-128:https://github.com/mchehab/zbar)" == '' ]; then echo $i; fi; done|wc -l
316

Perhaps it should pass the image to an algorithm that would try to improve the image before running the decoders.

mchehab commented 5 years ago

Funny enough, for QR, only 4 (integer) rotation angles got it wrong:

for i in qr-code.png; do for j in $(seq 1 359); do n=${i/.png/-$j.png}; convert -rotate $j $i ../rotated/$n;done; done
for i in ../rotated/*.png; do if [ "$(zbarimg $i 2>/dev/null)" != 'QR-Code:https://github.com/mchehab/zbar' ]; then echo $i; fi; done
../rotated/qr-code-183.png
../rotated/qr-code-342.png
../rotated/qr-code-72.png
../rotated/qr-code-73.png
jameshilliard commented 5 years ago

QR encoding has pretty solid error correction which allows recovery of the data even if up to 30% of codewords are missing it seems, that's also how QR Code Art is possible.

mchehab commented 5 years ago

QR encoding has pretty solid error correction which allows recovery of the data even if up to 30% of codewords are missing it seems, that's also how QR Code Art is possible.

I see. Yet, it sounds funny that there is a small range that are "blind spots" to the detection algorithm. Probably not worth fixing it, but for the 1D barcodes, it would be good if ZBar could do a lot better and read them with higher inclinations.

jasp00 commented 5 years ago

ZBar does not handle any inclination (exception: SQ code), it only processes space/bar pairs horizontally and vertically. In QR code, it detects the corner finders like 1D barcodes.

saurabheights commented 2 years ago

@mchehab Do you have some thoughts on how to approach this issue? I am working on rotation invariant barcode detection problem.

In the past, I handled edge detection using Canny and Hough, which looks like a good approach to start with. If one can localize barcodes, doing affine transformation should be enough as preprocessing to barcode detection. However, it puts a dependency on openCV.