-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
22 lines (16 loc) · 787 Bytes
/
Copy pathmain.py
File metadata and controls
22 lines (16 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import cv2
# Load the pre-trained Haar Cascade Classifier for face detection
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml')
# Load an image
image = cv2.imread('test1.jpg') # Replace with the path to your image
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) # Convert to grayscale for better detection
# Detect faces in the image
faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30))
# Draw rectangles around the faces
for (x, y, w, h) in faces:
cv2.rectangle(image, (x, y), (x + w, y + h), (0, 255, 0), 3)
# Display the result
cv2.imshow('Face Detection', image)
# Wait until a key is pressed and close the image window
cv2.waitKey(0)
cv2.destroyAllWindows()