我正在设计一种算法,我必须遍历图像中的每个轮廓并对其应用条件。我正在使用 cv2 库来执行此操作。代码如下:
i=0
gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,1,255,0)
contours,hierarchy=cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
while contours:
if (cv2.contourArea(contours[i]) < 5000 and cv2.arcLength(contours[i],True) < 200 ):
cv2.drawContours(img,contours,i,(0,255,0),3)
i = i+1
contours = contours.h_next()
错误是:
Traceback (most recent call last):
File "C:\Users\NOOR BRAR\Documents\College Stuff\5th SEM\e-yantra\task1\PS1_Task1\Task1_Practice\test_images\countourImagemine.py", line 55, in <module>
contours = contours.h_next()
AttributeError: 'list' object has no attribute 'h_next'