要解压的值太多/至少需要 3 个值 - OpenCV - Python

Too many values to unpack / Needs at least 3 values - OpenCV - Python

这是我的代码片段:

ret,thresh = cv2.threshold(image,127,255,0)
contours,hierarchy = cv2.findContours(thresh, 1, 2)
cnt = contours[0]
M = cv2.moments(cnt)
print M

起初它给了我错误:

Too many values to unpack.

然后我将代码更改为:

_,contours,_,hierarchy = cv2.findContours(thresh, 1, 2)

出现新错误:

Needs at least 3 values

有人知道如何解决这个问题吗?

it returns: img,contours,hierarchy in opencv3.0 but only contours,hierarchy in 2.4 – berak