Merge pull request #24710 from MaximSmolskiy:do-not-dilate-binary-images-on-first-iteration-in-findChessboardCorners

Do not dilate binary images on first iteration in findChessboardCorners
This commit is contained in:
Alexander Smorkalov 2024-02-12 15:40:02 +03:00 committed by GitHub
commit 82914e442c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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,12 +596,12 @@ 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
{
if (dilations > 0)
dilate( thresh_img, thresh_img, Mat(), Point(-1, -1), 1 );
}
SHOW("Old binarization", thresh_img);