How to avoid the None return from convexityDefects function?
If the function returns None I cannot use .shape
for None objects (which showed an error). However, if I insert my if statement right before the for loop, there is another error from numpy saying that
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any()
or a.all()
.
Then if I put defects.all()
for the if statement, the None object error shows again
cnt = contours[0]
hulll = cv.convexHull(cnt, returnPoints=False)
defects = cv.convexityDefects(cnt, hulll)
if (defects != None):
for i in range(defects.shape[0]):
s, e, f, d = defects[i, 0]
How can I execute the for loop without any problems?