-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Fix infinite loop on ArUco apriltag refinement #3220
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
Fix infinite loop on ArUco apriltag refinement #3220
Conversation
Software entered infinite loop when image height was smaller than 10*cv::getNumThreads(). With high core count machines this could happen with very reasonable image sizes. Fix is to ensure that chunksize is at least 1.
@buq2 Thanks for the contribution. The patch looks reasonable for me. Could you add your reproducer with |
@asmorkalov Do you mean adding the main function code from the initial PR description to (for example) https://github.com/opencv/opencv_contrib/blob/3.4/modules/aruco/test/test_arucodetection.cpp ? Sure! The "test" is not a very good test case as if it fails, it hangs indefinitely, but maybe it is better than nothing. I'll add it soonish and make it such that it will test also the other refinement methods with different initial number of threads with small aruco images. |
Test ensures that different aruco detection methods do not produce different results based on number of threads. Test was created after observing infinite loop caused by small image and large number of threads when using apriltag corner refinement.
4e44309
to
43ff44b
Compare
@buq2 Thanks for the test. I refactored it a bit, to make it parameterized (obvious test report in case of failure) and extracted the iteration with |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thx for fix and tests
Thanks for the reviews and refactoring! Next one will be less painful for everyone :) |
@alalek I propose to merge the patch. |
…-fix Fix infinite loop on ArUco apriltag refinement * Fix infinite loop on ArUco apriltag refinement Software entered infinite loop when image height was smaller than 10*cv::getNumThreads(). With high core count machines this could happen with very reasonable image sizes. Fix is to ensure that chunksize is at least 1. * Test aruco detection with different number of threads Test ensures that different aruco detection methods do not produce different results based on number of threads. Test was created after observing infinite loop caused by small image and large number of threads when using apriltag corner refinement. * Test refactoring. * Syntax fix for pre-C++11 compilers. Co-authored-by: Alexander Smorkalov <[email protected]>
ASSERT_EQ(original_ids.size(), 1); | ||
ASSERT_EQ(original_corners.size(), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: comparison between signed and unsigned integer expressions
sorry, I overlooked
cv::aruco::detectMarkers(img, dictionary, corners, ids, params); | ||
|
||
// If we don't find any markers, the test is broken | ||
ASSERT_EQ(ids.size(), 1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
warning: comparison between signed and unsigned integer expressions
sorry, I overlooked
Software entered infinite loop when image height
was smaller than 10*cv::getNumThreads(). With high
core count machines this could happen with very
reasonable image sizes.
Fix is to ensure that chunksize is at least 1.
The bug can be triggered with following test program:
Pull Request Readiness Checklist
See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request
Patch to opencv_extra has the same branch name.