Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -12,9 +12,29 @@ face_mesh = mp_face_mesh.FaceMesh(static_image_mode=True, max_num_faces=1, refin
|
|
| 12 |
|
| 13 |
def extract_features(image, landmarks):
|
| 14 |
mean_intensity = np.mean(image)
|
|
|
|
|
|
|
| 15 |
bbox_width = max(pt.x for pt in landmarks) - min(pt.x for pt in landmarks)
|
| 16 |
bbox_height = max(pt.y for pt in landmarks) - min(pt.y for pt in landmarks)
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
def train_model(output_range):
|
| 20 |
X = [[random.uniform(0.2, 0.5), random.uniform(0.05, 0.2), random.uniform(0.05, 0.2)] for _ in range(100)]
|
|
|
|
| 12 |
|
| 13 |
def extract_features(image, landmarks):
|
| 14 |
mean_intensity = np.mean(image)
|
| 15 |
+
h, w, _ = image.shape
|
| 16 |
+
|
| 17 |
bbox_width = max(pt.x for pt in landmarks) - min(pt.x for pt in landmarks)
|
| 18 |
bbox_height = max(pt.y for pt in landmarks) - min(pt.y for pt in landmarks)
|
| 19 |
+
|
| 20 |
+
# Compute facial region ratios (eye distance, nose length, jaw width, etc.)
|
| 21 |
+
def dist(p1, p2):
|
| 22 |
+
return ((p1.x - p2.x)**2 + (p1.y - p2.y)**2) ** 0.5
|
| 23 |
+
|
| 24 |
+
eye_dist = dist(landmarks[33], landmarks[263]) # between left and right eye
|
| 25 |
+
nose_len = dist(landmarks[1], landmarks[2]) + dist(landmarks[2], landmarks[98]) # bridge + tip
|
| 26 |
+
jaw_width = dist(landmarks[234], landmarks[454])
|
| 27 |
+
|
| 28 |
+
# Skin tone analysis from cheeks
|
| 29 |
+
left_cheek = landmarks[234]
|
| 30 |
+
right_cheek = landmarks[454]
|
| 31 |
+
cx1, cy1 = int(left_cheek.x * w), int(left_cheek.y * h)
|
| 32 |
+
cx2, cy2 = int(right_cheek.x * w), int(right_cheek.y * h)
|
| 33 |
+
skin_tone1 = np.mean(image[cy1-5:cy1+5, cx1-5:cx1+5]) if 5 <= cy1 < h-5 and 5 <= cx1 < w-5 else 0
|
| 34 |
+
skin_tone2 = np.mean(image[cy2-5:cy2+5, cx2-5:cx2+5]) if 5 <= cy2 < h-5 and 5 <= cx2 < w-5 else 0
|
| 35 |
+
avg_skin_tone = (skin_tone1 + skin_tone2) / 2
|
| 36 |
+
|
| 37 |
+
return [mean_intensity, bbox_width, bbox_height, eye_dist, nose_len, jaw_width, avg_skin_tone]
|
| 38 |
|
| 39 |
def train_model(output_range):
|
| 40 |
X = [[random.uniform(0.2, 0.5), random.uniform(0.05, 0.2), random.uniform(0.05, 0.2)] for _ in range(100)]
|