From 4884083019c3378a84b8eafd16a4aacbcec081e9 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Sun, 24 Dec 2023 11:45:20 +0300 Subject: [PATCH] Merge pull request #24667 from MaximSmolskiy:fix-mismatch-and-simplify-code-in-ChessBoardDetector-findQuadNeighbors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix mismatch and simplify code in ChessBoardDetector::findQuadNeighbors #24667 ### Pull Request Readiness Checklist Сode doesn't match comment. If we want check `1:4` edges ratio and `edge_len` is squared edge length, then we should check ``` ediff > 15*edge_len ``` with constant `15`, not `32`, because ``` ediff > 15*edge_len2 <=> edge_len1 - edge_len2 > 15*edge_len2 <=> edge_len1 > 16*edge_len2 <=> 1:4 edges ratio ``` But for me it's better and simpler to directly check `edge_len1 > 16*edge_len2` 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 - [ ] 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/calib3d/src/calibinit.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index bdf61695f6..39544f2bb3 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -1659,10 +1659,11 @@ void ChessBoardDetector::findQuadNeighbors() dist <= q_k.edge_len * thresh_scale) { // check edge lengths, make sure they're compatible - // edges that are different by more than 1:4 are rejected - const float ediff = fabs(cur_quad.edge_len - q_k.edge_len); - if (ediff > 32 * cur_quad.edge_len || - ediff > 32 * q_k.edge_len) + // edges that are different by more than 1:4 are rejected. + // edge_len is squared edge length, so we compare them + // with squared constant 16 = 4^2 + if (q_k.edge_len > 16 * cur_quad.edge_len || + cur_quad.edge_len > 16 * q_k.edge_len) { DPRINTF("Incompatible edge lengths"); continue;