Open himanshu3897 opened 5 years ago
gesture folder are made but cant save any image over that
The problem related to not being able to run CreateGest.py is due different versions of OpenCV as cv2.findContours() has varying return signatures in OpenCV 3.4.X, OpenCV 2.X and 4.1.X.
using the code below
contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
contours = contours[0] if len(contours) == 2 else contours[1]
instead of
contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE) [1]
runs CreateGest.py and saves 1200 images in the folder. However, the images are still not generating good hand contours.
I am using opencv-contrib-python==4.1.1.26
@akshaybahadur21 which opencv version did you use in this project ?
anyway, the above method in opencv == 4.1.1.26 had contour problem as it was finding black object from white background. This is incorrect because in OpenCV, object to be found should be white and background should be black. So the image needs to be inverted using THRESH_BINARY_INV
as shown below:
ret, thresh = cv2.threshold(opening, 30, 255, cv2.THRESH_BINARY_INV)
instead of :
ret, thresh = cv2.threshold(opening, 30, 255, cv2.THRESH_BINARY)
so the code after all changes is :
# ret, thresh = cv2.threshold(opening, 30, 255, cv2.THRESH_BINARY)
ret, thresh = cv2.threshold(opening, 30, 255, cv2.THRESH_BINARY_INV)
thresh = thresh[y:y + h, x:x + w]
#contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]
contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
contours = contours[0] if len(contours) == 2 else contours[1]
CreateGest.py runs correctly using above changes in code for opencv version 4.1.1.26
It is still not creating the gestures
my create gesture file is completely working but it is not saving the images
cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgproc\src\shapedescr.cpp:274: