Structural Analysis and Shape Descriptors#
Detailed Description#
Namespaces#
Classes#
Name |
Description |
|---|---|
|
finds arbitrary template in the grayscale image using Generalized Hough Transform View details |
finds arbitrary template in the grayscale image using Generalized Hough Transform View details |
|
|
finds arbitrary template in the grayscale image using Generalized Hough Transform View details |
|
struct returned by cv::moments View details |
Enumerations#
enum cv::ConnectedComponentsAlgorithmsTypes {
cv::CCL_DEFAULT = -1,
cv::CCL_WU = 0,
cv::CCL_GRANA = 1,
cv::CCL_BOLELLI = 2,
cv::CCL_SAUF = 3,
cv::CCL_BBDT = 4,
cv::CCL_SPAGHETTI = 5
}connected components algorithm View details
enum cv::ConnectedComponentsTypes {
cv::CC_STAT_LEFT = 0,
cv::CC_STAT_TOP = 1,
cv::CC_STAT_WIDTH = 2,
cv::CC_STAT_HEIGHT = 3,
cv::CC_STAT_AREA = 4
}connected components statistics View details
enum cv::ContourApproximationModes {
cv::CHAIN_CODE = 0,
cv::CHAIN_APPROX_NONE = 1,
cv::CHAIN_APPROX_SIMPLE = 2,
cv::CHAIN_APPROX_TC89_L1 = 3,
cv::CHAIN_APPROX_TC89_KCOS = 4,
cv::LINK_RUNS = 5
}the contour approximation algorithm View details
enum cv::RetrievalModes {
cv::RETR_EXTERNAL = 0,
cv::RETR_LIST = 1,
cv::RETR_CCOMP = 2,
cv::RETR_TREE = 3,
cv::RETR_FLOODFILL = 4
}mode of the contour retrieval algorithm View details
enum cv::ShapeMatchModes {
cv::CONTOURS_MATCH_I1 =1,
cv::CONTOURS_MATCH_I2 =2,
cv::CONTOURS_MATCH_I3 =3
}Shape matching methods. View details
Enumeration Type Documentation#
ConnectedComponentsAlgorithmsTypes#
enum cv::ConnectedComponentsAlgorithmsTypes
#include <opencv2/imgproc.hpp>
connected components algorithm
Enumerator:
|
Spaghetti [36] algorithm for 8-way connectivity, Spaghetti4C [37] algorithm for 4-way connectivity. |
|
SAUF [337] algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in [35] is available for SAUF. |
|
BBDT [122] algorithm for 8-way connectivity, SAUF algorithm for 4-way connectivity. The parallel implementation described in [35] is available for both BBDT and SAUF. |
|
Spaghetti [36] algorithm for 8-way connectivity, Spaghetti4C [37] algorithm for 4-way connectivity. The parallel implementation described in [35] is available for both Spaghetti and Spaghetti4C. |
|
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). |
|
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). |
|
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). |
ConnectedComponentsTypes#
enum cv::ConnectedComponentsTypes
#include <opencv2/imgproc.hpp>
connected components statistics
Enumerator:
|
The leftmost (x) coordinate which is the inclusive start of the bounding box in the horizontal direction. |
|
The topmost (y) coordinate which is the inclusive start of the bounding box in the vertical direction. |
|
The horizontal size of the bounding box. |
|
The vertical size of the bounding box. |
|
The total area (in pixels) of the connected component. |
ContourApproximationModes#
enum cv::ContourApproximationModes
#include <opencv2/imgproc.hpp>
the contour approximation algorithm
Enumerator:
|
TBD |
|
stores absolutely all the contour points. That is, any 2 subsequent points (x1,y1) and (x2,y2) of the contour will be either horizontal, vertical or diagonal neighbors, that is, max(abs(x1-x2),abs(y2-y1))==1. |
|
compresses horizontal, vertical, and diagonal segments and leaves only their end points. For example, an up-right rectangular contour is encoded with 4 points. |
|
applies one of the flavors of the Teh-Chin chain approximation algorithm [300] |
|
applies one of the flavors of the Teh-Chin chain approximation algorithm [300] |
|
TBD |
RetrievalModes#
enum cv::RetrievalModes
#include <opencv2/imgproc.hpp>
mode of the contour retrieval algorithm
Enumerator:
|
retrieves only the extreme outer contours. It sets |
|
retrieves all of the contours without establishing any hierarchical relationships. |
|
retrieves all of the contours and organizes them into a two-level hierarchy. At the top level, there are external boundaries of the components. At the second level, there are boundaries of the holes. If there is another contour inside a hole of a connected component, it is still put at the top level. |
|
retrieves all of the contours and reconstructs a full hierarchy of nested contours. |
|
ShapeMatchModes#
enum cv::ShapeMatchModes
#include <opencv2/imgproc.hpp>
Shape matching methods.
\(A\) denotes object1, \(B\) denotes object2
\(\begin{array}{l} m^A_i = \mathrm{sign} (h^A_i) \cdot \log{h^A_i} \\ m^B_i = \mathrm{sign} (h^B_i) \cdot \log{h^B_i} \end{array}\)
and \(h^A_i, h^B_i\) are the Hu moments of \(A\) and \(B\) , respectively.
Enumerator:
|
\[
I_1(A,B) = \sum _{i=1...7} \left | \frac{1}{m^A_i} - \frac{1}{m^B_i} \right |
\]
|
|
\[
I_2(A,B) = \sum _{i=1...7} \left | m^A_i - m^B_i \right |
\]
|
|
\[
I_3(A,B) = \max _{i=1...7} \frac{ \left| m^A_i - m^B_i \right| }{ \left| m^A_i \right| }
\]
|
Function Documentation#
connectedComponents()#
int cv::connectedComponents(
InputArray image,
OutputArray labels,
int connectivity,
int ltype,
int ccltype )
#include <opencv2/imgproc.hpp>
Python:
cv.connectedComponents(image[, labels[, connectivity[, ltype]]]) -> retval, labels
cv.connectedComponentsWithAlgorithm(image, connectivity, ltype, ccltype[, labels]) -> retval, labels
computes the connected components labeled image of boolean image
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 Bolelli (Spaghetti) [36], Grana (BBDT) [122] and Wu’s (SAUF) [337] 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.
Parameters
image— the 8-bit single-channel image to be labeledlabels— destination labeled imageconnectivity— 8 or 4 for 8-way or 4-way connectivity respectivelyltype— output image label type. Currently CV_32S and CV_16U are supported.ccltype— connected components algorithm type (see the ConnectedComponentsAlgorithmsTypes).
connectedComponents()#
int cv::connectedComponents(
InputArray image,
OutputArray labels,
int connectivity = 8,
int ltype = CV_32S )
#include <opencv2/imgproc.hpp>
Python:
cv.connectedComponents(image[, labels[, connectivity[, ltype]]]) -> retval, labels
cv.connectedComponentsWithAlgorithm(image, connectivity, ltype, ccltype[, labels]) -> retval, labels
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters
image— the 8-bit single-channel image to be labeledlabels— destination labeled imageconnectivity— 8 or 4 for 8-way or 4-way connectivity respectivelyltype— output image label type. Currently CV_32S and CV_16U are supported.
connectedComponentsWithStats()#
int cv::connectedComponentsWithStats(
InputArray image,
OutputArray labels,
OutputArray stats,
OutputArray centroids,
int connectivity,
int ltype,
int ccltype )
#include <opencv2/imgproc.hpp>
Python:
cv.connectedComponentsWithStats(image[, labels[, stats[, centroids[, connectivity[, ltype]]]]]) -> retval, labels, stats, centroids
cv.connectedComponentsWithStatsWithAlgorithm(image, connectivity, ltype, ccltype[, labels[, stats[, centroids]]]) -> retval, labels, stats, centroids
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 Bolelli (Spaghetti) [36], Grana (BBDT) [122] and Wu’s (SAUF) [337] 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.
Parameters
image— the 8-bit single-channel image to be labeledlabels— destination labeled imagestats— statistics output for each label, including the background label. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of ConnectedComponentsTypes, selecting the statistic. The data type is CV_32S.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.connectivity— 8 or 4 for 8-way or 4-way connectivity respectivelyltype— output image label type. Currently CV_32S and CV_16U are supported.ccltype— connected components algorithm type (see ConnectedComponentsAlgorithmsTypes).
connectedComponentsWithStats()#
int cv::connectedComponentsWithStats(
InputArray image,
OutputArray labels,
OutputArray stats,
OutputArray centroids,
int connectivity = 8,
int ltype = CV_32S )
#include <opencv2/imgproc.hpp>
Python:
cv.connectedComponentsWithStats(image[, labels[, stats[, centroids[, connectivity[, ltype]]]]]) -> retval, labels, stats, centroids
cv.connectedComponentsWithStatsWithAlgorithm(image, connectivity, ltype, ccltype[, labels[, stats[, centroids]]]) -> retval, labels, stats, centroids
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
Parameters
image— the 8-bit single-channel image to be labeledlabels— destination labeled imagestats— statistics output for each label, including the background label. Statistics are accessed via stats(label, COLUMN) where COLUMN is one of ConnectedComponentsTypes, selecting the statistic. The data type is CV_32S.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.connectivity— 8 or 4 for 8-way or 4-way connectivity respectivelyltype— output image label type. Currently CV_32S and CV_16U are supported.
createGeneralizedHoughBallard()#
Ptr< GeneralizedHoughBallard > cv::createGeneralizedHoughBallard()
#include <opencv2/imgproc.hpp>
Python:
cv.createGeneralizedHoughBallard() -> retval
Creates a smart pointer to a cv::GeneralizedHoughBallard class and initializes it.
createGeneralizedHoughGuil()#
Ptr< GeneralizedHoughGuil > cv::createGeneralizedHoughGuil()
#include <opencv2/imgproc.hpp>
Python:
cv.createGeneralizedHoughGuil() -> retval
Creates a smart pointer to a cv::GeneralizedHoughGuil class and initializes it.
findContours()#
void cv::findContours(
InputArray image,
OutputArrayOfArrays contours,
int mode,
int method,
Point offset = Point() )
#include <opencv2/imgproc.hpp>
Python:
cv.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> contours, hierarchy
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
findContours()#
void cv::findContours(
InputArray image,
OutputArrayOfArrays contours,
OutputArray hierarchy,
int mode,
int method,
Point offset = Point() )
#include <opencv2/imgproc.hpp>
Python:
cv.findContours(image, mode, method[, contours[, hierarchy[, offset]]]) -> contours, hierarchy
Finds contours in a binary image.
The function retrieves contours from the binary image. The contours are a useful tool for shape analysis and object detection and recognition. See squares.cpp in the OpenCV sample directory.
Note
Since OpenCV 4.14, when mode is RETR_LIST and no hierarchy is requested, this function automatically uses the TRUCO parallel algorithm [224], a scalable lock-free method for contour extraction. In all other cases, the sequential [287] algorithm is used.
Since opencv 3.2 source image is not modified by this function.
In Python, hierarchy is nested inside a top level array. Use hierarchy[0][i] to access hierarchical elements of i-th contour.
Parameters
image— Source, an 8-bit single-channel image. Non-zero pixels are treated as 1’s. Zero pixels remain 0’s, so the image is treated as binary . You can use compare, inRange, threshold , adaptiveThreshold, Canny, and others to create a binary image out of a grayscale or color one. If mode equals to RETR_CCOMP or RETR_FLOODFILL, the input can also be a 32-bit integer image of labels (CV_32SC1).contours— Detected contours. Each contour is stored as a vector of points (e.g. std::vector<std::vector<cv::Point> >).hierarchy— Optional output vector (e.g. std::vector<cv::Vec4i>), containing information about the image topology. It has as many elements as the number of contours. For each i-th contour contours[i], the elements hierarchy[i][0] , hierarchy[i][1] , hierarchy[i][2] , and hierarchy[i][3] are set to 0-based indices in contours of the next and previous contours at the same hierarchical level, the first child contour and the parent contour, respectively. If for the contour i there are no next, previous, parent, or nested contours, the corresponding elements of hierarchy[i] will be negative.mode— Contour retrieval mode, see RetrievalModesmethod— Contour approximation method, see ContourApproximationModesoffset— Optional offset by which every contour point is shifted. This is useful if the contours are extracted from the image ROI and then they should be analyzed in the whole image context.
findContoursLinkRuns()#
void cv::findContoursLinkRuns(
InputArray image,
OutputArrayOfArrays contours )
#include <opencv2/imgproc.hpp>
Python:
cv.findContoursLinkRuns(image[, contours[, hierarchy]]) -> contours, hierarchy
cv.findContoursLinkRuns(image[, contours]) -> contours
This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
findContoursLinkRuns()#
void cv::findContoursLinkRuns(
InputArray image,
OutputArrayOfArrays contours,
OutputArray hierarchy )
#include <opencv2/imgproc.hpp>
Python:
cv.findContoursLinkRuns(image[, contours[, hierarchy]]) -> contours, hierarchy
cv.findContoursLinkRuns(image[, contours]) -> contours
Find contours using link runs algorithm.
This function implements an algorithm different from cv::findContours:
doesn’t allocate temporary image internally, thus it has reduced memory consumption
supports CV_8UC1 images only
outputs 2-level hierarhy only (RETR_CCOMP mode)
doesn’t support approximation change other than CHAIN_APPROX_SIMPLE In all other aspects this function is compatible with cv::findContours.