0

I doing project find contours in opencv c++. I use OpenCV 2.4.9 and c++ but meet error: Unhandled exception at 0x0F792B99 (opencv_imgproc249d.dll) in Project2.exe: 0xC0000005: Access violation reading location 0xCDCDCDCD. My code:

Mat _src1 = imread("D:\\image1.jpg", CV_LOAD_IMAGE_COLOR);
Mat _gray, _binary;
cvtColor(_src1, _gray, CV_BGR2GRAY); 
threshold(_gray,_binary,100,255,CV_THRESH_BINARY);

Mat _morpho;
Mat _element = getStructuringElement(MORPH_CROSS, Size(3, 3), Point(1, 1)); 

erode(_binary, _morpho, _element, Point(-1, -1), 3); 

vector<vector<Point>> _contour1;
findContours(_morpho, _contour1, CV_RETR_LIST, CV_CHAIN_APPROX_NONE);
for (size_t i = 0; i < _contour1.size(); i++)
{
    Rect r = boundingRect(_contour1[i]);
    if (r.width / (double)r.height > 3.5f && r.width / (double)r.height < 4.5f)
    {
        rectangle(_src1, r, Scalar(0, 0, 255), 2, 8, 0);
    }
    else
    {
        rectangle(_src1, r, Scalar(0, 255, 0), 1, 8, 0);
    }
}

imshow("Result", _src1);
waitKey(0);

error

Unhandled exception at 0x0FF12B99 (opencv_imgproc249d.dll) in Project2.exe: 0xC0000005: Access 
violation reading location 0xCDCDCDCD.

and line error visual studio thrown exception unhandled

Rect r = boundingRect(_contour1[i]);

How can i fix it. Thanx in advance.

  • `0xCDCDCDCD` is uninitialized heap memory. [https://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations](https://stackoverflow.com/questions/127386/in-visual-studio-c-what-are-the-memory-allocation-representations) – drescherjm Dec 05 '19 at 03:07
  • Probably a C++ runtime mismatch -- either using debug build of OpenCV in a release build of the application, or using OpenCV built with a different version of Visual C++. Hard to tell what exactly, since relevant details are missing. – Dan Mašek Dec 05 '19 at 12:02

0 Answers0