pointPolygonTest:
C++: double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)
作用:用于测试一个点是否在多边形内;
当measureDist设置为true时,若返回值为正,表示点在多边形内部,返回值为负,表示在多边形外部,返回值为0,表示在多边形上;
当measureDist设置为false时,若返回值为+1,表示点在多边形内部,返回值为-1,表示在多边形外部,返回值为0,表示在多边形上;
示例:
……
/// 查找轮廓
std::vector<std::vector<cv::Point> > contours;
cv::Mat src; //src为输入图像
cv::findContours( src, contours, CV_RETR_EXTERNAL,CV_CHAIN_APPROX_SIMPLE,Point(0,0));
//判断p1(x,y)是否在轮廓内
cv::Point p1(x,y);
if (pointPolygonTest(Contours[j],cv::Point(x,y),false) == 1)
{
cout<<p1<<"在轮廓内"<<endl;
}
……
参考文章: