Fix angle discretization in Hough transforms#22164
Conversation
|
C++ and OpenCV version diverges: |
|
Right. So now there seems to be an issue when 1) Let me try to check how the removal of duplicate detections is usually done in literature. By the way, there is no difference in C++ and OpenCL code in this regard. It just happens that the OCL performance tests provide better test cases for this particular situation, which is why the issue was found during performance testing. Here starts the relevant test setup with three horizontal and three vertical lines: |
|
The updated version seems to pass all the tests and also fix the original problem. I quite arbitrarily chose the discretization such that when |
|
@lamm45, the fix looks reasonable, thank you for the contribution! Could you, please, add a test that reproduces the above-mentioned bug? |
|
Test added. |
|
Thanks a lot for added test! |
asmorkalov
left a comment
There was a problem hiding this comment.
👍 Looks good. Thanks a lot for the contribution. Could you squash the commits to have single commit patch in the history.
In some situations the last value was missing from the discrete theta values. Now, the last value is chosen such that it is close to the user-provided maximum theta, while the distance to pi remains always at least theta_step/2. This should avoid duplicate detections. A better way would probably be to use max_theta as is and adjust the resolution (theta_step) instead, such that the discretization would always be uniform (in a circular sense) when full angle range is used.
This aims to fix the bug that occurs in Hough transform (e.g., HoughLines) when 1) The user-supplied
max_thetaparameter is equal to or barely larger than the true value of theta, 2) Thethresholdparameter is not very small, and 3)min_thetaandthetaparameters are chosen such thatcvRoundin the existing code rounds its argument down.The bug was discovered in #21983
Here is an ad hoc test that illustrates the modification:
And output:
It looks like there might also be other issues related to the use of
cvRoundin hough.cpp. However, this PR should fix all issues related to angles (thetas).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.