| | """Utility module for face detection."""
|
| |
|
| | import cv2
|
| | import numpy as np
|
| | from typing import List, Tuple
|
| | from PIL import Image
|
| |
|
| |
|
| | def detect_faces(image: Image.Image) -> List[Tuple[int, int, int, int]]:
|
| | """
|
| | Detect faces in an image.
|
| |
|
| | Args:
|
| | image: PIL Image
|
| |
|
| | Returns:
|
| | List of face bounding boxes (x, y, w, h)
|
| | """
|
| |
|
| | img_array = np.array(image)
|
| | gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| |
|
| |
|
| | face_cascade = cv2.CascadeClassifier(
|
| | cv2.data.haarcascades + 'haarcascade_frontalface_default.xml'
|
| | )
|
| |
|
| |
|
| | faces = face_cascade.detectMultiScale(
|
| | gray,
|
| | scaleFactor=1.1,
|
| | minNeighbors=5,
|
| | minSize=(30, 30)
|
| | )
|
| |
|
| | return faces.tolist() if len(faces) > 0 else []
|
| |
|