-
Notifications
You must be signed in to change notification settings - Fork 0
/
ASLdetection.py
59 lines (46 loc) · 1.37 KB
/
ASLdetection.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import cv2
import Handtrack_module as htm
import numpy as np
import torch
from model import Net
net = Net()
net.load_state_dict(torch.load("model_parameters/model_parameter.pkl",map_location=torch.device('cpu')))
video = cv2.VideoCapture(0)
detector = htm.handdetector(detectionCon=0.85)
# img = detector.findHands(img)
# lmlist = detector.findposition(img,draw =False)
video.set(3,800)
video.set(4,800)
t =0
fingers = []
net.eval()
c=0
pastchar = None
curchar:chr
while True:
success, img = video.read()
if c<15:
c+=1
else:
img = detector.findHands(img)
lmlist = detector.findposition(img,draw =False)
if(len(lmlist)!=0):
lmlist = np.array(lmlist).reshape(-1,63)
outputs = net(torch.tensor(lmlist,dtype = torch.float32))
if(0<=torch.argmax(outputs,dim=1)<=25):
curchar = chr(torch.argmax(outputs,dim=1)+65)
elif torch.argmax(outputs,dim=1)==26:
curchar = "space"
elif torch.argmax(outputs,dim=1)==27:
curchar = "del"
else:
curchar = "nothing"
if curchar!=pastchar:
print(curchar)
pastchar = curchar
c=0
cv2.imshow("Img",img)
cv2.waitKey(1)
'''
I can set a threshold. When neural network determines which hand should it be, it cools down for 1 second.
# '''