diff --git a/face_detector.py b/face_detector.py new file mode 100644 index 0000000..6d790f0 --- /dev/null +++ b/face_detector.py @@ -0,0 +1,17 @@ +import cv2 + +def detect_faces(image_path): + face_cascade = cv2.CascadeClassifier(cv2.data.haarcascades + 'haarcascade_frontalface_default.xml') + image = cv2.imread(image_path) + gray_image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY) + faces = face_cascade.detectMultiScale(gray_image, scaleFactor=1.1, minNeighbors=5) + + for (x, y, w, h) in faces: + cv2.rectangle(image, (x, y), (x + w, y + h), (255, 0, 0), 2) + + cv2.imshow('Detected Faces', image) + cv2.waitKey(0) + cv2.destroyAllWindows() + +if __name__ == "__main__": + detect_faces('path_to_your_image.jpg')