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

WIP: Fix segfault in QRCodeDetector.detectAndDecodeCurved #23802

Closed

Conversation

AleksandrPanov
Copy link
Contributor

@AleksandrPanov AleksandrPanov commented Jun 14, 2023

fixes #22892
merge with opencv/opencv_extra#1072

The issue is in spline interpolation. Only the points of the function can be interpolated using splines, but the contour points may not be a function. There may be several points with the same x coordinate and different y. It results in getting NaN when calculating spline.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

modules/objdetect/src/qrcode.cpp Outdated Show resolved Hide resolved
@asmorkalov asmorkalov added this to the 4.8.0 milestone Jun 15, 2023
@AleksandrPanov
Copy link
Contributor Author

The problem was in the original algorithm - PR #18003

@APrigarina, could you look at this solution or suggest another one?

@AleksandrPanov AleksandrPanov marked this pull request as ready for review June 15, 2023 11:48
@asmorkalov asmorkalov self-assigned this Jun 15, 2023
@asmorkalov
Copy link
Contributor

@opencv-alalek Could you take a look on the solution?

@asmorkalov asmorkalov changed the title fix segfault in QRCodeDetector.detectAndDecodeCurved Fix segfault in QRCodeDetector.detectAndDecodeCurved Jun 16, 2023
@asmorkalov asmorkalov requested a review from vpisarev June 16, 2023 08:20
@vpisarev
Copy link
Contributor

@AleksandrPanov, @asmorkalov, frankly speaking, I don't like this hack. There is a general flexible method how to interpolate any polyline or any polygon using a spline. First, you introduce "time" axis t. The simplest (and probably good enough for this purpose) method is to set t=0 for the first point, t=1 for the second point etc. Then, instead of computing spline as y=y(x) you just build splines x=x(t) and y=y(t). Then you can compute intermediate points at any precision by choosing some fractional t values. In this case you don't need the proposed hack, because you can be sure that all t's are different.

@asmorkalov
Copy link
Contributor

thanks a lot for the parametrization idea!

@asmorkalov asmorkalov changed the title Fix segfault in QRCodeDetector.detectAndDecodeCurved WIP: Fix segfault in QRCodeDetector.detectAndDecodeCurved Jun 20, 2023
@asmorkalov asmorkalov removed this from the 4.8.0 milestone Jun 20, 2023
@AleksandrPanov AleksandrPanov marked this pull request as draft June 23, 2023 12:35
Comment on lines +1977 to +1979
OK = 0,
NEED_SWAP_AXES,
NEED_ADD_PARAMETRIZATION
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With parameterized spline we do not need branches any more.

@asmorkalov asmorkalov mentioned this pull request Feb 16, 2024
6 tasks
@asmorkalov
Copy link
Contributor

Replaced by #25026

@asmorkalov asmorkalov closed this Feb 16, 2024
asmorkalov pushed a commit that referenced this pull request Feb 16, 2024
Fix qrcode bugs #25026

This PR fixes #22892, #24011 and #24450 and adds regression tests using the images provided. I've also verified with the [benchmark](https://github.com/opencv/opencv_benchmarks/tree/develop/python_benchmarks/qr_codes) that this doesn't break anything there.

resolves #22892
resolves #24011
resolves #24450
Replaces #23802

Requires extra: opencv/opencv_extra#1148

### Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

- [x] I agree to contribute to the project under Apache 2 License.
- [x] To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
- [x] The PR is proposed to the proper branch
- [x] There is a reference to the original bug report and related work
- [x] There is accuracy test, performance test and test data in opencv_extra repository, if applicable
      Patch to opencv_extra has the same branch name.
- [ ] The feature is well documented and sample code can be built with the project CMake
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Segfault in QRCodeDetector.detectAndDecodeCurved
3 participants