-
Notifications
You must be signed in to change notification settings - Fork 21
/
main.py
50 lines (37 loc) · 1.66 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
import cv2
import mediapipe
from utils.dataset_utils import load_dataset, load_reference_signs
from utils.mediapipe_utils import mediapipe_detection
from sign_recorder import SignRecorder
from webcam_manager import WebcamManager
if __name__ == "__main__":
# Create dataset of the videos where landmarks have not been extracted yet
videos = load_dataset()
# Create a DataFrame of reference signs (name: str, model: SignModel, distance: int)
reference_signs = load_reference_signs(videos)
# Object that stores mediapipe results and computes sign similarities
sign_recorder = SignRecorder(reference_signs)
# Object that draws keypoints & displays results
webcam_manager = WebcamManager()
# Turn on the webcam
cap = cv2.VideoCapture(0, cv2.CAP_DSHOW)
# Set up the Mediapipe environment
with mediapipe.solutions.holistic.Holistic(
min_detection_confidence=0.5, min_tracking_confidence=0.5
) as holistic:
while cap.isOpened():
# Read feed
ret, frame = cap.read()
# Make detections
image, results = mediapipe_detection(frame, holistic)
# Process results
sign_detected, is_recording = sign_recorder.process_results(results)
# Update the frame (draw landmarks & display result)
webcam_manager.update(frame, results, sign_detected, is_recording)
pressedKey = cv2.waitKey(1) & 0xFF
if pressedKey == ord("r"): # Record pressing r
sign_recorder.record()
elif pressedKey == ord("q"): # Break pressing q
break
cap.release()
cv2.destroyAllWindows()