CV Faces File

You might also like

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

import cv2

face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades
+'haarcascade_frontalface_default.xml')

image_path = 'C:/Users/avina/OneDrive/Desktop/pic 2.jpg'

image = cv2.imread(image_path)

gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray_image)

for (x,y,w,h) in faces:


cv2.rectangle(image,(x,y),(x+w ,y+h),(0,250,0),5)

cv2.imshow('Faces detection: ',image)


print("Number of faces detected:",len(faces))
cv2.waitKey(0)

import cv2

face_cascade =
cv2.CascadeClassifier(cv2.data.haarcascades+'haarcascade_frontalfaace_default.xml')

image_path = 'C:/Users/avina/OneDrive/Desktop/pic 2.jpg'

image = cv2.imread(image_path)

gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

faces = face_cascade.detectMultiScale(gray_image)

for (x, y, w, h) in faces:


cv2.rectangle(image, (x+y), (x+w, y+h), (0, 225, 0), 5)
cv2.imshow('faces', image)
print("faces are :", len(faces))
cv2.waitKey(0)

You might also like