Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

I am learning Open CV using Python, and after doing some tutorials I found one exercise of hand gesture recognition but it gave me the next error :

image description

Here is my code:

image description

Any help is really appreciated!

I am learning Open CV using Python, and after doing some tutorials I found one exercise of hand gesture recognition but it gave me the next error :

image description

Traceback (most recent call last): File "F:\David\Varios\OPENCV\hand gestures.py", line 11, in <module> contours, hierarchy = cv2.findContours(th,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) ValueError: too many values to unpack

Here is my the code:

image descriptionimport numpy as np import cv2

cap = cv2.VideoCapture(0)

while(True): ret, frame = cap.read() gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (3,3),0) ret, th = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) contours, hierarchy = cv2.findContours(th,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) areas = [cv2.contourArea(temp) for temp in contours] max_index = np.argmax(areas) largest_contour = contours[max_index] approx = cv2.approxPolyDP(largest_contour,0.01*cv2.arcLength(largest_contour,True),True) hull = cv2.convexHull(approx,returnPoints = True) cv2.putText(frame,'Number of Fingers ' + str (len(hull)-2),(10,30),cv2.FONT_HERSHEY_COMPLEX_SMALL,1,(255,0,0)) cv2.drawContours(frame,[hull],0,(0,0,255),1) for i in range ( len( hull) ): [x,y] = hull[i] [0].flatten() cv2.circle(frame,(int(x), int(y)),2,(0,255,0),-1) cv2.circle(frame,(int(x), int(y)),5,(255,255,0),1) cv2.circle(frame,(int(x), int(y)),8,(255,0,0),1) print "Number of Fingers " + str ( (len(hull)-2) ) cv2.imshow('Gestures',frame)

    if cv2.waitKey(5) == 27:
        break
cv2.destroyAllWindows()
cap.release()

The version of Open CV is 3.2 and python 2.7

Any help is really appreciated!

I am learning Open CV using Python, and after doing some tutorials I found one exercise of hand gesture recognition but it gave me the next error :

Traceback (most recent call last): File "F:\David\Varios\OPENCV\hand gestures.py", line 11, in <module> contours, hierarchy = cv2.findContours(th,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) ValueError: too many values to unpack

Here is the code:

import numpy as np import cv2

cap = cv2.VideoCapture(0)

while(True): ret, frame = cap.read() gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (3,3),0) ret, th = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) contours, hierarchy = cv2.findContours(th,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) areas = [cv2.contourArea(temp) for temp in contours] max_index = np.argmax(areas) largest_contour = contours[max_index] approx = cv2.approxPolyDP(largest_contour,0.01*cv2.arcLength(largest_contour,True),True) hull = cv2.convexHull(approx,returnPoints = True) cv2.putText(frame,'Number of Fingers ' + str (len(hull)-2),(10,30),cv2.FONT_HERSHEY_COMPLEX_SMALL,1,(255,0,0)) cv2.drawContours(frame,[hull],0,(0,0,255),1) for i in range ( len( hull) ): [x,y] = hull[i] [0].flatten() cv2.circle(frame,(int(x), int(y)),2,(0,255,0),-1) cv2.circle(frame,(int(x), int(y)),5,(255,255,0),1) cv2.circle(frame,(int(x), int(y)),8,(255,0,0),1) print "Number of Fingers " + str ( (len(hull)-2) ) cv2.imshow('Gestures',frame)

    if cv2.waitKey(5) == 27:
        break
cv2.destroyAllWindows()
cap.release()

The version of Open CV is 3.2 and python 2.7

Any help is really appreciated!

click to hide/show revision 4
No.4 Revision

updated 2017-07-29 02:21:04 -0600

berak gravatar image

I am learning Open CV using Python, and after doing some tutorials I found one exercise of hand gesture recognition but it gave me the next error :

Traceback (most recent call last):
  File "F:\David\Varios\OPENCV\hand gestures.py", line 11, in <module>
    contours, hierarchy = cv2.findContours(th,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
ValueError: too many values to unpack

unpack >>>

Here is the code:

import numpy as np
import cv2

cv2 cap = cv2.VideoCapture(0)

cv2.VideoCapture(0) while(True): ret, frame = cap.read() gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY) blur = cv2.GaussianBlur(gray, (3,3),0) ret, th = cv2.threshold(blur,0,255,cv2.THRESH_BINARY_INV+cv2.THRESH_OTSU) contours, hierarchy = cv2.findContours(th,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE) areas = [cv2.contourArea(temp) for temp in contours] max_index = np.argmax(areas) largest_contour = contours[max_index] approx = cv2.approxPolyDP(largest_contour,0.01*cv2.arcLength(largest_contour,True),True) hull = cv2.convexHull(approx,returnPoints = True) cv2.putText(frame,'Number of Fingers ' + str (len(hull)-2),(10,30),cv2.FONT_HERSHEY_COMPLEX_SMALL,1,(255,0,0)) cv2.drawContours(frame,[hull],0,(0,0,255),1) for i in range ( len( hull) ): [x,y] = hull[i] [0].flatten() cv2.circle(frame,(int(x), int(y)),2,(0,255,0),-1) cv2.circle(frame,(int(x), int(y)),5,(255,255,0),1) cv2.circle(frame,(int(x), int(y)),8,(255,0,0),1) print "Number of Fingers " + str ( (len(hull)-2) ) cv2.imshow('Gestures',frame)

cv2.imshow('Gestures',frame)

        if cv2.waitKey(5) == 27:
         break
 cv2.destroyAllWindows()
 cap.release()

The version of Open CV is 3.2 and python 2.7

Any help is really appreciated!