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

Charuco detection has slowed down considerably since 4.6.0 #25188

Open
4 tasks done
jan-jachnik-oxa opened this issue Mar 8, 2024 · 3 comments · May be fixed by #25507
Open
4 tasks done

Charuco detection has slowed down considerably since 4.6.0 #25188

jan-jachnik-oxa opened this issue Mar 8, 2024 · 3 comments · May be fixed by #25507

Comments

@jan-jachnik-oxa
Copy link

System Information

OpenCV Python version: 4.9.0.80
OS / Platform: MacOS on Apple Silicon (M2 Max)
Python version: 3.11.6

I have seen the same behaviour in C++ going from 4.5.5 to 4.9.0.

Detailed description

Charuco board detection in 4.9.0 and 4.8.0 is running 10-20 times slower versus 4.5.5 and 4.6.0. The big change here is that it moved out of opencv_contrib and into the main opencv repository, which included a slight change to the API.

My app was in C++ and I initially figured it was an issue with my compilation of OpenCV - but I was able to reproduce the problem in Python using OpenCV versions from PyPI.

I dived into the code and aside from a few structural changes in the migration from contrib, the code doing the bulk of the work is almost identical. In the newer version there is the addition of the checkBoard() function here but I patched opencv 4.9.0 to remove it and it did not have a major affect on performance. As far as I can tell, all of the parameter default values remain the same (e.g. subpixel window size).

I also did some benchmarking of individual functions - for example the filterCornersWithoutMinMarkers() function is the last thing run and discards markers that don't meet the minMarkers parameter threshold. In 4.9.0 that was running 2-3 times slower than the entire charuco detection function in 4.5.5 - yet the code between the two versions is almost identical:

4.9.0:

int filterCornersWithoutMinMarkers(InputArray _allCharucoCorners, InputArray allCharucoIds, InputArray allArucoIds,

4.5.5: https://github.com/opencv/opencv_contrib/blob/49e8f123ca08e76891856a1ecce491b62d08ba20/modules/aruco/src/charuco.cpp#L233

Steps to reproduce

I have created a public repo that has Python code to benchmark charuco detection across multiple versions: https://github.com/jan-jachnik-oxa/opencv_charuco_version_benchmark

The output on my M2 Max Macbook:

Running tests on 4.5.5
Testing old api
Number of Aruco markers detected: 204
Number of Charuco corners detected: 368
Time to detect markers: 0.065684925
Time to detect charuco: 0.0057080125

Running tests on 4.6.0
Testing old api
Number of Aruco markers detected: 204
Number of Charuco corners detected: 368
Time to detect markers: 0.05975144583333334
Time to detect charuco: 0.0058611083333333334

Running tests on 4.8.1
Testing new api
Number of Aruco markers detected: 204
Number of Charuco corners detected: 368
Time to detect markers: 0.05999894569999999
Time to detect charuco: 0.1107731625

Running tests on 4.9.0
Testing new api
Number of Aruco markers detected: 204
Number of Charuco corners detected: 368
Time to detect markers: 0.061556029199999994
Time to detect charuco: 0.1175777584

I was unable to test 4.7.0 because it fails an assertion (which might be a bug).

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)
@jan-jachnik-oxa
Copy link
Author

@AleksandrPanov I've seen you working on various parts of the Charuco code. I wondered whether you had an insight into this issue. Thanks.

@jan-jachnik-oxa
Copy link
Author

I've just tested this on an x86 Ubuntu machine and I'm seeing the same slowdown.

@jan-jachnik-oxa
Copy link
Author

I found the bug. I'll get a PR together.

@jan-jachnik-oxa jan-jachnik-oxa linked a pull request Apr 29, 2024 that will close this issue
6 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants