请看下面的代码
声明
vector<vector<Point>> *contours;
vector<vector<Point>> *contoursPoly;
contours = new vector<vector<Point>>();
contoursPoly = new vector<vector<Point>>();Implementation
//Find contours
findContours(*canny,*contours,*heirarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));
//Draw contours
//drawContours(*current,*contours,-1,Scalar(0,0,255),2);
for(int i=0;i<contours->size();i++)
{
cv::approxPolyDP(Mat(contours[i]),contoursPoly[i], 3, true);
}一旦我运行这段代码,我就会得到错误
A first chance exception of type 'System.Runtime.InteropServices.SEHException' occurred in Automated System.exe
An unhandled exception of type 'System.Runtime.InteropServices.SEHException' occurred in Automated System.exe此错误来自代码的以下部分
cv::approxPolyDP(Mat(contours[i]),contoursPoly[i], 3, true);我为什么要得到这个?
发布于 2013-07-13 15:40:26
contoursPoly是指向向量的指针。
contoursPoly[i]将指向向量的指针视为向量数组,并获得i第四次指针。
您需要(*contoursPoly)[i],它首先取消指针。(*contours)[i]的情况可能也是一样。
此外,可能没有理由使用指向向量的指针.
取代:
vector<vector<Point>> *contours;
vector<vector<Point>> *contoursPoly;
contours = new vector<vector<Point>>();
contoursPoly = new vector<vector<Point>>();使用
vector<vector<Point>> contours;
vector<vector<Point>> contoursPoly;然后,从以下位置删除取消引用*:
findContours(*canny,*contours,*heirarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));就像这样:
findContours(canny,contours,*heirarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));并将函数中的std::vector<std::vector<Point>>*参数更改为std::vector<std::vector<Point>>&参数。将对这些变量使用->替换为使用.,并删除取消引用。
基于堆的分配(即免费存储)只是在C++中有时需要做的事情。不要做不必要的事。
https://stackoverflow.com/questions/17631576
复制相似问题