-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclosingApplication.py
More file actions
151 lines (131 loc) · 5.82 KB
/
Copy pathclosingApplication.py
File metadata and controls
151 lines (131 loc) · 5.82 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
import win32com.client
from datetime import datetime
import time
import mediapipe as mp
import cv2
import pyautogui as py
application_closed = False
def close():
cap = cv2.VideoCapture(0)
mp_hands = mp.solutions.hands
hands = mp_hands.Hands(static_image_mode=False, max_num_hands=1,
min_detection_confidence=0.5, min_tracking_confidence=0.5)
mp_drawing = mp.solutions.drawing_utils
while True:
global application_closed
application_closed = False
ret, frame = cap.read()
image_rbg = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
results = hands.process(image_rbg)
if results.multi_hand_landmarks:
for hands_landmarks in results.multi_hand_landmarks:
mp_drawing.draw_landmarks(frame, hands_landmarks, mp_hands.HAND_CONNECTIONS)
index_finger_tip = hands_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP].y
index_finger_pip = hands_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_PIP].y
middle_finger_tip = hands_landmarks.landmark[mp_hands.HandLandmark.MIDDLE_FINGER_TIP].y
middle_finger_pip = hands_landmarks.landmark[mp_hands.HandLandmark.RING_FINGER_PIP].y
ring_finger_tip = hands_landmarks.landmark[mp_hands.HandLandmark.RING_FINGER_TIP].y
ring_finger_pip = hands_landmarks.landmark[mp_hands.HandLandmark.RING_FINGER_PIP].y
# other finger
pinky_finger_pip = hands_landmarks.landmark[mp_hands.HandLandmark.PINKY_PIP].y
pinky_finger_tip = hands_landmarks.landmark[mp_hands.HandLandmark.PINKY_TIP].y
if index_finger_tip < index_finger_pip and middle_finger_tip < middle_finger_pip and ring_finger_tip > ring_finger_pip and pinky_finger_tip > pinky_finger_pip:
cv2.putText(frame, "scissors gesture \n closing current application ", (50, 50),
cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 255), 2)
py.hotkey("alt", "f4")
py.sleep(2)
py.press("enter")
time.sleep(2)
timestamp = datetime.now().strftime("%d-%m-%Y_%H-%M-%S")
file_name = f"Notes_{timestamp}.docx"
py.write(file_name)
py.sleep(2)
py.press("enter")
time.sleep(8)
py.hotkey('ctrl', 'f2')
application_closed = True
# print("closed closing application ")
else:
cv2.putText(frame, "not detected ", (50, 50), cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 255), 2)
# cv2.imshow("closing applications ", frame)
if cv2.waitKey(1) & 0xFF == ord("q") or application_closed:
break
cap.release()
cv2.destroyAllWindows()
# close()
# import mediapipe as mp
# import cv2
# import pyautogui
#
# # Initialize the camera
# cap = cv2.VideoCapture(0)
#
# # Initialize Mediapipe Hands
# mp_hands = mp.solutions.hands
# hands = mp_hands.Hands(static_image_mode=False, max_num_hands=1,
# min_detection_confidence=0.5, min_tracking_confidence=0.5)
#
# # Initialize Mediapipe Drawing
# mp_drawing = mp.solutions.drawing_utils
#
# def close():
# while True:
# # Capture the frame
# ret, frame = cap.read()
#
# # Check if frame was captured successfully
# if not ret:
# print("Failed to capture frame. Exiting...")
# break
#
# # Convert the frame to RGB
# image_rgb = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
#
# # Process the frame to detect hands
# results = hands.process(image_rgb)
#
# # Check if any hand landmarks are detected
# if results.multi_hand_landmarks:
# for hand_landmarks in results.multi_hand_landmarks:
# mp_drawing.draw_landmarks(frame, hand_landmarks, mp_hands.HAND_CONNECTIONS)
#
# # Get landmark positions
# index_finger_tip = hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_TIP]
# index_finger_pip = hand_landmarks.landmark[mp_hands.HandLandmark.INDEX_FINGER_PIP]
#
# middle_finger_tip = hand_landmarks.landmark[mp_hands.HandLandmark.MIDDLE_FINGER_TIP]
# middle_finger_pip = hand_landmarks.landmark[mp_hands.HandLandmark.MIDDLE_FINGER_PIP]
#
# ring_finger_tip = hand_landmarks.landmark[mp_hands.HandLandmark.RING_FINGER_TIP]
# ring_finger_pip = hand_landmarks.landmark[mp_hands.HandLandmark.RING_FINGER_PIP]
#
# pinky_finger_tip = hand_landmarks.landmark[mp_hands.HandLandmark.PINKY_TIP]
# pinky_finger_pip = hand_landmarks.landmark[mp_hands.HandLandmark.PINKY_PIP]
#
# # Detect "scissors gesture"
# if (
# index_finger_tip.y < index_finger_pip.y and
# middle_finger_tip.y < middle_finger_pip.y and
# ring_finger_tip.y > ring_finger_pip.y and
# pinky_finger_tip.y > pinky_finger_pip.y
# ):
# cv2.putText(frame, "Scissors gesture detected: Closing application",
# (50, 50), cv2.FONT_HERSHEY_PLAIN, 1, (0, 0, 255), 2)
# pyautogui.hotkey("alt", "f4")
# else:
# cv2.putText(frame, "Gesture not detected",
# (50, 50), cv2.FONT_HERSHEY_PLAIN, 1, (255, 0, 0), 2)
#
# # Display the frame
# cv2.imshow("Frame", frame)
#
# # Break loop on 'q' key press
# if cv2.waitKey(1) & 0xFF == ord("q"):
# break
#
# # Release resources
# cap.release()
# cv2.destroyAllWindows()
#
# # Call the close function
# close()