4

I detected a rectangle by:

  1. finding contours
  2. approximating polygon

then I tried to find the corners of the rectangle as:

imgPoints[0]=contours_poly[i][0];  
imgPoints[1]=contours_poly[i][1];  
imgPoints[3]=contours_poly[i][3];  
imgPoints[2]=contours_poly[i][2]; 

I want to order these points in a predefined order due to a reference point. Let's say I want to start at point 0, how can I order the previous points?

Chris A.
  • 6,817
  • 2
  • 25
  • 43
Storm2012
  • 549
  • 1
  • 9
  • 14

1 Answers1

3

If you calculate vectors from point 0 to point x and y, their cross product will which tell you vector is more counter-clockwise.

The code sample was given in the question "Sort four points in the clockwise order".

Community
  • 1
  • 1
Rafał Rawicki
  • 22,324
  • 5
  • 59
  • 79