Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

cv2.drawContours expects an array of contours, if you give it a single one, it will still try to access it as an array of arrays, and yea, bad result.

blame python's non-existing type system for making such an error possible.

your code here:

for index,cnt in enumerate(contours):
    cv2.drawContours(blank2, cnt, -1, (255, 50, 255), 1)

is simply wrong.

cv2.drawContours expects an array of contours, if you give it a single one, it will still try to access it as an array of arrays, and yea, bad result.

blame python's non-existing type system for making such an error possible.

your code here:

for index,cnt in enumerate(contours):
    cv2.drawContours(blank2, cnt, -1, (255, 50, 255), 1)

is simply wrong.

cv2.drawContours expects an array of contours, if you give it a single one, it will still try to access it as an array of arrays, and yea, bad result.

blame python's non-existing type system for making such an error possible.

if you want to use a loop, it has to be like this:

for index, _ in enumerate(contours):
    cv2.drawContours(blank2, contours, index, (255, 50, 255), 1)

your code here:

for index,cnt in enumerate(contours):
    cv2.drawContours(blank2, cnt, -1, (255, 50, 255), 1)

is simply wrong.

cv2.drawContours expects an array of contours, if you give it a single one, it will still try to access it as an array of arrays, and yea, bad result.

blame python's non-existing type system for making such an error possible.

if you want to use a loop, it has to be like this:this (use all the contours and an index):

for index, _ in enumerate(contours):
    cv2.drawContours(blank2, contours, index, (255, 50, 255), 1)