2

我一直在尝试使用 OpenCV 功能:

double pointPolygonTest(InputArray contour, Point2f pt, bool measureDist)

我有一个由 2D (x1,y1), ..., (x4,y4) 中的 4 个点指定的轮廓。我想测试一个点 (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);

我错过了什么吗?

4

1 回答 1

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
于 2011-09-20T19:35:44.367 回答