我一直在尝试使用OpenCV功能:
double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)
我的轮廓由2D(x1,y1),...,(x4,y4)中的4个点指定。我想测试Point(x,y)是否在轮廓内部或外部。但我似乎无法找到任何参考如何正确指定轮廓作为函数的输入。
我在没有得到正确结果的情况下尝试了以下实现:
vector< Point2f > contour;
contour.push_back(Point2f(x1, y1));
contour.push_back(Point2f(x2, y2));
contour.push_back(Point2f(x3, y3));
contour.push_back(Point2f(x4, y4));
int inCont;
inCont = pointPolygonTest(contour, Point2f(x, y), false);
我错过了什么吗?
答案 0 :(得分:4)
功能对我没有任何问题(OpenCV 2.3.1):
vector<Point2f> points;
points.push_back(Point2f(0,0));
points.push_back(Point2f(0,4));
points.push_back(Point2f(4,4));
points.push_back(Point2f(4,0));
cout << pointPolygonTest(points, Point2f(5,1), false) << endl;
cout << pointPolygonTest(points, Point2f(1,1), false) << endl;
cout << pointPolygonTest(points, Point2f(0,0), false) << endl;
输出:
-1
1
0