Spaces:
Configuration error
Configuration error
Create utils.py
Browse files
utils.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import cv2
|
| 2 |
+
import mediapipe as mp
|
| 3 |
+
import numpy as np
|
| 4 |
+
|
| 5 |
+
mp_face_detection = mp.solutions.face_detection
|
| 6 |
+
|
| 7 |
+
def extract_features(image_path):
|
| 8 |
+
"""Extract face shape, skin tone, and size from an image."""
|
| 9 |
+
image = cv2.imread(image_path)
|
| 10 |
+
image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
| 11 |
+
|
| 12 |
+
# Detect face (simplified example)
|
| 13 |
+
with mp_face_detection.FaceDetection(min_detection_confidence=0.5) as face_detector:
|
| 14 |
+
results = face_detector.process(image_rgb)
|
| 15 |
+
if not results.detections:
|
| 16 |
+
return None, None, None
|
| 17 |
+
|
| 18 |
+
# Mock logic (replace with actual calculations)
|
| 19 |
+
face_shape = "Oval" # Use landmarks to classify shape
|
| 20 |
+
skin_tone = "Medium" # Estimate from cheek region
|
| 21 |
+
face_size = "Medium" # Measure bounding box
|
| 22 |
+
|
| 23 |
+
return face_shape, skin_tone, face_size
|