mirror of
https://github.com/opencv/opencv.git
synced 2026-07-31 08:13:04 +04:00
Add Grana's connected components algorithm for 8-way connectivity. (#6823)
* Add Grana's connected components algorithm for 8-way connectivity. That algorithm is faster than Wu's one (currently implemented in opencv). For more details see https://github.com/prittt/YACCLAB. * New functions signature and distance transform compatibility * Add tests to imgproc/test/test_connectedcomponents.cpp * Change of test_connectedcomponents.cpp for c++98 support
This commit is contained in:
@@ -413,6 +413,13 @@ enum ConnectedComponentsTypes {
|
||||
CC_STAT_MAX = 5
|
||||
};
|
||||
|
||||
//! connected components algorithm
|
||||
enum ConnectedComponentsAlgorithmsTypes {
|
||||
CCL_WU = 0, //!< SAUF algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
|
||||
CCL_DEFAULT = -1, //!< BBDT algortihm for 8-way connectivity, SAUF algorithm for 4-way connectivity
|
||||
CCL_GRANA = 1 //!< BBDT algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity
|
||||
};
|
||||
|
||||
//! mode of the contour retrieval algorithm
|
||||
enum RetrievalModes {
|
||||
/** retrieves only the extreme outer contours. It sets `hierarchy[i][2]=hierarchy[i][3]=-1` for
|
||||
@@ -3648,16 +3655,56 @@ CV_EXPORTS_W void matchTemplate( InputArray image, InputArray templ,
|
||||
image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0
|
||||
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.
|
||||
the source image. ccltype specifies the connected components labeling algorithm to use, currently
|
||||
Grana's (BBDT) and Wu's (SAUF) algorithms are supported, see the cv::ConnectedComponentsAlgorithmsTypes
|
||||
for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
|
||||
|
||||
@param image the 8-bit single-channel image to be labeled
|
||||
@param labels destination labeled image
|
||||
@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
|
||||
@param ltype output image label type. Currently CV_32S and CV_16U are supported.
|
||||
*/
|
||||
@param ccltype connected components algorithm type (see the cv::ConnectedComponentsAlgorithmsTypes).
|
||||
*/
|
||||
CV_EXPORTS_AS(connectedComponentsWithAlgorithm) int connectedComponents(InputArray image, OutputArray labels,
|
||||
int connectivity, int ltype, int ccltype);
|
||||
|
||||
|
||||
/** @overload
|
||||
|
||||
@param image the 8-bit single-channel image to be labeled
|
||||
@param labels destination labeled image
|
||||
@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
|
||||
@param ltype output image label type. Currently CV_32S and CV_16U are supported.
|
||||
*/
|
||||
CV_EXPORTS_W int connectedComponents(InputArray image, OutputArray labels,
|
||||
int connectivity = 8, int ltype = CV_32S);
|
||||
|
||||
|
||||
/** @brief computes the connected components labeled image of boolean image and also produces a statistics output for each label
|
||||
|
||||
image with 4 or 8 way connectivity - returns N, the total number of labels [0, N-1] where 0
|
||||
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) algorithms are supported, see the cv::ConnectedComponentsAlgorithmsTypes
|
||||
for details. Note that SAUF algorithm forces a row major ordering of labels while BBDT does not.
|
||||
|
||||
|
||||
@param image the 8-bit single-channel image to be labeled
|
||||
@param labels destination labeled image
|
||||
@param stats statistics output for each label, including the background label, see below for
|
||||
available statistics. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of
|
||||
cv::ConnectedComponentsTypes. The data type is CV_32S.
|
||||
@param centroids centroid output for each label, including the background label. Centroids are
|
||||
accessed via centroids(label, 0) for x and centroids(label, 1) for y. The data type CV_64F.
|
||||
@param connectivity 8 or 4 for 8-way or 4-way connectivity respectively
|
||||
@param ltype output image label type. Currently CV_32S and CV_16U are supported.
|
||||
@param ccltype connected components algorithm type (see the cv::ConnectedComponentsAlgorithmsTypes).
|
||||
*/
|
||||
CV_EXPORTS_AS(connectedComponentsWithStatsWithAlgorithm) int connectedComponentsWithStats(InputArray image, OutputArray labels,
|
||||
OutputArray stats, OutputArray centroids,
|
||||
int connectivity, int ltype, int ccltype);
|
||||
|
||||
/** @overload
|
||||
@param image the 8-bit single-channel image to be labeled
|
||||
@param labels destination labeled image
|
||||
|
||||
Reference in New Issue
Block a user