C++ 使用opencv convexHul获取给定点的面积。-点到垫转换期间出错
我按照链接制作点的向量。为了计算给定点的面积,我使用了凸包。我跟着去做。当我试图计算凸轮内部的面积时,出现了以下错误。正如我注意到的,在将向量点转换为Mat之后,并没有深度<代码>CV_断言(总计>=0&(深度==CV_32F | |深度==CV_32S))代码> 我如何克服这个问题。感谢您的帮助。先谢谢你C++ 使用opencv convexHul获取给定点的面积。-点到垫转换期间出错,c++,opencv,C++,Opencv,我按照链接制作点的向量。为了计算给定点的面积,我使用了凸包。我跟着去做。当我试图计算凸轮内部的面积时,出现了以下错误。正如我注意到的,在将向量点转换为Mat之后,并没有深度CV_断言(总计>=0&(深度==CV_32F | |深度==CV_32S)) 我如何克服这个问题。感谢您的帮助。先谢谢你 #include "opencv2/highgui/highgui.hpp" #include "opencv2/imgproc/imgproc.hpp" #include <iostream>
#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;
}
该错误意味着函数
convexHull
需要将点坐标存储为浮点而不是双精度。要解决此问题,请将向量的定义更改为:
vector<Point2f> originalPoints;
vector<Point2f> hull;
vector<Point2f> contour;
向量原点;
向量壳;
矢量轮廓;
该错误意味着函数convexHull
需要将点坐标存储为浮点数,而不是双精度。要解决此问题,请将向量的定义更改为:
vector<Point2f> originalPoints;
vector<Point2f> hull;
vector<Point2f> contour;
向量原点;
向量壳;
矢量轮廓;