-
-
Notifications
You must be signed in to change notification settings - Fork 55.7k
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
cv2.findChessboardCorners() running endlessly on certain images #23558
Comments
I ran a test on this and found out that the testChessboardCorners function eventually returns. It is not running endlessly. It takes a lot of time in functions like processQuads and it is running in a loop so it takes around 3 minutes for the function to return. |
Even if it returns after some time (it did not return after 20 minutes on my MacBook Pro 2020 i5), I guess it's still not expected behaviour that it takes so long, especially since the |
checked, There are two problems:
|
The problems in my opinion are two:
In my opinion there are two possible things that can be done to mitigate the situation in this and similar cases. The first, more expensive, is to figure out why checkChessboardBinary() fails. The second, as already suggested, is to change the threshold that is used to filter quads. The threshold is now defined in this way:
To me 25 is a ridiculous number.
25 therefore means a quad of side 5 pixels! I don't know why this part of the code was commented out and what the various multiplicative factors mean but it made more sense. If it makes sense I make a pull request on this |
Thanks for your input @thewoz ! In my opinion, the most critical problem is the failing Nevertheless, any contributions that work towards solving the issue are of course more than welcome, so would be great if you're willing to spend time in this @thewoz ! |
…tor-findQuadNeighbors Speed up ChessBoardDetector::findQuadNeighbors #24605 ### Pull Request Readiness Checklist Replaced brute-force algorithm with O(N^2) time complexity with kd-tree with something like O(N * log N) time complexity (maybe only in average case). For example, on image from #23558 without quads filtering (by using `CALIB_CB_FILTER_QUADS` flag) finding chessboards corners took ~770 seconds on my laptop, of which finding quads neighbors took ~620 seconds. Now finding chessboards corners takes ~155-160 seconds, of which finding quads neighbors takes only ~5-10 seconds. 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 - [ ] 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
…dDetector-findQuadNeighbors Speed up ChessBoardDetector::findQuadNeighbors opencv#24605 ### Pull Request Readiness Checklist Replaced brute-force algorithm with O(N^2) time complexity with kd-tree with something like O(N * log N) time complexity (maybe only in average case). For example, on image from opencv#23558 without quads filtering (by using `CALIB_CB_FILTER_QUADS` flag) finding chessboards corners took ~770 seconds on my laptop, of which finding quads neighbors took ~620 seconds. Now finding chessboards corners takes ~155-160 seconds, of which finding quads neighbors takes only ~5-10 seconds. 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 - [ ] 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
To takle this problem, I think controling threshold for the size of the contours or binarization is less ensential, since we can make a binary background whitch contains small size contours already. Maybe we can do downsampling/blur operations in fast check, which can eliminate small contours in image.
|
System Information
OpenCV python version: both 3.4.18.65 and 4.7.0.72
Operating System / Platform: Ubuntu 18.04 and macOS 13.2.1
Python version: 3.7
Detailed description
I’m using OpenCV to find chessboard corners on an image using
cv2.findChessboardCorners()
. It can happen that an image is passed into the function that is of bad quality or almost completely black. When this happens, the function just endlessly runs, trying to find the corners.I initially opened a topic on the OpenCV forum, but there it was confirmed that it's a bug, hence why I'm also opening a bug report here.
This issue is a problem to me because it completely blocks my application when this happens.
Steps to reproduce
This issue can easily be reproduced.
You can use the code snippet below:
in combination with the image below:
![27-04-2023_14-13-21_494](https://user-images.githubusercontent.com/4648081/235081868-f46a588b-08f4-436e-973b-71fdca8e4480.png)
You will notice that the function just endlessly keeps running and consuming resources (I’ve let it run for +15 minutes already).
Issue submission checklist
The text was updated successfully, but these errors were encountered: