Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Name :Arya Chowkekar Roll no:- 04 Batch:-Et-01/T11 Subject IPMV

Input:-
import cv2
from google.colab.patches import cv2_imshow

def detect_faces(image_path):
# Load the pre-trained face detection model
face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades +
'haarcascade_frontalface_default.xml')

# Read the image


image = cv2.imread(image_path)

# Convert the image to grayscale


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 image with detected faces


cv2_imshow(image)

# Replace '/casestudy.jpg' with the path to your image


image_path = '/casestudy.jpg'
detect_faces(image_path)
Output :

You might also like