有没有办法将 OpenCV 中的 minAreaRect 与 double 一起使用
Is there a way to use minAreaRect from OpenCV with double?
我在3D环境和相机中工作,所以我在一边有一些3D坐标,在另一边玩OpenCV。
我需要找到一个多边形的最小边界矩形,考虑 2D 坐标,并希望为此使用 OpenCV。
问题是我的坐标以双精度表示。
我试过了:
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 错误:断言失败 (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, 第 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
只接受Point
或Point2f
,即类型为CV_32S
或CV_32F
的点。
如果float
点具有足够的精度,则可以使用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!
相关文章:
- 如何将enable-if与模板参数和参数包一起使用
- 如何将PERF_AMPLE_READ与mmap一起使用
- 如何将两个不同矢量的同一位置的两个元素组合在一起
- 如何将C++中的库和头与MinGW一起使用
- 将--whole archive链接器选项与CMake和具有其他库依赖项的库一起使用
- 为什么我不能将 rand() 与数组的大小一起使用?
- 要与"if constexpr"一起使用的编译时消息(在预处理器之后)
- 不能将复制初始化与隐式转换的多个步骤一起使用
- 将fold表达式与std::一起用于两个元组
- spdlog标头仅与外部fmt一起使用.spdlog错误:'内部':不是'fmt'
- C++在数学计算中将double转换为int
- 将 std::allocate_shared 与多态资源分配器一起使用
- 在c++中为double类型的数组创建一个unique_ptr
- 为什么常量词在重载运算符中不与 ostream 对象一起使用<<?
- 将 OpenCV 与 CMAKE 中的项目一起构建为第三方库的正确方法
- 将 exprtk 与自定义类的对象一起使用
- 将 std::set 与基于键的比较器一起使用
- 将运算符 ^ 与“double”操作数一起使用会发出编译器错误
- 有没有办法将 OpenCV 中的 minAreaRect 与 double 一起使用
- 将"const"与标量类型一起使用的好处?(例如 "const double"或"const int")