OpenCv 点多边形测试。如何提供轮廓作为输入?

发布于 2024-12-05 17:31:59 字数 529 浏览 1 评论 0原文

我一直在尝试使用OpenCV函数:

double pointPolygonTest(InputArray轮廓,Point2f pt,boolmeasureDist)

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

我错过了什么吗?

I've been trying to use the OpenCV function:

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

I have a contour specified by 4 Points in 2D (x1,y1), ..., (x4,y4). I want to test if a Point (x,y) is inside or outside of the contour. But I can't seem to find any reference how to specify the contours as input for the function correctly.

I've tried the following implementation without getting a correct result:

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);

Am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

青丝拂面 2024-12-12 17:31:59

函数对我来说没有任何问题(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

Function works for me without any problem (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;

Output:

-1
1
0
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文