【问题标题】:OpenCV - How to determine whether a given point is within a contour?OpenCV - 如何确定给定点是否在轮廓内?
【发布时间】:2015-05-01 07:11:06
【问题描述】:

给定一个随机轮廓,我如何判断给定的输入点是否位于轮廓内?如果它有一个简单的解决方案,我很抱歉,但我无法弄清楚。

我的一个想法是使用线方程,连接点并查看它是更大还是更小等。但这并没有让我有任何收获,因为它取决于线的位置。

【问题讨论】:

标签: opencv image-processing opencv-contour


【解决方案1】:

您可以使用 OpenCV here 找到此问题的完整解决方案

  /// Get the contours
  vector<vector<Point> > contours; vector<Vec4i> hierarchy;
  Mat src_copy = src.clone();

  findContours( src_copy, contours, hierarchy, RETR_TREE, CHAIN_APPROX_SIMPLE);

  /// Calculate the distances to the contour
  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) = pointPolygonTest( contours[0], Point2f(i,j), true ); }
     }

【讨论】:

    猜你喜欢
    • 2021-09-07
    • 2019-01-25
    • 2016-09-25
    • 2011-10-03
    • 2015-08-11
    • 2019-10-07
    • 2012-02-25
    • 1970-01-01
    • 2016-02-15
    相关资源
    最近更新 更多