MCPcopy Create free account
hub / github.com/creatale/node-dv / icvRotatingCalipers

Function icvRotatingCalipers

deps/opencv/modules/imgproc/src/rotcalipers.cpp:92–348  ·  view source on GitHub ↗

we will use usual cartesian coordinates */

Source from the content-addressed store, hash-verified

90
91/* we will use usual cartesian coordinates */
92static void
93icvRotatingCalipers( CvPoint2D32f* points, int n, int mode, float* out )
94{
95 float minarea = FLT_MAX;
96 float max_dist = 0;
97 char buffer[32] = {};
98 int i, k;
99 CvPoint2D32f* vect = (CvPoint2D32f*)cvAlloc( n * sizeof(vect[0]) );
100 float* inv_vect_length = (float*)cvAlloc( n * sizeof(inv_vect_length[0]) );
101 int left = 0, bottom = 0, right = 0, top = 0;
102 int seq[4] = { -1, -1, -1, -1 };
103
104 /* rotating calipers sides will always have coordinates
105 (a,b) (-b,a) (-a,-b) (b, -a)
106 */
107 /* this is a first base bector (a,b) initialized by (1,0) */
108 float orientation = 0;
109 float base_a;
110 float base_b = 0;
111
112 float left_x, right_x, top_y, bottom_y;
113 CvPoint2D32f pt0 = points[0];
114
115 left_x = right_x = pt0.x;
116 top_y = bottom_y = pt0.y;
117
118 for( i = 0; i < n; i++ )
119 {
120 double dx, dy;
121
122 if( pt0.x < left_x )
123 left_x = pt0.x, left = i;
124
125 if( pt0.x > right_x )
126 right_x = pt0.x, right = i;
127
128 if( pt0.y > top_y )
129 top_y = pt0.y, top = i;
130
131 if( pt0.y < bottom_y )
132 bottom_y = pt0.y, bottom = i;
133
134 CvPoint2D32f pt = points[(i+1) & (i+1 < n ? -1 : 0)];
135
136 dx = pt.x - pt0.x;
137 dy = pt.y - pt0.y;
138
139 vect[i].x = (float)dx;
140 vect[i].y = (float)dy;
141 inv_vect_length[i] = (float)(1./sqrt(dx*dx + dy*dy));
142
143 pt0 = pt;
144 }
145
146 //cvbInvSqrt( inv_vect_length, inv_vect_length, n );
147
148 /* find convex hull orientation */
149 {

Callers 1

cvMinAreaRect2Function · 0.85

Calls 2

cvAllocFunction · 0.85
sqrtFunction · 0.85

Tested by

no test coverage detected