opencv判断点是否在轮廓内

2023-01-15  本文已影响0人  会当临绝顶山小
std::vector<std::vector<cv::Point>> contours(1);
contours[0].push_back(cv::Point(0,0));
contours[0].push_back(cv::Point(500,0));
contours[0].push_back(cv::Point(500,500));
contours[0].push_back(cv::Point(0,500));

// measureDist = true
// 返回值大于0,点在轮廓内,返回值表示点和轮廓的最近距离
// 返回值小于0,点在轮廓外,返回值表示点和轮廓的最近距离
// 返回值等于0,点在轮廓上

// measureDist = false
// 返回值:1:在轮廓内,0:在轮廓上,-1:在轮廓外

bool measureDist = true;
double d = cv::pointPolygonTest(contours[0], cv::Point2f(10,20), measureDist);
std::cout << "d:" << d << " measureDist:" << measureDist << std::endl;
上一篇下一篇

猜你喜欢

热点阅读