Skip to content

Commit

Permalink
Merge pull request #141 from ChampGupta/main
Browse files Browse the repository at this point in the history
Face detection feature added to the code base
  • Loading branch information
suryanshsk authored Oct 11, 2024
2 parents e380101 + 5b8cdea commit b7e9c78
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions face_detection.py
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()

0 comments on commit b7e9c78

Please sign in to comment.