-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
64 lines (47 loc) · 1.63 KB
/
main.py
File metadata and controls
64 lines (47 loc) · 1.63 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
61
62
63
64
"""
This is the main module for the application.
"""
# 1st party imports
import json
# 3rd party imports
import cv2
# local imports
from config import SHOW_IMAGE
from detector.detector import Detector
from camera_handler.camera import CameraHandler
from mouse_handler.mouse_handler import MouseHandler
# create instances
camera_handler = CameraHandler()
detector = Detector()
mouse_handler = MouseHandler()
# run the camera
while camera_handler.cap.isOpened():
# get the frame and check if it is successful
success, orignal_image = camera_handler.get_frame()
# if the frame is not successful, continue
if not success:
print("Ignoring empty camera frame.")
continue
# preprocess the image
processed_image = camera_handler.preprocess_image_for_hands(orignal_image)
# Process the image and detect hands
results = detector.detect_hands(processed_image)
# get the cordinates of the index, middle and thumb tips
coordinates = detector.get_cordinates(results, orignal_image)
# show the image if in debug mode
if SHOW_IMAGE:
# Draw hand landmarks
drawn_image = camera_handler.draw_hand_landmarks(coordinates, orignal_image)
# show the image
camera_handler.show_image(drawn_image)
# check if palm is visible
palm_is_visible = detector.is_palm_visible(coordinates)
# check if palm is visible
if palm_is_visible:
# perform actions based on the landmarks
mouse_handler.handle_mouse_actions(coordinates)
# Break on 'q' key
if cv2.waitKey(5) & 0xFF == ord("q"):
break
camera_handler.cap.release()
cv2.destroyAllWindows()