这是opencv版本的问题,使用的可能是较新版本,如果可以的话,可以安装旧版本,但是安装旧版本往往会带来更多的版本冲突问题。
下面是我的问题以及解决方案:|
im2,contours, hierarchy = cv2.findContours(image.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
if cv2.contourArea(cnt) < 2000:
number+=1
area+=cv2.contourArea(cnt)
然后就报出了not enough values to unpack (expected 3, got 2),这是因为cv2.findContours在新版本只返回两个参数,所以修改成:
contours, hierarchy = cv2.findContours(image.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
for cnt in contours:
if cv2.contourArea(cnt) < 2000:
number+=1
area+=cv2.contourArea(cnt)
就没有问题了。