SuriRaja commited on
Commit
39eef5a
·
verified ·
1 Parent(s): edb3de6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -16
app.py CHANGED
@@ -12,22 +12,16 @@ 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
- h, w, _ = image.shape
16
- bbox_width = max(pt.x for pt in landmarks) - min(pt.x for pt in landmarks)
17
- bbox_height = max(pt.y for pt in landmarks) - min(pt.y for pt in landmarks)
18
- def dist(p1, p2):
19
- return ((p1.x - p2.x)**2 + (p1.y - p2.y)**2) ** 0.5
20
- eye_dist = dist(landmarks[33], landmarks[263])
21
- nose_len = dist(landmarks[1], landmarks[2]) + dist(landmarks[2], landmarks[98])
22
- jaw_width = dist(landmarks[234], landmarks[454])
23
- left_cheek = landmarks[234]
24
- right_cheek = landmarks[454]
25
- cx1, cy1 = int(left_cheek.x * w), int(left_cheek.y * h)
26
- cx2, cy2 = int(right_cheek.x * w), int(right_cheek.y * h)
27
- 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
28
- 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
29
- avg_skin_tone = (skin_tone1 + skin_tone2) / 2
30
- return [mean_intensity, bbox_width, bbox_height, eye_dist, nose_len, jaw_width, avg_skin_tone]
31
 
32
  def train_model(output_range):
33
  X = [[random.uniform(0.2, 0.5), random.uniform(0.05, 0.2), random.uniform(0.05, 0.2),
 
12
 
13
  def extract_features(image, landmarks):
14
  mean_intensity = np.mean(image)
15
+ red_channel = image[:, :, 2]
16
+ green_channel = image[:, :, 1]
17
+ blue_channel = image[:, :, 0]
18
+ total_pixels = image.shape[0] * image.shape[1]
19
+
20
+ red_percent = 100 * np.sum(red_channel > green_channel) / total_pixels
21
+ green_percent = 100 * np.sum(green_channel > red_channel) / total_pixels
22
+ blue_percent = 100 * np.sum(blue_channel > red_channel) / total_pixels
23
+
24
+ return [red_percent, green_percent, blue_percent]
 
 
 
 
 
 
25
 
26
  def train_model(output_range):
27
  X = [[random.uniform(0.2, 0.5), random.uniform(0.05, 0.2), random.uniform(0.05, 0.2),