-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcapture_face.py
More file actions
31 lines (23 loc) · 845 Bytes
/
capture_face.py
File metadata and controls
31 lines (23 loc) · 845 Bytes
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
import cv2
import os
import time
# Define a directory to save the captured face image
TEST_IMAGE_PATH = "assets/test_face.jpg"
def capture_face():
"""Captures an image from the webcam automatically after 1 second."""
cap = cv2.VideoCapture(0) # Open webcam
if not cap.isOpened():
print("Error: Could not open webcam.")
return False
print("📷 Capturing your face... Look at the camera.")
time.sleep(1) # Wait for 1 second before capturing
ret, frame = cap.read()
if not ret:
print("Error: Failed to capture image.")
cap.release()
return False
cv2.imwrite(TEST_IMAGE_PATH, frame)
print("✅ Face captured successfully!")
cap.release()
cv2.destroyAllWindows()
return True # Return True if face capture is successful