python - OpenCV Python : cv2. findContours - ValueError:解包的值太多

标签 python opencv image-processing contour

我正在编写一个 opencv 程序,我在另一个 stackoverflow 问题上找到了一个脚本:Computer Vision: Masking a human hand

当我运行脚本答案时,我收到以下错误:

Traceback (most recent call last):
    File "skinimagecontour.py", line 13, in <module>
    contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
ValueError: too many values to unpack

代码:

import sys
import numpy
import cv2

im = cv2.imread('Photos/test.jpg')
im_ycrcb = cv2.cvtColor(im, cv2.COLOR_BGR2YCR_CB)

skin_ycrcb_mint = numpy.array((0, 133, 77))
skin_ycrcb_maxt = numpy.array((255, 173, 127))
skin_ycrcb = cv2.inRange(im_ycrcb, skin_ycrcb_mint, skin_ycrcb_maxt)
cv2.imwrite('Photos/output2.jpg', skin_ycrcb) # Second image

contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
for i, c in enumerate(contours):
    area = cv2.contourArea(c)
    if area > 1000:
        cv2.drawContours(im, contours, i, (255, 0, 0), 3)
cv2.imwrite('Photos/output3.jpg', im)

感谢任何帮助!

最佳答案

我从 OpenCV Stack Exchange 站点得到了答案。 Answer

答案:

I bet you are using the current OpenCV's master branch: here the return statements have changed, see http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findcontours.

Thus, change the corresponding line to read:

_, contours, _= cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

Or: since the current trunk is still not stable and you probably will run in some more problems, you may want to use OpenCV's current stable version 2.4.9.

关于python - OpenCV Python : cv2. findContours - ValueError:解包的值太多,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25504964/

相关文章:

Python 类/函数和 self 参数

python - MapReduce Python - 太多值无法解包

python - 向图像添加高斯噪声

image-processing - 图像处理(主要是opencv)索引约定

python - body 是什么? `from fastapi import Body`

python - 软件包未通过 elastic beanstalk config.yml 安装

python - 如何在opencv(opencv-master)python中进行背景减法

python - CentOS上用python模块安装OpenCV出错

c++ - addWeighted 函数中的 OpenCV( Gamma )

python - 如何操纵跟踪器区域使其变为正方形?