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:
JavaScript
x
5
1
Traceback (most recent call last):
2
File "skinimagecontour.py", line 13, in <module>
3
contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
4
ValueError: too many values to unpack
5
The code:
JavaScript
1
19
19
1
import sys
2
import numpy
3
import cv2
4
5
im = cv2.imread('Photos/test.jpg')
6
im_ycrcb = cv2.cvtColor(im, cv2.COLOR_BGR2YCR_CB)
7
8
skin_ycrcb_mint = numpy.array((0, 133, 77))
9
skin_ycrcb_maxt = numpy.array((255, 173, 127))
10
skin_ycrcb = cv2.inRange(im_ycrcb, skin_ycrcb_mint, skin_ycrcb_maxt)
11
cv2.imwrite('Photos/output2.jpg', skin_ycrcb) # Second image
12
13
contours, _ = cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
14
for i, c in enumerate(contours):
15
area = cv2.contourArea(c)
16
if area > 1000:
17
cv2.drawContours(im, contours, i, (255, 0, 0), 3)
18
cv2.imwrite('Photos/output3.jpg', im)
19
Any help is appreciated!
Advertisement
Answer
I got the answer from the OpenCV Stack Exchange site. Answer
THE 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:
JavaScript121_, contours, _= cv2.findContours(skin_ycrcb, cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)
2
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.