gpt4 book ai didi

c++ - OpenCV:System.Runtime.InteropServices.SEHException

转载 作者:太空宇宙 更新时间:2023-11-03 23:01:18 26 4
gpt4 key购买 nike

请看下面的代码

声明

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是指向 vector 的指针。

contoursPoly[i]将指向 vector 的指针视为 vector 数组,并获取 i第一个。

你想要(*contoursPoly)[i] ,它首先取消引用指针。 (*contours)[i] 可能相同.

此外,可能没有理由使用指向 vector 的指针。

替换:

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++ 中,基于堆的分配(即自由存储)只是有时您需要做的事情。不要做不必要的事情。

关于c++ - OpenCV:System.Runtime.InteropServices.SEHException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17631576/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com