-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCam_Detection.py
34 lines (24 loc) · 884 Bytes
/
Cam_Detection.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 cv2
import pyautogui
cap = cv2.VideoCapture(0)
face_cascade = cv2.CascadeClassifier('haarcascade_frontalface_default (2).xml')
while True:
ret, frame = cap.read()
# Convertir el fotograma a escala de grises
gray = cv2.cvtColor(frame, cv2.COLOR_BGR2GRAY)
faces = face_cascade.detectMultiScale(gray, 1.3, 5, minSize=(30, 30), maxSize=(200, 200))
for (x, y, w, h) in faces:
cv2.rectangle(frame, (x, y), (x + w, y + h), (255, 0, 0), 2)
face_center_x = x + w // 2
face_center_y = y + h // 2
if face_center_x < 200:
pyautogui.press('left')
print("Moviendo hacia la izquierda")
elif face_center_x > 440:
pyautogui.press('right')
print("Moviendo hacia la derecha")
cv2.imshow('Face Detection', frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release()
cv2.destroyAllWindows()