# ---
# jupyter:
#   jupytext:
#     text_representation:
#       extension: .py
#       format_name: light
#       format_version: '1.5'
#       jupytext_version: 1.14.4
#   kernelspec:
#     display_name: Python 3
#     language: python
#     name: python3
# ---

# +
# importing the libraries

import cv2 # importing the opencv for detecting the face
import numpy as np # for array manipulation

# -

# importing classifiers
# for classifing the face
face_classifier =cv2.CascadeClassifier(cv2.data.haarcascades +'haarcascade_frontalface_default.xml')


face_classifier

# +
# reading_image
# reading the image, it read the image and store the pixcel value of the image
image = cv2.imread('faceDetect1.jpg')  

# converting the color image to black and white image
gray_image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)
# -

# detecting multiple faces in a image
# detectMultiScale -  Detects objects of different sizes in the input image. The detected objects are returned as a list of rectangles
faces = face_classifier.detectMultiScale(gray_image) 

# +

for (x,y,w,h) in faces:
    
    # draw rectangle around face region    
    cv2.rectangle(image,(x,y),(x+w,y+h),(0,255,0),2)
    
# -

# saving the detected images
cv2.imwrite('DetectedFaces.png',image)

# +
# displaying the detected images
cv2.imshow('DetectedFaces',image)

cv2.waitKey(0)

# closing all the windows
cv2.destroyAllWindows()
# -






StarcoderdataJupyterScriptsDedupFiltered