From 24ce1a233960601bc8a00e1fe1a4aecde91dc532 Mon Sep 17 00:00:00 2001 From: boyska Date: Thu, 5 Jan 2017 17:04:02 +0100 Subject: [PATCH] maximum algorithm slightly simpler --- lines.cpp | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/lines.cpp b/lines.cpp index 6fa6434..04c6f6c 100644 --- a/lines.cpp +++ b/lines.cpp @@ -19,27 +19,25 @@ int main(int argc, char *argv[]) std::vector hull; cv::convexHull(cv::Mat(contours[0]),hull,false); - int i; - int idx[4]={0}; + // takes the two points that are more distant from the next, ie: + // i st distance(hull[i], hull[i+1]) is maximum and 2nd maximum + int idx[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 two=hull[(i+1)%hull.size()]; - int d=pow(one.x-two.x,2)+pow(one.y-two.y,2); - if( d>distance[0] ) + cv::Point thispoint=hull[i]; + cv::Point nextpoint=hull[(i+1)%hull.size()]; + int d=pow(thispoint.x-nextpoint.x,2)+pow(thispoint.y-nextpoint.y,2); + if( d>distance[0] ) //the biggest till now { idx[1]=idx[0]; - idx[3]=(idx[1]+1)%hull.size(); idx[0]=i; - idx[2]=(idx[0]+1)%hull.size(); distance[1]=distance[0]; distance[0]=d; } - else if( d>distance[1] ) + else if( d>distance[1] ) // it is the second biggest till now { idx[1]=i; - idx[3]=(i+1)%hull.size(); distance[1]=d; } } @@ -61,3 +59,5 @@ int main(int argc, char *argv[]) return 0; } + +// vim: set noet ts=4 sw=4: