How to use the fer.FER function in fer

To help you get started, we’ve selected a few fer examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github justinshenk / fer / tests / test_fer.py View on Github external
def setUpClass(cls):
        global detector, mtcnn_detector
        detector = FER()
        mtcnn_detector = FER(mtcnn=True)
github justinshenk / fer / tests / test_fer.py View on Github external
def setUpClass(cls):
        global detector, mtcnn_detector
        detector = FER()
        mtcnn_detector = FER(mtcnn=True)
github justinshenk / fer / tests / test_fer.py View on Github external
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)
github justinshenk / fer / video-example.py View on Github external
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()
github justinshenk / fer / example.py View on Github external
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import cv2

from fer import FER

detector = FER(mtcnn=True) # or with mtcnn=False for Haar Cascade Classifier

image = cv2.imread("justin.jpg")
result = detector.detect_emotions(image)

# Result is an array with all the bounding boxes detected. We know that for 'justin.jpg' there is only one.
bounding_box = result[0]["box"]
emotions = result[0]["emotions"]

cv2.rectangle(
    image,
    (bounding_box[0], bounding_box[1]),
    (bounding_box[0] + bounding_box[2], bounding_box[1] + bounding_box[3]),
    (0, 155, 255),
    2,
)

fer

Facial expression recognition from images

MIT
Latest version published 11 months ago

Package Health Score

59 / 100
Full package analysis

Similar packages