Skip to content

QRCodeEncoderImpl::estimateVersion does not properly estimate version for certain input length ranges #24366

@bagelbytes61

Description

@bagelbytes61

System Information

OpenCV version: 4.8.1
Operating System / Platform: Ubuntu 20.04 (also observed on Windows 10)
Compiler and compiler version: Clang/LLVM 17

Detailed description

QRCodeEncoderImpl::estimateVersion() attempts to be clever about "estimating" the QR code version based around some comparisons of various QR code version capacities in order to bound the QR code version candidates. Certain ranges of input sizes yield an incorrect "estimate" which in turn causes failures upstream of the function call due to possible_version vector containing indices that incorrectly constrain the QR code version range such that QRCodeEncoderImpl::findVersionCapacity() fails (because there are not enough available "data code words" to represent the input.

This all ends up bubbling up from OpenCV as an assertion exception that detected_index != -1 is not satisfied.

My PR to address the issue: #24364

Steps to reproduce

Code: https://gist.github.com/bagelbytes61/e276935f7f32ee54a27dd66cbf33322a

Compile the above code, linking against the necessary OpenCV libraries (libopencv_objdetect and all of its dependencies). I compiled w/ -O2 optimization level.

Execute passing the following optional positional arguments: <qr code version> <input size increment step>.

Observe the aforementioned failures.

An interesting example log. Notice the "hole" in the processed input:

https://gist.github.com/bagelbytes61/c1beac9840ad79daa5252fec12ee01f0

The above was run w/ a version of 40 and a step of 50.

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)

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions