OpenCV python: ValueError: too many values to unpack
本帖最后由 莫晓沙 于 2018-10-13 10:15 编辑我正在写一个opencv程序,我找到了另一个stackoverflow有问题的脚本,链接如下:
https://stackoverflow.com/questions/14752006/computer-vision-masking-a-human-hand/14756351#14756351
运行脚本的时候却发现报错了
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)这是咋回事啊
本帖最后由 AI的世界 于 2018-10-13 10:15 编辑
在opencv堆栈交换站点有答案
Opencv的主分支的返回语句已经改了:
http://docs.opencv.org/modules/i ... light=findcontours.
因此对应的行应该改为:
_, contours, _= cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
页:
[1]