OpenCV python:ValueError:解压的值太多 [英] OpenCV python: ValueError: too many values to unpack
问题描述
我正在编写一个 opencv 程序,我在另一个 stackoverflow 问题上找到了一个脚本:计算机视觉:掩盖人手
I'm writing an opencv program and I found a script on another stackoverflow question: Computer Vision: Masking a human hand
当我运行脚本化答案时,出现以下错误:
When I run the scripted answer, I get the following error:
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 站点得到了答案.答案
I got the answer from the OpenCV Stack Exchange site. Answer
答案:
我敢打赌您正在使用当前 OpenCV 的主分支:这里的返回语句已更改,请参阅 http://docs.opencv.org/modules/imgproc/doc/structural_analysis_and_shape_descriptors.html?highlight=findcontours.
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)
或者:由于当前主干还不稳定,你可能会遇到更多问题,你可能需要使用OpenCV当前的稳定版本2.4.9.
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.
这篇关于OpenCV python:ValueError:解压的值太多的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!