drawContours error: (-215) npoints > 0 in function drawContours [closed]

asked 2017-05-20 10:49:31 -0600

bonevale gravatar image

updated 2020-10-10 21:29:04 -0600

here's my code

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
labelNum, labelImg, contours, GoCs = cv2.connectedComponentsWithStats(gray)

    for c in contours:
        x,y,w,h,size = c
        if size <= 100:
            cv2.drawContours(image, [c], 0, 0)
edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by sturkmen
close date 2020-10-10 21:29:52.104051

Comments

LBerger gravatar imageLBerger ( 2017-05-20 11:12:27 -0600 )edit

I found the post and tried the tip but it didn't fix my error, thanks though.

bonevale gravatar imagebonevale ( 2017-05-20 11:54:33 -0600 )edit

Ok connectedComponentsWithStats works with binary image. have you got a binary image in gray?

I don't know python but are you sure that connectedComponentsWithStats give you image contour ? in c++ it is findContour.

python = C++ ?

LBerger gravatar imageLBerger ( 2017-05-20 12:01:12 -0600 )edit

Yes when I call rectangle to draw around the contours instead of drawContours I get the behavior I want where all the little dots are selected so the rest of my function works as desired. And yes before all this my image is given a threshold.

bonevale gravatar imagebonevale ( 2017-05-20 14:10:05 -0600 )edit
1

third paramter is stat not contour.

LBerger gravatar imageLBerger ( 2017-05-20 14:54:41 -0600 )edit

connectedComponents does not compute any contours (the output is a "labels" image), thus your whole for loop does not make any sense (it's also total bs anyway..)

berak gravatar imageberak ( 2017-05-22 06:34:16 -0600 )edit