Python OpenCV:ValueError:要解压缩的值太多

时间:2017-10-09 18:24:46

标签: python opencv scipy

我正在尝试通过OpenCV教程,我正在使用提供的源代码。我遇到了这个错误:

文件“C:\ xxx \ xxxxxxx \ Desktop \ basic-motion-detection \ motion_detector.py”,第61行,     cv2.CHAIN_APPROX_SIMPLE) ValueError:要解压的值太多。

以下是代码:

# on thresholded image
thresh = cv2.dilate(thresh, None, iterations=3)
(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)`

2 个答案:

答案 0 :(得分:1)

问题是你使用的是cv2版本3,而不是版本2,代码是版本2。 要解决您的问题,只需更改此行

(cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)

为此:

(_, cnts, _) = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL,
    cv2.CHAIN_APPROX_SIMPLE)

答案 1 :(得分:0)

findContours会返回三件事,而您只需指定两封即可解压缩到(cnts, _)

如果您只对第一个感兴趣:

# on thresholded image
thresh = cv2.dilate(thresh, None, iterations=3)
cnts, _, _ = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)`