gpt4 book ai didi

c++ - 有没有办法将 OpenCV 中的 minAreaRect 与 double 一起使用?

转载 作者:搜寻专家 更新时间:2023-10-31 01:36:39 25 4
gpt4 key购买 nike

我在 3D 环境和相机中工作,因此我在一侧有一些 3D 坐标,在另一侧使用 OpenCV。

考虑到 2D 坐标,我需要找到一个多边形的最小边界矩形,并且想为此使用 OpenCV。

问题是我的坐标以 double 表示。

我试过:

  std::vector<cv::Point2d> poly {{1.1, 2.2}, {3.3, 4.4}, {5.5, 6.6}, {7.7, 8.8}};
cv::RotatedRect box = cv::minAreaRect(poly); // crashes here

cv::Point2f corners[4];
box.points(corners);

但出现以下错误:

OpenCV Error: Assertion failed (points.checkVector(2) >= 0 && (points.depth() == CV_32F || points.depth() == CV_32S)) in minAreaRect, file /build/buildd/opencv-2.4.8+dfsg1/modules/imgproc/src/contours.cpp, line 1913

如果我使用一些 Point 而不是 Point2d,结果矩形的坐标将被截断

// narrowing conversions
std::vector<cv::Point2d> poly {{1.1, 2.2}, {3.3, 4.4}, {5.5, 6.6}, {7.7, 8.8}};
cv::RotatedRect box = cv::minAreaRect(poly);

cv::Point2f corners[4];
box.points(corners);

我不能百分百确定我是否以正确的方式使用 OpenCV,但我偶然发现了这一点,并希望避免编写自己的旋转卡尺函数。

谢谢!

最佳答案

minAreaRect只接受 PointPoint2f ,即 CV_32S 类型的点或 CV_32F .

如果float points 对你来说足够准确,你可以使用 Point2f而不是 Point2d :

std::vector<cv::Point2f> poly{ { 1.1f, 2.2f }, { 3.3f, 4.4f }, { 5.5f, 6.6f }, { 7.7f, 8.8f } };
cv::RotatedRect box = cv::minAreaRect(poly); // now it works!

关于c++ - 有没有办法将 OpenCV 中的 minAreaRect 与 double 一起使用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35295298/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com