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

相关文章:

  • 2022-02-09
  • 2022-02-09
  • 2022-01-24
  • 2022-01-31
  • 2022-12-23
  • 2021-09-21
  • 2021-08-23
猜你喜欢
  • 2021-04-16
  • 2021-07-24
  • 2021-04-28
  • 2021-10-29
  • 2022-12-23
  • 2021-07-03
  • 2021-12-15
相关资源
相似解决方案