Ask Your Question
0

Python: ValueError: too many values to unpack

asked 2014-08-26 08:18:29 -0600

ahmadux gravatar image

updated 2014-08-26 08:20:02 -0600

I'm writing an opencv program and I found a script on another stackoverflow question: Computer Vision Masking A Human Hand

I've already asked this question at Stackoverflow: OpenCV python: ValueError: too many values to unpack

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

The code:

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)

Any help is appreciated!

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2014-08-26 10:09:13 -0600

Guanta gravatar image

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

Thus, change the correspinding line to:

_, 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.

edit flag offensive delete link more

Comments

Excellent stuff! To note, I changed the line. Thanks for the solution!

ahmadux gravatar imageahmadux ( 2014-08-26 10:39:22 -0600 )edit

Question Tools

Stats

Asked: 2014-08-26 08:18:29 -0600

Seen: 16,182 times

Last updated: Aug 26 '14