Draw Contours error [closed]
Hello,
I'm trying to draw countours (Java) and I get this error.
OpenCV Error: Assertion failed (0 <= contourIdx && contourIdx < (int)last) in drawContours, file ~/code/OpenCV/opencv-2.4.6.1/modules/imgproc/src/contours.cpp, line 1810
Exception in thread "main" CvException [org.opencv.core.CvException: /home/slani/code/OpenCV/opencv-2.4.6.1/modules/imgproc/src/contours.cpp:1810: error: (-215) 0 <= contourIdx && contourIdx < (int)last in function drawContours
]
at org.opencv.imgproc.Imgproc.drawContours_2(Native Method)
at org.opencv.imgproc.Imgproc.drawContours(Imgproc.java:5013)
at HsvImage.main(HsvImage.java:83)
Can someone please explain me what this error mean. Thanks,
P.S. Code
// convert color space
Imgproc.GaussianBlur(frame, smooth, new Size(19,19), 0.0);
Imgproc.cvtColor(smooth, hsvFrame, Imgproc.COLOR_BGR2HSV);
// checks if array elements lie beween min and max
Core.inRange(hsvFrame, min, max, thresholded);
Core.inRange(hsvFrame, min2, max2, thresholded2);
Core.bitwise_or(thresholded, thresholded2, thresholded);
Imgproc.findContours(thresholded, contours, hierarchy, Imgproc.RETR_CCOMP, Imgproc.CHAIN_APPROX_SIMPLE);
Imgproc.drawContours(frame, contours, 4, new Scalar(40, 233, 45,0 ));
panel.setImage(frame);
HSVpanel.setImage(thresholded);
panel.repaint();
HSVpanel.repaint();
your contourIdx is out of bounds. can you show the piece of code, where you're drawing ?
so, you're trying to draw contour 4. what if it finds only 2 contours in your img ? boom maybe you wanted:
to draw all of them.
or: