Spaces:
Sleeping
Sleeping
File size: 885 Bytes
1dd5b3e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
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}"
|