forked from Largo-m/security-tools-hacking
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcapture_webcam.py
More file actions
43 lines (31 loc) · 955 Bytes
/
Copy pathcapture_webcam.py
File metadata and controls
43 lines (31 loc) · 955 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
32
33
34
35
36
37
38
39
40
41
42
import cv2
import time
import random
from datetime import datetime
import os
# 8/13/2025
# Get JPG Picture from user Face if camera enabled
# AUX-441
class Camera_:
def get_picture(self, save_path="captured_faces"):
os.makedirs(save_path, exist_ok=True)
cap = cv2.VideoCapture(0)
if not cap.isOpened():
print("Cannot access camera")
return None
print("Camera activated.")
time.sleep(random.randint(1,3))
ret, frame = cap.read()
if not ret:
print("Failed to capture image")
cap.release()
return None
filename = datetime.now().strftime("%Y%m%d_%H%M%S") + ".jpg"
full_path = os.path.join(save_path, filename)
cv2.imwrite(full_path, frame)
cap.release()
print(f"Picture saved to {full_path}")
return full_path
if __name__ == "__main__":
cam = Camera_()
cam.get_picture()