I am using the DeepFace library to analyze emotions in a video. Here is the relevant code:
import cv2
from deepface import DeepFace
cap = cv2.VideoCapture("video.mp4")
prev_emotion = None
prev_time = 0
while True:
ret, frame = cap.read()
if not ret:
break
# Analyze emotions in the frame
result = DeepFace.analyze(frame, actions=['emotion'], enforce_detection=False)
# Get the dominant emotion
dominant_emotion = result[0]['dominant_emotion']
# Get the current time
current_time = cap.get(cv2.CAP_PROP_POS_MSEC) / 1000
# Check if the emotion has changed
if dominant_emotion != prev_emotion:
# Check if this is the first emotion or not
if prev_emotion is not None:
print(f"{current_time:.2f} seconds: Emotion changed from {prev_emotion} to {dominant_emotion}")
# Update the previous emotion and time
prev_emotion = dominant_emotion
prev_time = current_time
cap.release()
When I run this code, it displays a progress bar showing the emotion detection progress for each frame.
Sample output for a frame:
Action: emotion: 100%|██████████| 1/1 [00:00<00:00, 18.19it/s]
I would like to disable this progress bar as it is not necessary for my use case.
Is there a way to disable the emotion detection progress bar in the DeepFace library? If so, how can I do it?
Set silent argument of analyze function to True as mentioned in its docstring.
DeepFace.analyze("img.jpg", actions = ["emotion"], silent = True)