emotional-analysis2 / more robust
logu29's picture
Create more robust
1dd5b3e verified
raw
history blame contribute delete
885 Bytes
import cv2
import os
from deepface import DeepFace
def analyze_emotion(video_path):
# Check if the file exists
if not os.path.isfile(video_path):
return "Error: File not found."
try:
# Open the video file
cap = cv2.VideoCapture(video_path)
# Check if the video file opened successfully
if not cap.isOpened():
return "Error: Could not open video file."
# Process frames from the video
while cap.isOpened():
ret, frame = cap.read()
if not ret:
break
# Perform emotion analysis
result = DeepFace.analyze(frame, actions=['emotion'])
print(result)
cap.release()
return "Video processed successfully."
except Exception as e:
return f"Error processing video file: {e}"