-
Notifications
You must be signed in to change notification settings - Fork 113
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #141 from ChampGupta/main
Face detection feature added to the code base
- Loading branch information
Showing
1 changed file
with
22 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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 the image where you want to detect faces | ||
image = cv2.imread('path_to_image.jpg') | ||
|
||
# Convert the image to grayscale as the face detection model works with gray images | ||
gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) | ||
|
||
# Detect faces in the image | ||
faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5, minSize=(30, 30)) | ||
|
||
# Draw rectangles around the detected faces | ||
for (x, y, w, h) in faces: | ||
cv2.rectangle(image, (x, y), (x+w, y+h), (255, 0, 0), 2) | ||
|
||
# Display the output | ||
cv2.imshow('Face Detection', image) | ||
cv2.waitKey(0) | ||
cv2.destroyAllWindows() |