fix: update face detected at same time as emotions
ref: N25B-395
This commit is contained in:
@@ -90,6 +90,9 @@ class VisualEmotionRecognitionAgent(BaseAgent):
|
|||||||
# Tracks counts of detected emotions per face index
|
# Tracks counts of detected emotions per face index
|
||||||
face_stats = defaultdict(Counter)
|
face_stats = defaultdict(Counter)
|
||||||
|
|
||||||
|
# How many times a face has been detected
|
||||||
|
face_detection_yes_no = [0, 0]
|
||||||
|
|
||||||
prev_dominant_emotions = set()
|
prev_dominant_emotions = set()
|
||||||
|
|
||||||
while self._running:
|
while self._running:
|
||||||
@@ -109,13 +112,11 @@ class VisualEmotionRecognitionAgent(BaseAgent):
|
|||||||
# Get the dominant emotion from each face
|
# Get the dominant emotion from each face
|
||||||
current_emotions = self.emotion_recognizer.sorted_dominant_emotions(frame)
|
current_emotions = self.emotion_recognizer.sorted_dominant_emotions(frame)
|
||||||
|
|
||||||
# Form (or unform) face_detected belief
|
# Update face face_detection_yes_no
|
||||||
if len(current_emotions) == 0 and self._face_detected:
|
if len(current_emotions) > 0:
|
||||||
self._face_detected = False
|
face_detection_yes_no[0] += 1
|
||||||
await self._inform_face_detected()
|
else:
|
||||||
elif len(current_emotions) > 0 and not self._face_detected:
|
face_detection_yes_no[1] += 1
|
||||||
self._face_detected = True
|
|
||||||
await self._inform_face_detected()
|
|
||||||
|
|
||||||
# Update emotion counts for each detected face
|
# Update emotion counts for each detected face
|
||||||
for i, emotion in enumerate(current_emotions):
|
for i, emotion in enumerate(current_emotions):
|
||||||
@@ -132,6 +133,18 @@ class VisualEmotionRecognitionAgent(BaseAgent):
|
|||||||
dominant_emotion = counter.most_common(1)[0][0]
|
dominant_emotion = counter.most_common(1)[0][0]
|
||||||
window_dominant_emotions.add(dominant_emotion)
|
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)
|
await self.update_emotions(prev_dominant_emotions, window_dominant_emotions)
|
||||||
prev_dominant_emotions = window_dominant_emotions
|
prev_dominant_emotions = window_dominant_emotions
|
||||||
face_stats.clear()
|
face_stats.clear()
|
||||||
|
|||||||
Reference in New Issue
Block a user