opencv中如何判断一个点是否在一个多边形中

来源:互联网 发布:淘宝产品卖点怎么写 编辑:程序博客网 时间:2024/06/06 01:18

pointPolygonTest()函数可以实现这个功能。

!
double cvPointPolygonTest(const CvArr* contour, CvPoint2D32f pt, int measure_dist)

参数:contour,多边形。  pt将要判断的点。measure_dist  如果为真,则返回的double类型是点距离轮廓的最近的距离。如果为假,返回的值无意义。

参考资料opencv2refman.pdf 297页。

下面为英文原文。

pointPolygonTest
Performs a point-in-contour test.
C++: double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)
Python: cv2.pointPolygonTest(contour, pt, measureDist) ! retval
C: double cvPointPolygonTest(const CvArr* contour, CvPoint2D32f pt, int measure_dist)
Python: cv.PointPolygonTest(contour, pt, measure_dist) ! float
Parameters
contour – Input contour.
pt – Point tested against the contour.
measureDist – If true, the function estimates the signed distance from the point to the
nearest contour edge. Otherwise, the function only checks if the point is inside a contour or
not.
The function determines whether the point is inside a contour, outside, or lies on an edge (or coincides with a vertex). It
returns positive (inside), negative (outside), or zero (on an edge) value, correspondingly. When measureDist=false
, the return value is +1, -1, and 0, respectively. Otherwise, the return value is a signed distance between the point and
the nearest contour edge.
See below a sample output of the function where each image pixel is tested against the contour.




原创粉丝点击