maximum algorithm slightly simpler

This commit is contained in:
boyska 2017-01-05 17:04:02 +01:00
parent 1d75808c0e
commit 24ce1a2339

View file

@ -19,27 +19,25 @@ int main(int argc, char *argv[])
std::vector<cv::Point> hull; std::vector<cv::Point> hull;
cv::convexHull(cv::Mat(contours[0]),hull,false); cv::convexHull(cv::Mat(contours[0]),hull,false);
int i; // takes the two points that are more distant from the next, ie:
int idx[4]={0}; // i st distance(hull[i], hull[i+1]) is maximum and 2nd maximum
int idx[2]={0};
int distance[2]={0}; int distance[2]={0};
for( i=0; hull.size()>i; i++ ) for( unsigned i=0; hull.size()>i; i++ )
{ {
cv::Point one=hull[i]; cv::Point thispoint=hull[i];
cv::Point two=hull[(i+1)%hull.size()]; cv::Point nextpoint=hull[(i+1)%hull.size()];
int d=pow(one.x-two.x,2)+pow(one.y-two.y,2); int d=pow(thispoint.x-nextpoint.x,2)+pow(thispoint.y-nextpoint.y,2);
if( d>distance[0] ) if( d>distance[0] ) //the biggest till now
{ {
idx[1]=idx[0]; idx[1]=idx[0];
idx[3]=(idx[1]+1)%hull.size();
idx[0]=i; idx[0]=i;
idx[2]=(idx[0]+1)%hull.size();
distance[1]=distance[0]; distance[1]=distance[0];
distance[0]=d; distance[0]=d;
} }
else if( d>distance[1] ) else if( d>distance[1] ) // it is the second biggest till now
{ {
idx[1]=i; idx[1]=i;
idx[3]=(i+1)%hull.size();
distance[1]=d; distance[1]=d;
} }
} }
@ -61,3 +59,5 @@ int main(int argc, char *argv[])
return 0; return 0;
} }
// vim: set noet ts=4 sw=4: