Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot decode numeric QR codes containing exactly 4 digits #392

Closed
simon-staal opened this issue May 31, 2023 · 2 comments
Closed

Cannot decode numeric QR codes containing exactly 4 digits #392

simon-staal opened this issue May 31, 2023 · 2 comments
Labels

Comments

@simon-staal
Copy link

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
@lessthanoptimal
Copy link
Owner

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.

@lessthanoptimal
Copy link
Owner

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants