I am trying to run a code from Kaggle, but i am unable to.
The code is here
The error msg i get is:
--------------------------------------------------------------------------- IndexError Traceback (most recent call last) <ipython-input-6-2a3e36c2605f> in <module>() 59 _, contours_mask, _ = cv2.findContours(thresh_mask.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE) 60 ---> 61 main_contour = sorted(contours_mask, key = cv2.contourArea, reverse = True)[0] 62 63 x,y,w,h = cv2.boundingRect(main_contour) IndexError: list index out of range
It might be python or package version related, as other ppl havent experienced the code.
I tried openning some outputs but I am new to cv2.
To my understanding:
cv2.findContours() -> image, contours, hierarchy
What i do get:
cv2.findContours(thresh_mask.copy(),cv2.RETR_TREE,cv2.CHAIN_APPROX_NONE) -> (array([[0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], ..., [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0], [0, 0, 0, ..., 0, 0, 0]], dtype=uint8), [], None)
Hence, countours is empty, which might be the problem. thresh_mask is an all zero matrix for that case, which might be the cause. unsure of it though.
Any hints/advices?
Thx
1 Answers
Answers 1
It happens because your input image (thresh_mask) is empty i.e complete black. No contours are detected. Please check contents of thresh_mask or display it using cv2.imshow.
0 comments:
Post a Comment