Hi,I did the translation of contour points (about 300-1000 points) i.e. each point I changed its X and Y coordinates to move the center of vector XOY to the center of gravity with this formula:
vector<vector<Point> > contours_poly( contours.size() );
vector<vector<Point> > contours( contours.size() );
for(unsigned int i=0;i<contours.size();i++)
{
approxPolyDP( Mat(contours[i]), contours_poly[i], 2, true );
convexHull( Mat(contours[i]), hull[i], false );
}
/// centre de gravité
vector<Moments> mu(contours.size() );
for( int i = 0; i < contours.size(); i++ ){
mu[i] = moments( contours[i], false );
}
vector<Point2f> mc( contours.size() );
for( int i = 0; i < contours.size(); i++ ){
mc[i] = Point2f( mu[i].m10/mu[i].m00 , mu[i].m01/mu[i].m00 );
}
/// Translation* the program bug here !!
for(i=0; i < contours.size(); i++)
{ contours_poly[1][i].x -= mc[1].x;
contours_poly[1][i].y -= mc[1].y;
}
/// draw the new contour
for(unsigned int i=0;i<contours.size();i++)
{
drawContours( drawing, contours_poly, i, colors, 1, 8, vector<Vec4i>(), 0, Point() );
}
But I do not know if the bug is generated by the modification of a large number of points or the formula is false because here is the result: the application has requested the Runtime to terminate it in an unusual way.
Thanks