fix: update face detected at same time as emotions

ref: N25B-395
This commit is contained in:
2026-01-30 20:33:16 +01:00
parent 1f799299b9
commit 3a5c27e01f

View File

@@ -90,6 +90,9 @@ class VisualEmotionRecognitionAgent(BaseAgent):
# Tracks counts of detected emotions per face index
face_stats = defaultdict(Counter)
# How many times a face has been detected
face_detection_yes_no = [0, 0]
prev_dominant_emotions = set()
while self._running:
@@ -109,13 +112,11 @@ class VisualEmotionRecognitionAgent(BaseAgent):
# Get the dominant emotion from each face
current_emotions = self.emotion_recognizer.sorted_dominant_emotions(frame)
# Form (or unform) face_detected belief
if len(current_emotions) == 0 and self._face_detected:
self._face_detected = False
await self._inform_face_detected()
elif len(current_emotions) > 0 and not self._face_detected:
self._face_detected = True
await self._inform_face_detected()
# Update face face_detection_yes_no
if len(current_emotions) > 0:
face_detection_yes_no[0] += 1
else:
face_detection_yes_no[1] += 1
# Update emotion counts for each detected face
for i, emotion in enumerate(current_emotions):
@@ -132,6 +133,18 @@ class VisualEmotionRecognitionAgent(BaseAgent):
dominant_emotion = counter.most_common(1)[0][0]
window_dominant_emotions.add(dominant_emotion)
if (
face_detection_yes_no[0] > face_detection_yes_no[1]
and not self._face_detected
):
self._face_detected = True
await self._inform_face_detected()
elif (
face_detection_yes_no[0] <= face_detection_yes_no[1] and self._face_detected
):
self._face_detected = False
await self._inform_face_detected()
await self.update_emotions(prev_dominant_emotions, window_dominant_emotions)
prev_dominant_emotions = window_dominant_emotions
face_stats.clear()