From bcbc74d4cd57f3536d947e4815685c91a6c4fb46 Mon Sep 17 00:00:00 2001 From: MaximSmolskiy Date: Thu, 8 Feb 2024 01:31:29 +0300 Subject: [PATCH] Do not dilate binary images on first iteration in findChessboardCorners --- modules/calib3d/src/calibinit.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/modules/calib3d/src/calibinit.cpp b/modules/calib3d/src/calibinit.cpp index b61c0069e3..4b57aad1fe 100644 --- a/modules/calib3d/src/calibinit.cpp +++ b/modules/calib3d/src/calibinit.cpp @@ -531,14 +531,14 @@ bool findChessboardCorners(InputArray image_, Size pattern_size, const int min_dilations = 0; const int max_dilations = is_plain ? 0 : 7; - // Try our standard "1" dilation, but if the pattern is not found, iterate the whole procedure with higher dilations. - // This is necessary because some squares simply do not separate properly with a single dilation. However, + // Try our standard "0" and "1" dilations, but if the pattern is not found, iterate the whole procedure with higher dilations. + // This is necessary because some squares simply do not separate properly without and with a single dilations. However, // we want to use the minimum number of dilations possible since dilations cause the squares to become smaller, // making it difficult to detect smaller squares. for (int dilations = min_dilations; dilations <= max_dilations; dilations++) { //USE BINARY IMAGE COMPUTED USING icvBinarizationHistogramBased METHOD - if(!is_plain) + if(!is_plain && dilations > 0) dilate( thresh_img_new, thresh_img_new, Mat(), Point(-1, -1), 1 ); // So we can find rectangles that go to the edge, we draw a white line around the image edge. @@ -596,13 +596,13 @@ bool findChessboardCorners(InputArray image_, Size pattern_size, block_size = block_size | 1; // convert to binary adaptiveThreshold( img, thresh_img, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, block_size, (k/2)*5 ); - if (dilations > 0) - dilate( thresh_img, thresh_img, Mat(), Point(-1, -1), dilations-1 ); + dilate( thresh_img, thresh_img, Mat(), Point(-1, -1), dilations ); } else { - dilate( thresh_img, thresh_img, Mat(), Point(-1, -1), 1 ); + if (dilations > 0) + dilate( thresh_img, thresh_img, Mat(), Point(-1, -1), 1 ); } SHOW("Old binarization", thresh_img);