LittleMonkeyLab commited on
Commit
4b259f1
·
verified ·
1 Parent(s): 1f80bce

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -14
app.py CHANGED
@@ -106,21 +106,22 @@ def analyze_expression(image):
106
 
107
  # Analyze Action Units
108
  aus = {
109
- 'AU01': measurements['inner_brow_raise'] > 0.15, # Inner Brow Raiser
110
- 'AU02': measurements['outer_brow_raise'] > 0.15, # Outer Brow Raiser
111
- 'AU04': measurements['brow_furrow'] < 0.2, # Brow Lowerer
112
- 'AU05': measurements['eye_opening'] > 0.12, # Upper Lid Raiser
113
- 'AU12': measurements['smile_width'] > 0.45, # Lip Corner Puller
114
- 'AU25': measurements['mouth_opening'] > 0.1, # Lips Part
115
- 'AU26': measurements['mouth_opening'] > 0.2 # Jaw Drop
116
  }
117
 
118
- # Emotion classification based on AUs
119
  emotions = {
120
- "Happy": (aus['AU12'] and measurements['lip_corner_height'] < 0),
121
- "Sad": (not aus['AU12'] and measurements['lip_corner_height'] > 0 and (aus['AU01'] or aus['AU04'])),
122
- "Surprised": (aus['AU01'] and aus['AU02'] and (aus['AU25'] or aus['AU26'])),
123
- "Neutral": not any([aus['AU01'], aus['AU02'], aus['AU04'], aus['AU12'], aus['AU26']])
 
124
  }
125
 
126
  # Create visualization
@@ -136,13 +137,15 @@ def analyze_expression(image):
136
  'jaw': (255, 128, 0) # Orange
137
  }
138
 
139
- # Draw landmarks with feature-specific colors
140
  for feature, points_list in FACIAL_LANDMARKS.items():
141
  color = colors.get(feature.split('_')[0], (0, 255, 0))
142
  for point_idx in points_list:
143
  pos = (int(landmarks.landmark[point_idx].x * w),
144
  int(landmarks.landmark[point_idx].y * h))
145
- cv2.circle(viz_image, pos, 2, color, -1)
 
 
146
 
147
  # Add emotion text
148
  detected_emotions = [emotion for emotion, is_present in emotions.items() if is_present]
 
106
 
107
  # Analyze Action Units
108
  aus = {
109
+ 'AU01': measurements['inner_brow_raise'] > 0.12, # Inner Brow Raiser - more sensitive
110
+ 'AU02': measurements['outer_brow_raise'] > 0.12, # Outer Brow Raiser - more sensitive
111
+ 'AU04': measurements['brow_furrow'] < 0.25, # Brow Lowerer - more lenient
112
+ 'AU05': measurements['eye_opening'] > 0.1, # Upper Lid Raiser - more sensitive
113
+ 'AU12': measurements['smile_width'] > 0.4, # Lip Corner Puller - more sensitive
114
+ 'AU25': measurements['mouth_opening'] > 0.08, # Lips Part - more sensitive
115
+ 'AU26': measurements['mouth_opening'] > 0.15 # Jaw Drop - more sensitive
116
  }
117
 
118
+ # Emotion classification based on AUs - more lenient conditions
119
  emotions = {
120
+ "Happy": (aus['AU12'] or measurements['lip_corner_height'] < -0.02),
121
+ "Sad": (measurements['lip_corner_height'] > 0.02 and (aus['AU01'] or aus['AU04'])),
122
+ "Surprised": ((aus['AU01'] or aus['AU02']) and (aus['AU25'] or aus['AU26'])),
123
+ "Neutral": not any([aus['AU01'], aus['AU02'], aus['AU04'], aus['AU12'], aus['AU26']]) and
124
+ abs(measurements['lip_corner_height']) < 0.02
125
  }
126
 
127
  # Create visualization
 
137
  'jaw': (255, 128, 0) # Orange
138
  }
139
 
140
+ # Draw landmarks with feature-specific colors - made more visible
141
  for feature, points_list in FACIAL_LANDMARKS.items():
142
  color = colors.get(feature.split('_')[0], (0, 255, 0))
143
  for point_idx in points_list:
144
  pos = (int(landmarks.landmark[point_idx].x * w),
145
  int(landmarks.landmark[point_idx].y * h))
146
+ # Larger circles with white outline for visibility
147
+ cv2.circle(viz_image, pos, 4, (255, 255, 255), -1) # White background
148
+ cv2.circle(viz_image, pos, 3, color, -1) # Colored center
149
 
150
  # Add emotion text
151
  detected_emotions = [emotion for emotion, is_present in emotions.items() if is_present]