forked from kinivi/hand-gesture-recognition-mediapipe
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
60 lines (46 loc) · 2.12 KB
/
app.py
File metadata and controls
60 lines (46 loc) · 2.12 KB
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
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from src.application.application_mode import select_mode, ApplicationMode
from src.application.initialize_application import initialize_application
from src.domain.GestureRules import apply_rules
from src.domain.logger import log_data
from src.domain.GestureReader import prepare_for_model, prepare_points_for_model
from src.infrastructure.openCV.Keys import get_key_press
from src.infrastructure.openCV.draw.ScreenPrinter import print_screen
def main():
# Argument parsing #################################################################
video_capture, cv_fps_calc, \
hands_reader, gesture_reader, mode = initialize_application()
while True:
fps = cv_fps_calc.get()
key = get_key_press()
if key == 27: # ESC
break
number, mode = select_mode(key, mode)
ret, image = video_capture.get_frame()
if not ret:
break
processable_image, debug_image = image.prepare()
processable_image.image.flags.writeable = False
hands = hands_reader.get_hands(processable_image)
processable_image.image.flags.writeable = True
if hands is not None:
gestures = gesture_reader.read(hands, image)
if mode != ApplicationMode.PLAY:
for hand, gesture in zip(hands.hands_list, gestures):
print_screen(
debug_image, mode, fps, number, hand, gesture_reader.book_keeper.index_location_history,
gesture.hand_sign, gesture.finger_gesture)
log_data(mode, number,
prepare_points_for_model(gesture_reader.book_keeper.index_location_history, image),
prepare_for_model(hand))
print(apply_rules(gestures))
elif mode == ApplicationMode.PLAY:
print(apply_rules(gestures))
else:
if mode != ApplicationMode.PLAY:
print_screen(
debug_image, mode, fps, number)
video_capture.destroy_windows()
if __name__ == '__main__':
main()