Created
February 16, 2021 13:25
-
-
Save j-adamczyk/bdf56466abcf3803216e4a814928de3d to your computer and use it in GitHub Desktop.
Face detection using Viola-Jones method
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import cv2 | |
import numpy as np | |
face_cascade = cv2.CascadeClassifier() | |
face_cascade.load("haarcascade_frontalface_alt.xml") | |
def viola_jones_detect(img: np.ndarray) -> np.ndarray: | |
frame_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) | |
frame_gray = cv2.equalizeHist(frame_gray) | |
faces = face_cascade.detectMultiScale(frame_gray) | |
for x, y, w, h in faces: | |
img = cv2.rectangle(img, (x, y), (x + w, y + h), (0, 255, 0), 2) | |
return img |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment