forked from Er-AI-GK/oneAPI-Sign-Language-Gesture-Translator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
62 lines (44 loc) · 1.78 KB
/
main.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
60
61
62
import numpy as np
import os
import mediapipe as mp
import cv2
from my_functions import *
import tensorflow as tf
from tensorflow import keras
from keras.models import load_model
import keyboard
PATH = os.path.join('data')
actions = np.array(os.listdir(PATH))
model = load_model('my_model')
sentence, keypoints = [' '], []
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Cannot access camera.")
exit()
with mp.solutions.holistic.Holistic(min_detection_confidence=0.75, min_tracking_confidence=0.75) as holistic:
while cap.isOpened():
_, image = cap.read()
results = image_process(image, holistic)
draw_landmarks(image, results)
keypoints.append(keypoint_extraction(results))
if len(keypoints) == 10:
keypoints = np.array(keypoints)
prediction = model.predict(keypoints[np.newaxis, :, :])
keypoints = []
if np.amax(prediction) > 0.9:
if sentence[-1] != actions[np.argmax(prediction)]:
sentence.append(actions[np.argmax(prediction)])
if len(sentence) > 7:
sentence = sentence[-7:]
if keyboard.is_pressed(' '):
sentence = [' ']
textsize = cv2.getTextSize(' '.join(sentence), cv2.FONT_HERSHEY_SIMPLEX, 1, 2)[0]
text_X_coord = (image.shape[1] - textsize[0]) // 2
cv2.putText(image, ' '.join(sentence), (text_X_coord, 470),
cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2, cv2.LINE_AA)
cv2.imshow('Camera', image)
cv2.waitKey(1)
if cv2.getWindowProperty('Camera',cv2.WND_PROP_VISIBLE) < 1:
break
cap.release()
cv2.destroyAllWindows()