我最近开始在Python上学习OpenCV。使用cv2.findContours()与Python的错误
我指的是this这里的教程,以获得一些帮助获取图像的轮廓。
我的代码 -
import cv2
import numpy as np
img = cv2.imread('shapes.jpg', 0)
img = cv2.medianBlur(img, 5)
thresh = cv2.adaptiveThreshold(img,255,cv2.ADAPTIVE_THRESH_GAUSSIAN_C,\
cv2.THRESH_BINARY,11,2)
cv2.imshow('Thresh', thresh)
cv2.waitKey(0)
cv2.destroyAllWindows()
image, contours, hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
cv2.drawContours(image, countours, -1, (0,255,0), 3)
cv2.imshow('Contours', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
第一阈值的图像时出现的,但在那之后我得到一个错误消息
Traceback (most recent call last):
File "contours.py", line 21, in <module>
image, contours, hierarchy = cv2.findContours(thresh.copy(),cv2.RETR_LIST,cv2.CHAIN_APPROX_SIMPLE)
ValueError: need more than 2 values to unpack
任何帮助解决这一问题将不胜感激。
根据Opencv版本,findContours可以有2个或3个返回值... – Mehdi