判断一个点是否在轮廓内的函数pointPolygonTest()的用法

OpenCV函数pointPolygonTest():

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

用于判断一个点是否在轮廓中
当measureDist设置为true时,若返回值为正,表示点在轮廓内部,返回值为负,表示在轮廓外部,返回值为0,表示在轮廓上。
当measureDist设置为false时,若返回值为+1,表示点在轮廓内部,返回值为-1,表示在轮廓外部,返回值为0,表示在轮廓上。
例:

……
/// 查找轮廓
std::vector<std::vector > 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(x1,y1),false) == 1)
{
    cout<"在轮廓内"<

你可能感兴趣的:(C++)