![](/img/trans.png)
[英]'System.Runtime.InteropServices.SEHException' unhandled exception in OpenCV code
[英]OpenCV: System.Runtime.InteropServices.SEHException
请看下面的代码
宣言
vector<vector<Point>> *contours;
vector<vector<Point>> *contoursPoly;
contours = new vector<vector<Point>>();
contoursPoly = new vector<vector<Point>>();
履行
//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);
我为什么得到这个?
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 ++中有时需要执行的操作。 不要做不必要的事情。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.