From 7c672b2aa95a5ecf493e699bd0f88a90dc619a4f Mon Sep 17 00:00:00 2001 From: gdamms Date: Tue, 25 Jun 2024 10:44:42 +0200 Subject: haar cascade --- utils.py | 32 ++++++++++++++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/utils.py b/utils.py index 509bd11..9935d16 100644 --- a/utils.py +++ b/utils.py @@ -1,6 +1,6 @@ import numpy as np import scipy.linalg -import matplotlib.pyplot as plt +import cv2 def fid(reals, fakes): @@ -77,4 +77,32 @@ def jsd(reals, fakes): hist_avg = (hist_real + hist_fake) / 2 - return 0.5 * (np.mean(np.log(hist_real / hist_avg)) + np.mean(np.log(hist_fake / hist_avg))) \ No newline at end of file + return 0.5 * (np.mean(np.log(hist_real / hist_avg)) + np.mean(np.log(hist_fake / hist_avg))) + + +def haar(image): + # Load the Haar cascade for face detection + face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') + + # Convert the image to grayscale + gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) + + # Perform face detection + faces = face_cascade.detectMultiScale(gray, scaleFactor=1.1, minNeighbors=4) + + # 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 result + cv2.imshow('Face Detection', image) + cv2.waitKey(0) + cv2.destroyAllWindows() + + +if __name__ == '__main__': + # Load the image + image = cv2.imread('data/edface/500/03120500_000.png') + + # Perform face detection + haar(image) \ No newline at end of file -- cgit v1.3.1