Hello,
I'm doing the tutorial for the biggest contour detection by following the code from this program.
[biggest contour detection](http://harismoonamkunnu.blogspot.com/2013/06/opencv-find-biggest-contour-using-c.html)
I had edit the code to include the moment calculation and getting the centroid. Then I would like to draw the centroid on the biggest contour detected using circle statement. The problem now, there are images than can draw on the biggest contour detected AND also there are images draw more than one centroid i.e. for two blobs detected, there are 2 centroids will be draw. Which can be my coding mistake?
for( int i = 0; i< contours.size(); i++ ) // iterate through each contour.
{
double a=contourArea( contours[i],false); // Find the area of contour
if(a>largest_area)
{
largest_area=a;
largest_contour_index=i; //Store the index of largest contour
bounding_rect=boundingRect(contours[i]); // Find the bounding rectangle for biggest contour
circle( src, mc[i], 4, Scalar(0,0,255), -1, 8, 0 );//color the centroid point
std::cout << "x1 " << mc[i] << std::endl;
}
}
TQ
↧