Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_video(self):
detector = FER()
video = Video("tests/woman2.mp4")
raw_data = video.analyze(detector, display=False)
assert isinstance(raw_data, list)
# Convert to pandas for analysis
df = video.to_pandas(raw_data)
assert sum(df.neutral[:5] > 0.5) == 5, f"Expected neutral > 0.5, got {df.neutral[:5]}"
assert isinstance(df, pd.DataFrame)
assert "angry" in df
df = video.get_first_face(df)
assert isinstance(df, pd.DataFrame)
df = video.get_emotions(df)
assert isinstance(df, pd.DataFrame)
import matplotlib
if os.name == 'posix' and "DISPLAY" not in os.environ:
matplotlib.use("Agg")
import matplotlib.pyplot as plt
from fer import FER
from fer import Video
if __name__ == "__main__":
try:
videofile = sys.argv[1]
except:
videofile = "test.mp4"
detector = FER(mtcnn=True)
video = Video(videofile)
# Output list of dictionaries
raw_data = video.analyze(detector, display=False)
# Convert to pandas for analysis
df = video.to_pandas(raw_data)
df = video.get_first_face(df)
df = video.get_emotions(df)
# Plot emotions
df.plot()
plt.show()