【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++; } }
参考
End
各美其美,美美与共,不和他人作比较,不对他人有期待,不批判他人,不钻牛角尖。
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/
心正意诚,做自己该做的事情,做自己喜欢做的事情,安静做一枚有思想的技术媛。
版权声明,转载请注明出处:https://www.cnblogs.com/happyamyhope/