mirror of
https://github.com/opencv/opencv.git
synced 2025-06-12 20:42:53 +08:00
Merge pull request #21275 from stal12:CCL_improvements
Improve CCL with new algorithms and tests * Improve CCL with new algorithms and tests * Split CCL test into dedicated tests cases
This commit is contained in:
parent
49bef1cdbf
commit
91817bffe1
@ -1278,3 +1278,11 @@
|
||||
pages={281--305},
|
||||
year={1987}
|
||||
}
|
||||
@article{Bolelli2021,
|
||||
title={One DAG to Rule Them All},
|
||||
author={Bolelli, Federico and Allegretti, Stefano and Grana, Costantino},
|
||||
journal={IEEE Transactions on Pattern Analysis and Machine Intelligence},
|
||||
year={2021},
|
||||
publisher={IEEE},
|
||||
doi = {10.1109/TPAMI.2021.3055337}
|
||||
}
|
||||
|
@ -406,10 +406,10 @@ enum ConnectedComponentsTypes {
|
||||
|
||||
//! connected components algorithm
|
||||
enum ConnectedComponentsAlgorithmsTypes {
|
||||
CCL_DEFAULT = -1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF.
|
||||
CCL_DEFAULT = -1, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, Spaghetti4C @cite Bolelli2021 algorithm for 4-way connectivity.
|
||||
CCL_WU = 0, //!< SAUF @cite Wu2009 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for SAUF.
|
||||
CCL_GRANA = 1, //!< BBDT @cite Grana2010 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both BBDT and SAUF.
|
||||
CCL_BOLELLI = 2, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity.
|
||||
CCL_BOLELLI = 2, //!< Spaghetti @cite Bolelli2019 algorithm for 8-way connectivity, Spaghetti4C @cite Bolelli2021 algorithm for 4-way connectivity. The parallel implementation described in @cite Bolelli2017 is available for both Spaghetti and Spaghetti4C.
|
||||
CCL_SAUF = 3, //!< Same as CCL_WU. It is preferable to use the flag with the name of the algorithm (CCL_SAUF) rather than the one with the name of the first author (CCL_WU).
|
||||
CCL_BBDT = 4, //!< Same as CCL_GRANA. It is preferable to use the flag with the name of the algorithm (CCL_BBDT) rather than the one with the name of the first author (CCL_GRANA).
|
||||
CCL_SPAGHETTI = 5, //!< Same as CCL_BOLELLI. It is preferable to use the flag with the name of the algorithm (CCL_SPAGHETTI) rather than the one with the name of the first author (CCL_BOLELLI).
|
||||
@ -3912,9 +3912,10 @@ image with 4 or 8 way connectivity - returns N, the total number of labels [0, N
|
||||
represents the background label. ltype specifies the output label image type, an important
|
||||
consideration based on the total number of labels or alternatively the total number of pixels in
|
||||
the source image. ccltype specifies the connected components labeling algorithm to use, currently
|
||||
Grana (BBDT) and Wu's (SAUF) @cite Wu2009 algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes
|
||||
for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
|
||||
This function uses parallel version of both Grana and Wu's algorithms if at least one allowed
|
||||
Bolelli (Spaghetti) @cite Bolelli2019, Grana (BBDT) @cite Grana2010 and Wu's (SAUF) @cite Wu2009 algorithms
|
||||
are supported, see the #ConnectedComponentsAlgorithmsTypes for details. Note that SAUF algorithm forces
|
||||
a row major ordering of labels while Spaghetti and BBDT do not.
|
||||
This function uses parallel version of the algorithms if at least one allowed
|
||||
parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.
|
||||
|
||||
@param image the 8-bit single-channel image to be labeled
|
||||
@ -3944,9 +3945,10 @@ image with 4 or 8 way connectivity - returns N, the total number of labels [0, N
|
||||
represents the background label. ltype specifies the output label image type, an important
|
||||
consideration based on the total number of labels or alternatively the total number of pixels in
|
||||
the source image. ccltype specifies the connected components labeling algorithm to use, currently
|
||||
Grana's (BBDT) and Wu's (SAUF) @cite Wu2009 algorithms are supported, see the #ConnectedComponentsAlgorithmsTypes
|
||||
for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
|
||||
This function uses parallel version of both Grana and Wu's algorithms (statistics included) if at least one allowed
|
||||
Bolelli (Spaghetti) @cite Bolelli2019, Grana (BBDT) @cite Grana2010 and Wu's (SAUF) @cite Wu2009 algorithms
|
||||
are supported, see the #ConnectedComponentsAlgorithmsTypes for details. Note that SAUF algorithm forces
|
||||
a row major ordering of labels while Spaghetti and BBDT do not.
|
||||
This function uses parallel version of the algorithms (statistics included) if at least one allowed
|
||||
parallel framework is enabled and if the rows of the image are at least twice the number returned by #getNumberOfCPUs.
|
||||
|
||||
@param image the 8-bit single-channel image to be labeled
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -42,7 +42,8 @@
|
||||
|
||||
#include "test_precomp.hpp"
|
||||
|
||||
namespace opencv_test { namespace {
|
||||
namespace opencv_test {
|
||||
namespace {
|
||||
|
||||
class CV_ConnectedComponentsTest : public cvtest::BaseTest
|
||||
{
|
||||
@ -357,4 +358,436 @@ TEST(Imgproc_ConnectedComponents, spaghetti_bbdt_sauf_stats)
|
||||
}
|
||||
}
|
||||
|
||||
}} // namespace
|
||||
TEST(Imgproc_ConnectedComponents, chessboard_even)
|
||||
{
|
||||
cv::Size size(16, 16);
|
||||
cv::Mat1b input(size);
|
||||
cv::Mat1i output_8c(size);
|
||||
cv::Mat1i output_4c(size);
|
||||
|
||||
// Chessboard image with even number of rows and cols
|
||||
// Note that this is the maximum number of labels for 4-way connectivity
|
||||
{
|
||||
input <<
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||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||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1;
|
||||
|
||||
output_4c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0,
|
||||
0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16,
|
||||
17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0,
|
||||
0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 32,
|
||||
33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0, 40, 0,
|
||||
0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0, 48,
|
||||
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0,
|
||||
0, 57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64,
|
||||
65, 0, 66, 0, 67, 0, 68, 0, 69, 0, 70, 0, 71, 0, 72, 0,
|
||||
0, 73, 0, 74, 0, 75, 0, 76, 0, 77, 0, 78, 0, 79, 0, 80,
|
||||
81, 0, 82, 0, 83, 0, 84, 0, 85, 0, 86, 0, 87, 0, 88, 0,
|
||||
0, 89, 0, 90, 0, 91, 0, 92, 0, 93, 0, 94, 0, 95, 0, 96,
|
||||
97, 0, 98, 0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0, 104, 0,
|
||||
0, 105, 0, 106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0, 112,
|
||||
113, 0, 114, 0, 115, 0, 116, 0, 117, 0, 118, 0, 119, 0, 120, 0,
|
||||
0, 121, 0, 122, 0, 123, 0, 124, 0, 125, 0, 126, 0, 127, 0, 128;
|
||||
}
|
||||
|
||||
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
cv::Mat1i labels;
|
||||
cv::Mat diff;
|
||||
int nLabels = 0;
|
||||
for (size_t cclt = 0; cclt < sizeof(ccltype) / sizeof(int); ++cclt) {
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 8, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_8c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 4, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_4c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, chessboard_odd)
|
||||
{
|
||||
cv::Size size(15, 15);
|
||||
cv::Mat1b input(size);
|
||||
cv::Mat1i output_8c(size);
|
||||
cv::Mat1i output_4c(size);
|
||||
|
||||
// Chessboard image with odd number of rows and cols
|
||||
// Note that this is the maximum number of labels for 4-way connectivity
|
||||
{
|
||||
input <<
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
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 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1,
|
||||
0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1;
|
||||
|
||||
output_4c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
|
||||
0, 9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0,
|
||||
16, 0, 17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23,
|
||||
0, 24, 0, 25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0,
|
||||
31, 0, 32, 0, 33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38,
|
||||
0, 39, 0, 40, 0, 41, 0, 42, 0, 43, 0, 44, 0, 45, 0,
|
||||
46, 0, 47, 0, 48, 0, 49, 0, 50, 0, 51, 0, 52, 0, 53,
|
||||
0, 54, 0, 55, 0, 56, 0, 57, 0, 58, 0, 59, 0, 60, 0,
|
||||
61, 0, 62, 0, 63, 0, 64, 0, 65, 0, 66, 0, 67, 0, 68,
|
||||
0, 69, 0, 70, 0, 71, 0, 72, 0, 73, 0, 74, 0, 75, 0,
|
||||
76, 0, 77, 0, 78, 0, 79, 0, 80, 0, 81, 0, 82, 0, 83,
|
||||
0, 84, 0, 85, 0, 86, 0, 87, 0, 88, 0, 89, 0, 90, 0,
|
||||
91, 0, 92, 0, 93, 0, 94, 0, 95, 0, 96, 0, 97, 0, 98,
|
||||
0, 99, 0, 100, 0, 101, 0, 102, 0, 103, 0, 104, 0, 105, 0,
|
||||
106, 0, 107, 0, 108, 0, 109, 0, 110, 0, 111, 0, 112, 0, 113;
|
||||
}
|
||||
|
||||
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
cv::Mat1i labels;
|
||||
cv::Mat diff;
|
||||
int nLabels = 0;
|
||||
for (size_t cclt = 0; cclt < sizeof(ccltype) / sizeof(int); ++cclt) {
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 8, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_8c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 4, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_4c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, maxlabels_8conn_even)
|
||||
{
|
||||
cv::Size size(16, 16);
|
||||
cv::Mat1b input(size);
|
||||
cv::Mat1i output_8c(size);
|
||||
cv::Mat1i output_4c(size);
|
||||
|
||||
{
|
||||
input <<
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0,
|
||||
0, 0, 0, 0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, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 32, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0, 40, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0, 48, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
|
||||
|
||||
output_4c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 32, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0, 40, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0, 48, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64, 0,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0;
|
||||
}
|
||||
|
||||
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
cv::Mat1i labels;
|
||||
cv::Mat diff;
|
||||
int nLabels = 0;
|
||||
for (size_t cclt = 0; cclt < sizeof(ccltype) / sizeof(int); ++cclt) {
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 8, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_8c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 4, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_4c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, maxlabels_8conn_odd)
|
||||
{
|
||||
cv::Size size(15, 15);
|
||||
cv::Mat1b input(size);
|
||||
cv::Mat1i output_8c(size);
|
||||
cv::Mat1i output_4c(size);
|
||||
|
||||
{
|
||||
input <<
|
||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 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 32,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0, 40,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0, 48,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64;
|
||||
|
||||
output_4c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
9, 0, 10, 0, 11, 0, 12, 0, 13, 0, 14, 0, 15, 0, 16,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
17, 0, 18, 0, 19, 0, 20, 0, 21, 0, 22, 0, 23, 0, 24,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
25, 0, 26, 0, 27, 0, 28, 0, 29, 0, 30, 0, 31, 0, 32,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
33, 0, 34, 0, 35, 0, 36, 0, 37, 0, 38, 0, 39, 0, 40,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
41, 0, 42, 0, 43, 0, 44, 0, 45, 0, 46, 0, 47, 0, 48,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
49, 0, 50, 0, 51, 0, 52, 0, 53, 0, 54, 0, 55, 0, 56,
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
57, 0, 58, 0, 59, 0, 60, 0, 61, 0, 62, 0, 63, 0, 64;
|
||||
}
|
||||
|
||||
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
cv::Mat1i labels;
|
||||
cv::Mat diff;
|
||||
int nLabels = 0;
|
||||
for (size_t cclt = 0; cclt < sizeof(ccltype) / sizeof(int); ++cclt) {
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 8, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_8c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 4, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_4c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, single_row)
|
||||
{
|
||||
cv::Size size(1, 15);
|
||||
cv::Mat1b input(size);
|
||||
cv::Mat1i output_8c(size);
|
||||
cv::Mat1i output_4c(size);
|
||||
|
||||
{
|
||||
input <<
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1;
|
||||
|
||||
|
||||
output_8c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
|
||||
|
||||
|
||||
output_4c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
|
||||
|
||||
}
|
||||
|
||||
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
cv::Mat1i labels;
|
||||
cv::Mat diff;
|
||||
int nLabels = 0;
|
||||
for (size_t cclt = 0; cclt < sizeof(ccltype) / sizeof(int); ++cclt) {
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 8, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_8c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 4, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_4c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
TEST(Imgproc_ConnectedComponents, single_column)
|
||||
{
|
||||
cv::Size size(15, 1);
|
||||
cv::Mat1b input(size);
|
||||
cv::Mat1i output_8c(size);
|
||||
cv::Mat1i output_4c(size);
|
||||
|
||||
{
|
||||
input <<
|
||||
1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1, 0, 1;
|
||||
|
||||
|
||||
output_8c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
|
||||
|
||||
|
||||
output_4c <<
|
||||
1, 0, 2, 0, 3, 0, 4, 0, 5, 0, 6, 0, 7, 0, 8;
|
||||
|
||||
}
|
||||
|
||||
int ccltype[] = { cv::CCL_DEFAULT, cv::CCL_WU, cv::CCL_GRANA, cv::CCL_BOLELLI, cv::CCL_SAUF, cv::CCL_BBDT, cv::CCL_SPAGHETTI };
|
||||
|
||||
cv::Mat1i labels;
|
||||
cv::Mat diff;
|
||||
int nLabels = 0;
|
||||
for (size_t cclt = 0; cclt < sizeof(ccltype) / sizeof(int); ++cclt) {
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 8, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_8c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
|
||||
|
||||
EXPECT_NO_THROW(nLabels = cv::connectedComponents(input, labels, 4, CV_32S, ccltype[cclt]));
|
||||
normalizeLabels(labels, nLabels);
|
||||
|
||||
diff = labels != output_4c;
|
||||
EXPECT_EQ(cv::countNonZero(diff), 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
} // namespace
|
||||
|
Loading…
Reference in New Issue
Block a user