使用 opencv 凸胡尔 获取给定点的面积. - 点到垫子转换期间发生错误
Using opencv convexHul Get area of given points. - Errors occurred during points to Mat conversion
我点击了这个链接来制作点的向量。为了计算给定点的面积,我使用了凸包。为此,我遵循了这个。当我尝试计算凸体内部的面积时,发生了以下错误。正如我在将矢量点转换为 Mat 后注意到的那样,没有深度。CV_Assert(total >= 0 && (depth == CV_32F || depth == CV_32S));
我如何克服这个问题。任何帮助,不胜感激。提前谢谢你。
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <math.h>
using namespace std;
using namespace cv;
int main()
{
vector<Point2d> originalPoints;
vector<Point2d> hull;
vector<Point2f> contour;
double epsilon = 0.001;
for(int dataPointCount=0; dataPointCount < 10; dataPointCount++)
{
cv::Point2d point;
point.x = 10 * ( (double)rand() / (double)RAND_MAX ) + 2; // just genarate random point
point.y = 5 * ( (double)rand() / (double)RAND_MAX ) + 2;
originalPoints.push_back(point);
}
convexHull(Mat(originalPoints) , hull , true);
approxPolyDP(Mat(hull), contour, 0.001, true);
cout << "====>"<< fabs(contourArea(Mat(contour)));
return 0;
}
错误
OpenCV Error: Assertion failed (total >= 0 && (depth == CV_32F || depth == CV_32S)) in convexHull, file /home/ve/workspace/opencv-3.3.0/modules/imgproc/src/convhull.cpp, line 136
terminate called after throwing an instance of 'cv::Exception'
what(): /home/ve/workspace/opencv-3.3.0/modules/imgproc/src/convhull.cpp:136: error: (-215) total >= 0 && (depth == CV_32F || depth == CV_32S) in function convexHull
该错误意味着函数convexHull
要求将点坐标存储为浮点数而不是双精度。要解决此问题,请将向量的定义更改为:
vector<Point2f> originalPoints;
vector<Point2f> hull;
vector<Point2f> contour;
相关文章:
- C++使用params创建线程函数会导致转换错误
- 为什么g++在未执行的代码处标记强制转换错误
- 为什么C++在将浮点数转换为字符时没有显示缩小转换错误?
- 如何在构建对象堆栈时解决转换错误?
- 执行具有转换错误的过程
- 指向类成员函数的指针中存在类型转换错误
- 为什么我在这里收到C++没有已知的转换错误?
- 增加图形转换错误
- 尝试向 COM 对象添加另一个接口时出现静态强制转换错误 C2440
- 返回带有另一个类的数据成员的构造函数?遇到转换错误?
- 指针和双重转换错误,代码没有
- 自定义函数转换错误?
- 将 C 程序转换为具有大量字符* 和无符号字符转换错误的C++
- 如何在我使用过的Arduino库之一中固定构造函数中的转换错误
- 试图使用strCMP时的char转换错误
- 我在 TSP 的C++解决方案中遇到转换错误
- "double(*)(string, double, double)"尝试传递函数C++时"double"转换错误
- 此语法中的构造函数转换错误
- Opengl 精度转换错误编译错误 E0415
- 无效的转换错误和无效的类型