akshaybahadur21 / Emojinator

A simple emoji classifier for humans. 🖖
MIT License
501 stars 190 forks source link

showing error in making gestures #19

Open himanshu3897 opened 5 years ago

himanshu3897 commented 5 years ago

cv2.error: OpenCV(4.1.1) C:\projects\opencv-python\opencv\modules\imgproc\src\shapedescr.cpp:274:

himanshu3897 commented 5 years ago

gesture folder are made but cant save any image over that

mM-009 commented 5 years ago

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 ?

mM-009 commented 5 years ago

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

pradeep42375 commented 4 years ago

It is still not creating the gestures

sohanatarafder99 commented 4 years ago

my create gesture file is completely working but it is not saving the images