lessthanoptimal / BoofCV

Fast computer vision library for SFM, calibration, fiducials, tracking, image processing, and more.

Home Page:http://boofcv.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Cannot decode numeric QR codes containing exactly 4 digits

simon-staal opened this issue · comments

I'm using PyBoof which is a wrapper for this library. Whilst benchmarking the QR code decoding for 1-H codes using random integer payloads, I noticed that payloads with values in the range [1000. 10000) were never detected, whilst these were detected successfully using OpenCV's QR code detection algorithm.

Sample code:

import pyboof as pb
import segno
from time import time
from random import randint
# uninstall Java JDK after testing
TEST_FILE = 'qr_test.png'
ATTEMPTS = 10000-1000

qr_pyboof = pb.FactoryFiducial(np.uint8).qrcode()
total_pyboof = 0

for i in range(1000, 10000):
    x = i
    qrcode = segno.make(x, version=1)
    assert qrcode.error == 'H'
    qrcode.save(TEST_FILE, scale = 5)

    img = cv2.imread(TEST_FILE)
    img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    img = cv2.resize(img, (88, 88))

    start = time()
    image = pb.ndarray_to_boof(img)
    qr_pyboof.detect(image)
    end = time()
    assert len(qr_pyboof.detections) == 0, f"Successfully detected {len(qr_pyboof.detections)} qr codes (input = {x})" # Assertion always passes, i.e. detection fails
    total_pyboof += (end - start) * 1000

print(f'Took an average of {(total_pyboof / ATTEMPTS):.2f}ms for {ATTEMPTS} attempts')

The detector starts working again at 10000, although some values still don't work here. I didn't test everything exhaustively, but obtained errors for the following values:

10110, 10427, 11207, 11303, 11674, 12389, 14244, 14515

This discussion for this issue is in PyBoof message board. lessthanoptimal/PyBoof#23

Summary: 

Failure to read 4-digit markers is caused by a bug in segno. In the future, by default, BoofCV will ignore the padding bit pattern since it's not worth fighting all the buggy encoders. Verified that this is what other libraries are doing. 

Problems with a few 5-digit markers appear to be an actual issue. With 10110 there's a false positive when detecting the finder pattern. This should be fixable.

As of 0.43.1 it ignores the padding bit patterns so bad encoders no longer are an issue. Created a new ticket for the other issue.