Skip to content

Swiss QR-bills (ISO 20022) not decoded #21929

New issue

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

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

Already on GitHub? # to your account

Closed
4 tasks done
sbrunner opened this issue Apr 29, 2022 · 5 comments
Closed
4 tasks done

Swiss QR-bills (ISO 20022) not decoded #21929

sbrunner opened this issue Apr 29, 2022 · 5 comments

Comments

@sbrunner
Copy link

sbrunner commented Apr 29, 2022

System information (version)
  • OpenCV => 4.5.5.64
  • Operating System / Platform => Ubuntu Linux
  • Compiler => gcc?
Detailed description

The Swiss QR-bills are detected but not decoded.

See also: https://scanbot.io/en/sdk/scanner-sdk/barcode-scanner-sdk/swiss-qr

Steps to reproduce
import cv2

image = cv2.imread("test-qr-code/155567196-54dbec58-7fa4-473a-a551-b52ecd04e11e.png")
detector = cv2.QRCodeDetector()
print(detector.detect(image))

data, bbox, straight_qrcode = detector.detectAndDecode(image)
print(data)
print(bbox)

With image: 155567196-54dbec58-7fa4-473a-a551-b52ecd04e11e
=>

(True, array([[[ 42.,  42.],
        [433.,  42.],
        [433., 433.],
        [ 42., 433.]]], dtype=float32))

[[[ 42.  42.]
  [433.  42.]
  [433. 433.]
  [ 42. 433.]]]
Issue submission checklist
  • I report the issue, it's not a question
  • I checked the problem with documentation, FAQ, open issues,
    forum.opencv.org, Stack Overflow, etc and have not found any solution
  • I updated to the latest OpenCV version and the issue is still there
  • There is reproducer code and related data files: videos, images, onnx, etc
@Kumataro
Copy link
Contributor

Kumataro commented May 5, 2022

This image is a QR Code image consisting of 49x49 cells. In the samplingForVersion() function, it was determined as follows.

https://github.com/opencv/opencv/blob/4.5.5/modules/objdetect/src/qrcode.cpp#L2359

postIntermediate.rows/cols = 18000
version_size  = 49
delta_rows / cols = 367.

The 0/1 recognized logic of each cell using this parameter runs 50 * 50 = 2500 times.

// for (int r = 0; r <postIntermediate.rows; r + = delta_rows)

r = 0 // 0
r = 367 // 1
r = 734 // 2
r = 1101 // 3

r = 17249 // 47
r = 17616 // 48
r = 17983 // 49 !!!

The QR decoder knows that the QR Code image consists of 49x49 cells. Then, the 0/1 recognized results are adopted in the order in which they are detected. Therefore, the sampled image is skewed one cell per line.

 0 1 2 3 ... 47 48
49 0 1 2 ... 46 47
48 49 0 1 ... 45 46

The QR Code decode has failed because the sampled image is skewed and corrupted.

This patch replaces the delta_rows skip loop with a simpler version_size loop.

I'm sorry I didn't test with python, however my test with C++ works well.

@AleksandrPanov AleksandrPanov self-assigned this May 13, 2022
@Baerbeisser
Copy link

Baerbeisser commented May 23, 2022

Version: 4.5.5.64

I have the same problem.
Here are some samples: https://github.com/swico/qr-bill
Cutting the Qr Code out, preprocessing it and then feeding it to decode doesn't help much.

Attached is a log file of a Powershell foreach run over above samples.

edit: removed duplicate lines due to extracted pages from PDF

foreach-run.log

@AleksandrPanov
Copy link
Contributor

fixed by #22025

SPC
0100
1
CH3709000000304442225
Stiftung Heilsarmee Schweiz


3000
Bern
CH







CHF







NON

Spende für die Aktion Winterfest
[[[ 42.  42.]
  [433.  42.]
  [433. 433.]
  [ 42. 433.]]]

@sbrunner
Copy link
Author

sbrunner commented Jun 9, 2022

Many thanks for your great effort :-)

@sbrunner
Copy link
Author

In cases like this one, it steels not working...
2

I get the bbox:

[[ 21.436857  23.88773 ]
 [564.2752    25.00468 ]
 [559.34143  562.7794  ]
 [ 16.857067 559.7231  ]]

But no data...

# for free to join this conversation on GitHub. Already have an account? # to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants