opencv函数
pointPolygonTest:
C++: double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)
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: |
|
---|
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.
使用例子如下:
-
/// 得到轮廓
-
std::vector<std::vector<cv::Point> > contours;
-
std::vector<cv::Vec4i> hierarchy;
-
cv::Mat src; //src为图像
-
//contours为函数findContours计算得到的轮廓点分布值
-
cv::findContours( src_copy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);
-
// 计算到轮廓的距离
-
cv::Mat raw_dist( src.size(), CV_32FC1 );
-
for( int j = 0; j < src.rows; j++ ){
-
for( int i = 0; i < src.cols; i++ ){
-
raw_dist.at<float>(j,i) = cv::pointPolygonTest( contours[0], Point2f(i,j), true );
-
}
--------------------- 本文来自 周作才 的CSDN 博客 ,全文地址请点击:https://blog.csdn.net/xiaxiazls/article/details/48392875?utm_source=copy