forked from metafy-social/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain_nose_scroll.py
More file actions
executable file
·58 lines (31 loc) · 1.04 KB
/
main_nose_scroll.py
File metadata and controls
executable file
·58 lines (31 loc) · 1.04 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
import cv2
import mediapipe as mp
import pyautogui as pd
face_mesh = mp.solutions.face_mesh.FaceMesh(max_num_faces=1)
frame_width = 640
frame_height = 480
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
frame = cv2.flip(frame,1)
frame = cv2.resize(frame, (frame_width, frame_height))
new_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
output = face_mesh.process(new_frame)
landmarks_points = output.multi_face_landmarks
if landmarks_points:
landmarks = landmarks_points[0].landmark
x = int(landmarks[1].x * frame_width)
y = int(landmarks[1].y * frame_height)
if y < 200:
pd.press("up")
elif y>250:
pd.press("down")
if x > 320:
pd.press("right")
elif x < 180:
pd.press("left")
cv2.imshow("face", frame)
if cv2.waitKey(2) & 0xFF == ord("d"):
break
cap.release()
cv2.destroyAllWindows()