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.