您的位置:首页 > 运维架构

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

2013-08-01 15:46 726 查看
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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: