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

Function cvPointPolygonTest

deps/opencv/modules/imgproc/src/geometry.cpp:130–312  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

128
129
130CV_IMPL double
131cvPointPolygonTest( const CvArr* _contour, CvPoint2D32f pt, int measure_dist )
132{
133 double result = 0;
134
135 CvSeqBlock block;
136 CvContour header;
137 CvSeq* contour = (CvSeq*)_contour;
138 CvSeqReader reader;
139 int i, total, counter = 0;
140 int is_float;
141 double min_dist_num = FLT_MAX, min_dist_denom = 1;
142 CvPoint ip = {0,0};
143
144 if( !CV_IS_SEQ(contour) )
145 {
146 contour = cvPointSeqFromMat( CV_SEQ_KIND_CURVE + CV_SEQ_FLAG_CLOSED,
147 _contour, &header, &block );
148 }
149 else if( CV_IS_SEQ_POINT_SET(contour) )
150 {
151 if( contour->header_size == sizeof(CvContour) && !measure_dist )
152 {
153 CvRect r = ((CvContour*)contour)->rect;
154 if( pt.x < r.x || pt.y < r.y ||
155 pt.x >= r.x + r.width || pt.y >= r.y + r.height )
156 return -1;
157 }
158 }
159 else if( CV_IS_SEQ_CHAIN(contour) )
160 {
161 CV_Error( CV_StsBadArg,
162 "Chains are not supported. Convert them to polygonal representation using cvApproxChains()" );
163 }
164 else
165 CV_Error( CV_StsBadArg, "Input contour is neither a valid sequence nor a matrix" );
166
167 total = contour->total;
168 is_float = CV_SEQ_ELTYPE(contour) == CV_32FC2;
169 cvStartReadSeq( contour, &reader, -1 );
170
171 if( !is_float && !measure_dist && (ip.x = cvRound(pt.x)) == pt.x && (ip.y = cvRound(pt.y)) == pt.y )
172 {
173 // the fastest "pure integer" branch
174 CvPoint v0, v;
175 CV_READ_SEQ_ELEM( v, reader );
176
177 for( i = 0; i < total; i++ )
178 {
179 int dist;
180 v0 = v;
181 CV_READ_SEQ_ELEM( v, reader );
182
183 if( (v0.y <= ip.y && v.y <= ip.y) ||
184 (v0.y > ip.y && v.y > ip.y) ||
185 (v0.x < ip.x && v.x < ip.x) )
186 {
187 if( ip.y == v.y && (ip.x == v.x || (ip.y == v0.y &&

Callers 1

pointPolygonTestMethod · 0.85

Calls 4

cvPointSeqFromMatFunction · 0.85
cvStartReadSeqFunction · 0.85
cvRoundFunction · 0.85
sqrtFunction · 0.85

Tested by

no test coverage detected