-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
34 lines (32 loc) · 1.25 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
import mediapipe as mp
import cv2 as cv
import pyautogui
cam = cv.VideoCapture(0)
face_maesh = mp.solutions.face_mesh.FaceMesh(refine_landmarks = True)
screen_w ,screen_h = pyautogui.size()
while 1>0:
_, frame = cam.read()
frame = cv.flip(frame,1)
rgb_Frame = cv.cvtColor(frame, cv.COLOR_BGR2RGB)
output = face_maesh.process(rgb_Frame)
landmark_points = output.multi_face_landmarks
frame_h, frame_w , _ = frame.shape
if landmark_points:
landmarks = landmark_points[0].landmark
for id , landmark in enumerate( landmarks[474:478]):
x = int(landmark.x * frame_w)
y = int(landmark.y * frame_h)
cv.circle(frame,(x,y),3 , (0,255,0))
if id == 1:
screen_x = int(landmark.x * screen_w)
screen_y = int(landmark.y * screen_h)
pyautogui.moveTo(screen_x,screen_y)
left = [ landmarks[145], landmarks[159]]
for landmark in left:
x = int(landmark.x * frame_w)
y = int(landmark.y * frame_h)
cv.circle(frame,(x,y),3 , (0,255,255))
if (left[0].y - left[1].y)<0.008:
pyautogui.click()
cv.imshow("Eye Contolled Mouse", frame)
cv.waitKey(1)