drawContours error: (-215) npoints > 0 in function drawContours [closed]
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)
google is your friend ?
I found the post and tried the tip but it didn't fix my error, thanks though.
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++ ?
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.
third paramter is stat not contour.
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..)