From 355adf839cae1c3409db428ce32118d4913e5370 Mon Sep 17 00:00:00 2001 From: Harsimran Singh Dalal Date: Mon, 28 Oct 2024 21:03:53 +0530 Subject: [PATCH] Create detect_faces.py --- detect_faces.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 detect_faces.py diff --git a/detect_faces.py b/detect_faces.py new file mode 100644 index 0000000..4789ac1 --- /dev/null +++ b/detect_faces.py @@ -0,0 +1,19 @@ +import os +from PIL import Image + +def detect_faces(image_path): + """Detect faces in the given image path.""" + # Validate input + if not os.path.exists(image_path): + raise FileNotFoundError(f"The file {image_path} does not exist.") + if not image_path.lower().endswith(('.png', '.jpg', '.jpeg')): + raise ValueError("Unsupported image format. Please use .png, .jpg, or .jpeg files.") + + try: + image = Image.open(image_path) + except IOError: + raise ValueError("The image file is corrupted or cannot be opened.") + + # Face detection logic here... + faces = [] # Replace with actual face detection logic + return faces