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
| import cv2
import mediapipe as mp
import pyautogui
import webbrowser
def detection():
cam = cv2.VideoCapture(0)
face_mesh = mp.solutions.face_mesh.FaceMesh(refine_landmarks = True)
compteur = 0
taille_la, taille_ha = pyautogui.size()
while True:
_,frame = cam.read()
frame = cv2.flip(frame, 1)
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
output = face_mesh.process(rgb_frame)
landmark_points = output.multi_face_landmarks
frame_h, frame_l,_ = frame.shape
if landmark_points:
landmarks = landmark_points[0].landmark
for id, landmark in enumerate(landmarks[474:478]):
compteur = compteur+1
x = int(landmark.x*frame_l)
y = int(landmark.y*frame_h)
cv2.circle(frame,(x,y),3,(0,0,255))
if id ==1:
#screen_x = taille_la/frame_l*x
#screen_y = taille_ha/frame_h*y
screen_x = taille_la*landmark.x
screen_y = taille_ha*landmark.y
pyautogui.moveTo(screen_x,screen_y)
yeux = [landmarks[145], landmarks[159]]
yeux1 = [landmarks[275], landmarks[276]]
for landmark in yeux:
x = int(landmark.x*frame_l)
y = int(landmark.y*frame_h)
cv2.circle(frame,(x,y),3,(0,255,255))
for landmark in yeux1:
x = int(landmark.x*frame_l)
y = int(landmark.y*frame_h)
cv2.circle(frame, (x,y), 3,(255,0,255))
if (yeux[0].y - yeux[1].y)<0.004: # commande cligner de yeux
pyautogui.click() # mais quand j'appuye sur q mais cela ne marche pas
pyautogui.sleep(3)
ouverture()
print("detection de clignement")
if(cv2.waitKey(1) & 0xff == ord('q')):
break
cv2.imshow('Controle par yeux', frame)
#cv2.waitKey(1)
if (cv2.waitKey(1) & 0xff == ord('q')):
print("arret")
break
def ouverture():
webbrowser.open("https://www.google.com/", new = 0, autoraise = True)
detection() |
Partager