sohanatarafder / My-Projects--Sohana-Tarafder

Emojis Generator- This project is used to construct emojis using hand gestures.
0 stars 0 forks source link

CV2 #1

Closed shrinidhi99 closed 4 years ago

shrinidhi99 commented 4 years ago

Could you resolve the issue in openCV library link to that issue is: https://github.com/akshaybahadur21/Emojinator/issues/22

sohanatarafder commented 4 years ago

Open settings, then click on privacy to open camera. then, you have to click on 'yes' which will give the apps' access to camera.

shrinidhi99 commented 4 years ago

Did you use the same code that I have? I will check with your code once. If it doesn't work then I will get back. My webcam has automatically switched on whenever I have run the code but the issue was in some line of code where the openCV stuff was happening.

sohanatarafder commented 4 years ago

Yes I have used the same code.

sohanatarafder commented 4 years ago

Srinidhi have you completed your devanagari script recognition. Would you please help me with that?

shrinidhi99 commented 4 years ago

error Traceback (most recent call last) in 93 94 keras_predict(model1, np.zeros((32, 32, 1), dtype=np.uint8)) ---> 95 main()

in main() 35 center = None 36 if len(cnts) >= 1: ---> 37 contour = max(cnts, key=cv2.contourArea) 38 if cv2.contourArea(contour) > 250: 39 ((x, y), radius) = cv2.minEnclosingCircle(contour)

error: OpenCV(4.1.2) /io/opencv/modules/imgproc/src/shapedescr.cpp:274: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'contourArea'

This is the error that I have got in both my projects. If this error gets resolved, I guess both my projects will be complete. I think it has got to do with openCV version number. The openCV in my machine is the latest one. Which version are you using? And in devanagari project what error are you getting? Is it the exact same one?

sohanatarafder commented 4 years ago

Update the version to 4.2.0. And, my devanagri project has been completed but there's a problem regarding air character writing. I don't know what's happening but the alphabets get written on their own.

sohanatarafder commented 4 years ago

I know what's wrong with the code. Change this contours = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_NONE)[0] To contours, hierarchy = cv2.findContours(thresh.copy(), cv2.RETR_EXTERNAL, cv2.CHAIN_APPROX_SIMPLE)

sohanatarafder commented 4 years ago

And lemmi know if it's resolved.

sohanatarafder commented 4 years ago

And unfortunately I closed the issue by mistake.

shrinidhi99 commented 4 years ago

Thanks for your help. I will try resolving my error by following your solution :)

sohanatarafder commented 4 years ago

Did it work?

shrinidhi99 commented 4 years ago

I was actually working with 4.2.0 version of openCV only. I tried using my existing code for the version 3.4.8 but it didn't work. Now will try your code for 4.2.0. At the moment I have two different versions of openCV installed in my machine thanks to the virtual environment

sohanatarafder commented 4 years ago

Do this using 4.2.0 version of opencv

shrinidhi99 commented 4 years ago

I ran TrainEmojinator.py file and it trained a model and saved it. After this, in what sequence should I run the other files? I have forgotten the sequence of running these files. Create_gestures.py opened two windows one with color and another was black and white. It also asked for an input number. I gave 5 but later the windows were not closing. So I had to interrupt them to close it. EmojisGenerator.py gave 1 to 12 as output and then crashed. I had 12 images in a dummy folder that I gave as input and it predicted correctly. Now the problem is in the create_gestures.py file. I want to create my own dataset. How to fix that problem of infinite opening of window

shrinidhi99 commented 4 years ago

the window did not open where we predict the image

shrinidhi99 commented 4 years ago

Update: I ran his code once. I changed the contours, hierarchy line as you had suggested. His code worked fine. He already had generated 1000s of images in a folder and a model was ready. So it all worked well. Now I need to make a video out of it.

sohanatarafder commented 4 years ago

Oh I'm glad it worked. But could you please send me the create_gest.py file

shrinidhi99 commented 4 years ago

for emojinator?

sohanatarafder commented 4 years ago

Yesssss

shrinidhi99 commented 4 years ago

import cv2 import numpy as np import os

image_x, image_y = 50, 50

cap = cv2.VideoCapture(0) fbag = cv2.createBackgroundSubtractorMOG2()

def create_folder(folder_name): if not os.path.exists(folder_name): os.mkdir(folder_name)

def main(g_id): total_pics = 1200 cap = cv2.VideoCapture(0) x, y, w, h = 300, 50, 350, 350

create_folder("gestures/" + str(g_id))
pic_no = 0
flag_start_capturing = False
frames = 0

