Home > other >  Connected domain function connectedComponentsWithStats subsequent processing function
Connected domain function connectedComponentsWithStats subsequent processing function

Time:10-22

Want to be in the subsequent processing of the connected domain function, the perimeter of each connected domain area, etc.
Related functions can operate?
Still need your handwritten
Or use findContours function?
Feeling using findContours function is equal to the analysis of the two is a waste,

CodePudding user response:

I recommend this
Feature extraction of the comprehensive experiment (multiple Angle SIFT, SURF, your BRISK, ORB algorithm)
https://www.cnblogs.com/jsxyhelu/p/7813629.html
In addition to including:
https://zzk.cnblogs.com/my/s/blogpost-p? Keywords=% E7%89% % B9 E5 % BE 82% % 81% E7 % B9

CodePudding user response:

The hair is wrong, I recommend this
The new function of OpenCV connectedComponentsWithStats use
https://www.cnblogs.com/jsxyhelu/p/7439655.html
Main contents: the contrast between old and new function, used in filtering the original image contour analysis after a smaller area, leave a larger area,
Key words: connectedComponentsWithStats

In the past, the commonly used method is "is the first call CV: : findContours () function (afferent CV: : RETR_CCOMP mark), then in the connected area circulation call CV: : drawContours ()", "
For example, I was realized in GOCVHelper such
//looking for the biggest profile
VP FindBigestContour Mat (SRC) {
Int imax=0;//represents the largest outline of serial number
Int imaxcontour=1;//represents the size of the largest contour
std::vector Contours.
FindContours (SRC, contours, CV_RETR_LIST CV_CHAIN_APPROX_SIMPLE);
for (int i=0; iInt itmp=contourArea (contours [I]);//here is the outline size
If (imaxcontour & lt; Itmp) {
Imax=I;
Imaxcontour=itmp;
}
}
Return contours (imax);
}
//to find and to map the color unicom area
vector Connection2 (Mat SRC, Mat& The draw) {
The draw=Mat: : zeros (SRC) rows, SRC, cols, CV_8UC3);
vector Contours.
FindContours (SRC) clone (), contours, CV_RETR_LIST, CV_CHAIN_APPROX_SIMPLE);
//due to the large area color will cover small area, so first sorting operation
//bubble sort, from small to large order
The VP VPTMP;
for(int i=1; iFor (int j=contours. The size () - 1; J>=I; J -) {
If (contourArea (contours) [j] {
VPTMP=contours [j - 1);
Contours [1]=contours [j];
Contours [j]=VPTMP;
}
}
}
A new special function in OpenCV3 CV: : connectedComponents CV () and function: : connectedComponentsWithStats ()
Definition:
Int CV: : connectedComponents (
CV: : InputArrayn image,//input 8-bit single - channel (binary)
CV: : OutputArray labels,//the output label map
Int connectivity=8, 4 - or//8 - connected components
Int ltype=CV_32S//the Output label type (CV_32S or CV_16U)
);
Int CV: : connectedComponentsWithStats (
CV: : InputArrayn image,//input 8-bit single - channel (binary)
CV: : OutputArray labels,//the output label map
CV: : OutputArray stats,//Nx5 matrix (CV_32S) of the statistics:
//[x0, y0, width0 height0, area0;
//... ; X (N - 1), y (N - 1), width (N - 1),
//height (N - 1), area (N - 1)]
CV: : OutputArray centroids,//Nx2 CV_64F matrix of centroids:
//[cx0, cy0;...; cx (N - 1), cy (N - 1)]
Int connectivity=8, 4 - or//8 - connected components
Int ltype=CV_32S//the Output label type (CV_32S or CV_16U)
);
Among them, the new parameter
Stats: long
Corresponding to the contour of x, y, width, height and area, pay attention to the regional identity is 0 background
Center of the centroids is corresponding a
While the label corresponding to said is the current pixel is which a contour
Example:
For image
Mat img=CV: : imread (" e:/sandbox/the rect. PNG ", 0).
CV: : Mat img_edge, labels, img_color, stats, centroids;
CV: : threshold (img, img_edge, 128, 255, CV: : THRESH_BINARY);
Bitwise_not (img_edge img_edge);
CV: : imshow (" Image after threshold ", img_edge);
Int I, nccomps=CV: : connectedComponentsWithStats (
Img_edge, labels,
Stats, centroids
);
cout <"Total Connected Components Detected:" & lt; vectorColors [0]=Vec3b (0, 0);//background pixels remain black.
For (I=1; I & lt; Nccomps; I++) {
Colors [I]=Vec3b (rand () % 256, 256 rand () %, the rand () % 256);
If (stats. At (I, CV: : CC_STAT_AREA) & lt; 200)
Colors [I]=Vec3b (0, 0);//small regions made with black too.
}
Img_color=Mat: : zeros (img. The size (), CV_8UC3);
For (int y=0; Y & lt; Img_color. Rows; Y++)
For (int x=0; X & lt; Img_color. Cols; X++)
{
Int label=labels. At (y, x);
CV_Assert (0 & lt;=label & amp; & The label & lt;=nccomps);
Img_color. At}
CV: : imshow (Labeled "map", img_color);
CV: : waitKey ();
Note:
1, for OpenCV, white represents data, black represents no data, so the image before enter into "black white figure
"2, see the labels and stats, including 2 1 6 area smaller than 200
The labels of the
Completely on the number, the result is


CodePudding user response:

Bosses also encounter this problem, I find myself after connected domain traversal wrote a image, then find the coordinates of the edge, the requirements on the edge of the circumference of what now, arclength function requires coordinates is clockwise or counter-clockwise order, could you tell me how do you resolve oh, can share?

CodePudding user response:

The
refer to the original poster dzcssb1 response:
want to be in the subsequent processing of the connected domain function, the perimeter of each connected domain area, etc.
Related functions can operate?
Still need your handwritten
Or use findContours function?
Was analyzed by using the feeling findContours function is equivalent to two very waste,
the original poster to solve this problem, I also met don't know how to deal with this problem,
  • Related