Hello, I am trying to draw contours, but it throws an assertion error
"OpenCV Error: Assertion failed (0 <= contourIdx && contourIdx < (int)last) in unknown function,
file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line 1810"
My input image is :
Here's a code snippet of what I'm doing :
Mat input_image = imread(filename, 0);
Mat canny_op;
Canny(input_image, canny_op, 100, 200, 3);
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( input_image, contours, hierarchy, CV_RETR_LIST, CV_CHAIN_APPROX_NONE, Point(0, 0) );
cout << "Size of contours [vector] is " << contours.size() << endl;
cout << "Size of hierarchy [vector] is " << hierarchy.size() << endl;
// Draw contours
Mat drawing = Mat::zeros( input_image.size(), CV_8UC3 );
for( int i = 0; i< contours.size(); i++ ) {
Scalar color(0,0,255);
drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}
showImage("output of drawing",drawing);
The output of the program gives
Size of contours [vector] is 160
Size of hierarchy [vector] is 120