while True:
    ret, frame = cap.read()
    frame = cv2.flip(frame, 1)
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    mask2 = cv2.inRange(hsv, np.array([2, 50, 60]), np.array([25, 150, 255]))
    res = cv2.bitwise_and(frame, frame, mask=mask2)
    gray = cv2.cvtColor(res, cv2.COLOR_BGR2GRAY)
    median = cv2.GaussianBlur(gray, (5, 5), 0)

    kernel_square = np.ones((5, 5), np.uint8)
    dilation = cv2.dilate(median, kernel_square, iterations=2)
    opening = cv2.morphologyEx(dilation, cv2.MORPH_CLOSE, kernel_square)

    ret, thresh = cv2.threshold(opening, 30, 255, cv2.THRESH_BINARY)
    thresh = thresh[y:y + h, x:x + w]
    contours = cv2.findContours(thresh.copy(), cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)[1]

    if len(contours) > 0:
        contour = max(contours, key=cv2.contourArea)
        if cv2.contourArea(contour) > 10000 and frames > 50:
            x1, y1, w1, h1 = cv2.boundingRect(contour)
            pic_no += 1
            save_img = thresh[y1:y1 + h1, x1:x1 + w1]
            if w1 > h1:
                save_img = cv2.copyMakeBorder(save_img, int((w1 - h1) / 2), int((w1 - h1) / 2), 0, 0,
                                              cv2.BORDER_CONSTANT, (0, 0, 0))
            elif h1 > w1:
                save_img = cv2.copyMakeBorder(save_img, 0, 0, int((h1 - w1) / 2), int((h1 - w1) / 2),
                                              cv2.BORDER_CONSTANT, (0, 0, 0))
            save_img = cv2.resize(save_img, (image_x, image_y))
            cv2.putText(frame, "Capturing...", (30, 60), cv2.FONT_HERSHEY_TRIPLEX, 2, (127, 255, 255))
            cv2.imwrite("gestures/" + str(g_id) + "/" + str(pic_no) + ".jpg", save_img)

    cv2.rectangle(frame, (x, y), (x + w, y + h), (0, 255, 0), 2)
    cv2.putText(frame, str(pic_no), (30, 400), cv2.FONT_HERSHEY_TRIPLEX, 1.5, (127, 127, 255))
    cv2.imshow("Capturing gesture", frame)
    cv2.imshow("thresh", thresh)
    keypress = cv2.waitKey(1)
    if keypress == ord('c'):
        if flag_start_capturing == False:
            flag_start_capturing = True
        else:
            flag_start_capturing = False
            frames = 0
    if flag_start_capturing == True:
        frames += 1
    if pic_no == total_pics:
        break

g_id = input("Enter gesture number: ") main(g_id)

sohanatarafder commented 4 years ago

Hey did u get the certificate?

shrinidhi99 commented 4 years ago

Not yet. I am yet to submit the two projects. Every thing else is done. Once that devanagari project error gets resolved, I'll make videos of the two project and claim for a certificate.

sohanatarafder commented 4 years ago

When did you enroll for this course?

shrinidhi99 commented 4 years ago

I enrolled it in May 2019. But then I was interning, so didn't get much time. During college days I was doing it slowly and now I need to finish project submissions. What about you?

sohanatarafder commented 4 years ago

October 2019

sohanatarafder commented 4 years ago

Btw I wanna ask you so bad what's your name Shrinidhi or Anil? I got confused so many times because I didn't see your face?

shrinidhi99 commented 4 years ago

Shrinidhi but I am a boy

shrinidhi99 commented 4 years ago

Any updates in Devanagari project?

sohanatarafder commented 4 years ago

I already submitted my projects and got the certificate and currently I'm applying for internship. Devanagri project was pretty awesome. What abt you? Are u facing issues on that project?

sohanatarafder commented 4 years ago

Btw did u complete the graduate studies or are u pursuing?

shrinidhi99 commented 4 years ago

I am currently doing BTech. I am yet to finish devanagari project. I am getting an error which many were getting. Still trying to resolve it. Related to openCV only.

shrinidhi99 commented 4 years ago

processed: (1, 32, 32, 1) Traceback (most recent call last): File "/home/shrinidhi/learning-machine-learning/Projects/Devanagiri-Recognizer/Dev-Rec.py", line 103, in main() File "/home/shrinidhi/learning-machine-learning/Projects/Devanagiri-Recognizer/Dev-Rec.py", line 39, in main if len(cnts) >= 1: TypeError: object of type 'NoneType' has no len()

This is the error I am getting

shrinidhi99 commented 4 years ago

Now the error has gone. I was keen on knowing how to operate the cursor or stylus or finger gesture to write the letters on the screen? My index finger gestures aren't getting recorded but sometimes there are some zig-zag lines getting drawn without any gesture...

sohanatarafder commented 4 years ago

Did u wear blue or green? There shouldn't be any blue or green color and you don't have to write using index finger. This project is using computer vision hence area with blue color will be captured what you have to do is try it using the tip of pen that's blue in color.

shrinidhi99 commented 4 years ago

Oh ok. I will try it asap. Thanks :)

shrinidhi99 commented 4 years ago

Used a blue bottle cap and it was working xD

sohanatarafder commented 4 years ago

Great!!!

sohanatarafder commented 4 years ago

So, You're doing B.tech?? Which year you're in?

shrinidhi99 commented 4 years ago

I'm in 3rd year BTech

shrinidhi99 commented 4 years ago

Are you interning this summer?