Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Can't draw contours

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 :

image description

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

Can't draw contours

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 :

image description

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, canny_op, 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++ ) {
cout << i << endl;
    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

Here is the output of Canny :

image description

And here is the output of the program :

Size of contours [vector] is 160
Size of hierarchy [vector] is 120
0
1
2
...
119

Can't draw contours

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 :

image description

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( canny_op, 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++ ) {
cout << i << endl;
    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

Here is the output of Canny :

image description

And here is the output of the program :

Size of contours [vector] is 160
Size of hierarchy [vector] is 120
0
1
2
...
119
120
OpenCV Error: Assertion failed (0 <= contourIdx && contourIdx < (int)last) in un
known function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line
1810

Can't draw contours

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 :

image description

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( canny_op, 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++ ) {
cout << i << endl;
    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

Here is the output of Canny :

image description

And here is the output of the program :

Size of contours [vector] is 160
Size of hierarchy [vector] is 120
0
1
2
...
120
OpenCV Error: Assertion failed (0 <= contourIdx && contourIdx < (int)last) in un
known function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line
1810

Can't draw contours

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 :

image description

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( canny_op, 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++ ) {
cout << i << endl;
    Scalar color(0,0,255);
    drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}

showImage("output of drawing",drawing);

Here is the output of Canny :

image description

And here is the output of the program :

Size of contours [vector] is 160
Size of hierarchy [vector] is 120
0
1
2
...
120
OpenCV Error: Assertion failed (0 <= contourIdx && contourIdx < (int)last) in un
known function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line
1810

Can't draw contourscontours [SOLVED]

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 :

image description

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( canny_op, 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++ ) {
cout << i << endl;
    Scalar color(0,0,255);
    drawContours( drawing, contours, i, color, 2, 8, hierarchy, 0, Point() );
}

showImage("output of drawing",drawing);

Here is the output of Canny :

image description

And here is the output of the program :

Size of contours [vector] is 160
Size of hierarchy [vector] is 120
0
1
2
...
120
OpenCV Error: Assertion failed (0 <= contourIdx && contourIdx < (int)last) in un
known function, file ..\..\..\src\opencv\modules\imgproc\src\contours.cpp, line
1810