@@ -89,34 +89,3 @@ void detectAndDraw( Mat img, CascadeClassifier& cascade,
8989 }
9090 // imshow( "result", img );
9191}
92-
93- void refineSegments (const Mat& img, Mat& mask, Mat& dst)
94- {
95- int niters = 3 ;
96- vector<vector<Point> > contours;
97- vector<Vec4i> hierarchy;
98- Mat temp;
99- dilate (mask, temp, Mat (), Point (-1 ,-1 ), niters);
100- erode (temp, temp, Mat (), Point (-1 ,-1 ), niters*2 );
101- dilate (temp, temp, Mat (), Point (-1 ,-1 ), niters);
102- findContours ( temp, contours, hierarchy, RETR_CCOMP, CHAIN_APPROX_SIMPLE );
103- dst = Mat::zeros (img.size (), CV_8UC3);
104- if ( contours.size () == 0 )
105- return ;
106- // iterate through all the top-level contours,
107- // draw each connected component with its own random color
108- int idx = 0 , largestComp = 0 ;
109- double maxArea = 0 ;
110- for ( ; idx >= 0 ; idx = hierarchy[idx][0 ] )
111- {
112- const vector<Point>& c = contours[idx];
113- double area = fabs (contourArea (Mat (c)));
114- if ( area > maxArea )
115- {
116- maxArea = area;
117- largestComp = idx;
118- }
119- }
120- Scalar color ( 0 , 0 , 255 );
121- drawContours ( dst, contours, largestComp, color, FILLED, LINE_8, hierarchy );
122- }
0 commit comments