FACE DETECTION IN IMAGE FILE USING PYTHON

# Face detection in a image file
import cv2

# trained dataset (from github)
trained_dataset = cv2.CascadeClassifier('haarcascade_frontalface_default.xml')

# read image
img = cv2.imread('images/multiface.jpg')

# convert colour img to grayscale img
gray_img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

# getting values of x-axis, y-axis, width, height
faces = trained_dataset.detectMultiScale(gray_img)
""" print(faces) -> return values of x-axis, y-axis, width, height """

# creating rectangle around the face
for x, y, w, h in faces:
cv2.rectangle(img, (x, y), (x+w, y+h), (0, 0, 255), 2)

# show image
cv2.imshow("Face Detected", img)
cv2.waitKey()

Comments

Popular posts from this blog

MOTION DETECTION AND TRACKING USING OPENCV AND PYTHON

BASIC HAND TRACKING USING PYTHON

PARANTHESIS CHECKER IMPLEMENTATION USING PYTHON - STACK APPLICATON👩‍💻👨‍💻