首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >OpenCV: System.Runtime.InteropServices.SEHException

OpenCV: System.Runtime.InteropServices.SEHException
EN

Stack Overflow用户
提问于 2013-07-13 15:28:42
回答 1查看 2.8K关注 0票数 1

请看下面的代码

声明

代码语言:javascript
复制
vector<vector<Point>> *contours;
vector<vector<Point>> *contoursPoly;

contours = new vector<vector<Point>>();
contoursPoly = new vector<vector<Point>>();

Implementation

代码语言:javascript
复制
//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);
}

一旦我运行这段代码,我就会得到错误

代码语言:javascript
复制
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

此错误来自代码的以下部分

代码语言:javascript
复制
cv::approxPolyDP(Mat(contours[i]),contoursPoly[i], 3, true);

我为什么要得到这个?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-07-13 15:40:26

contoursPoly是指向向量的指针。

contoursPoly[i]将指向向量的指针视为向量数组,并获得i第四次指针。

您需要(*contoursPoly)[i],它首先取消指针。(*contours)[i]的情况可能也是一样。

此外,可能没有理由使用指向向量的指针.

取代:

代码语言:javascript
复制
vector<vector<Point>> *contours;
vector<vector<Point>> *contoursPoly;

contours = new vector<vector<Point>>();
contoursPoly = new vector<vector<Point>>();

使用

代码语言:javascript
复制
vector<vector<Point>> contours;
vector<vector<Point>> contoursPoly;

然后,从以下位置删除取消引用*

代码语言:javascript
复制
findContours(*canny,*contours,*heirarchy,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,Point(0,0));

就像这样:

代码语言:javascript
复制
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++中有时需要做的事情。不要做不必要的事。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/17631576

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档