在OpenCV的函数调用中使用FindContours函数时出现运行时错误。我得到一个运行时错误,如下所示:
An unhandled exception of type 'System.AccessViolationException' occured in Project.exe.
Additional information: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
然后光标指向 vector.h 文件中的一行,如下所示。
void _Assign_rv(_Myt&& _Right)
{ // assign by moving _Right
this->_Swap_all((_Myt&)_Right);
this->_Myfirst = _Right._Myfirst; // The cursor points here
this->_Mylast = _Right._Mylast;
this->_Myend = _Right._Myend;
_Right._Myfirst = pointer();
_Right._Mylast = pointer();
_Right._Myend = pointer();
}
但findContours函数在main()函数中有效。我无法理解它。
代码运行正常而不使用FindContours函数。 我已将正确的图片传递给该功能。
我对这个问题进行了很多探讨。我发现findContours函数存在很多问题,这些问题没有得到正确回答,或者答案不足以解决这个问题。 我认为问题可能出在CLI上。但是,控制台应用程序也存在问题。
为了您的信息,我在visual studio 2012中使用openCV248。我在Windows窗体文件“MyForm.h”中的代码片段
vector<vector<cv::Point>> Image_Contours;
vector<Vec4i> Image_Hierarchy;
FillContours(ColorImage,Image_Contours,Image_Hierarchy); // Function Call to do basic image filtering and find the contours
FillContours(&ColorImage, & vector<vector<cv::Point>>& ContoursP, vector<cv::Vec4i> &HierarchyP)
{
.......... // Filtering operations of ColorImage
cvtColor(ImageFiltered, GrayConverted, CV_BGR2GRAY);
findContours(GrayConverted, ContoursP, HierarchyP, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE);
}
我还在findContours函数中使用了一个简单的现有GRAY图像而不是这样的函数调用,但我仍然遇到了运行时错误。