【opencv基础】pointPolygonTest

pointPolygonTest

opencv函数

pointPolygonTest:

C++: double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)

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.

用于测试一个点是否在多边形中

当measureDist设置为true时,若返回值为正,表示点在多边形内部,返回值为负,表示在多边形外部,返回值为0,表示在多边形上。

当measureDist设置为false时,若返回值为+1,表示点在多边形内部,返回值为-1,表示在多边形外部,返回值为0,表示在多边形上。

   std::vector<cv::Point2f> vertex(4);
   for (size_t i =0; i < contours.size(); i++)
    {
        float area = cv::contourArea(contours[i]);
        //Neareat Area.
        int k = 0;
        for (int j = 0; j < 4; j++)
        {
            double tmp = pointPolygonTest(contours[i], vertex[j], true);
            if ( tmp > 0 || tmp == 0) k++;
        }
    }

参考

1. opencv_pointPolygonTest

End

posted on 2018-08-03 10:57  鹅要长大  阅读(3302)  评论(0编辑  收藏  举报

导航