From 28d22d7b84c847042838503011b884d0f0f935f4 Mon Sep 17 00:00:00 2001 From: Maxim Smolskiy Date: Tue, 6 Feb 2024 15:16:12 +0300 Subject: [PATCH] Merge pull request #24779 from MaximSmolskiy:fix-bug-in-ChessBoardDetector-findQuadNeighbor Fix bug in ChessBoardDetector::findQuadNeighbors #24779 ### Pull Request Readiness Checklist `corners` and `neighbors` indices means not filling order, but relative position. So, for example if `quad->count = 2`, it doesn't mean that `quad->neighbors[0]` and `quad->neighbors[1]` are filled. And we should should iterate over all four `neighbors`. 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 | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index 39544f2bb3..b61c0069e3 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -156,7 +156,8 @@ struct ChessBoardQuad float edge_len; // quad edge len, in pix^2 // neighbors and corners are synced, i.e., neighbor 0 shares corner 0 ChessBoardCorner *corners[4]; // Coordinates of quad corners - struct ChessBoardQuad *neighbors[4]; // Pointers of quad neighbors + struct ChessBoardQuad *neighbors[4]; // Pointers of quad neighbors. M.b. sparse. + // Each neighbors element corresponds to quad corner, but not just sequential index. ChessBoardQuad(int group_idx_ = -1) : count(0), @@ -1701,12 +1702,12 @@ void ChessBoardDetector::findQuadNeighbors() continue; // Check that each corner is a neighbor of different quads - for(j = 0; j < closest_quad->count; j++ ) + for(j = 0; j < 4; j++ ) { if (closest_quad->neighbors[j] == &cur_quad) break; } - if (j < closest_quad->count) + if (j < 4) continue; // check whether the closest corner to closest_corner