-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
49 lines (39 loc) · 1.47 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
import cv2
import signal
import sys
from core import VideoProcessor, StateManager
from gestures import CursorControl, ClickHandler
from additional.utils import setup_window
def signal_handler(sig, frame):
print('\nprogramm updated (Control+C)')
cv2.destroyAllWindows()
sys.exit(0)
def main():
signal.signal(signal.SIGINT, signal_handler)
video_processor = VideoProcessor()
state_manager = StateManager()
cursor_control = CursorControl(*video_processor.screen_size)
click_handler = ClickHandler()
setup_window(video_processor.mouse_callback)
try:
while video_processor.is_camera_opened():
image = video_processor.process_frame()
if image is None:
continue
hand_landmarks = video_processor.detect_hand(image)
if hand_landmarks:
image = state_manager.process_hand(image, hand_landmarks, video_processor, cursor_control, click_handler)
else:
state_manager.reset()
cursor_control.reset()
video_processor.draw_no_hand_message(image)
video_processor.draw_interface(image, state_manager, click_handler)
if video_processor.should_exit():
break
except KeyboardInterrupt:
print('\nПрограмма остановлена (Control+C)')
finally:
video_processor.release()
cv2.destroyAllWindows()
if __name__ == "__main__":
main()