示例#1
0
def test_happy_2():
    filename = get_absolute_path(current_directory + "test_face_emotion_extr" +
                                 "action_data/happy2.png")
    img = cv2.imread(filename)
    face_data = classify_faces([img])
    assert len(face_data[0]) == 7
    assert face_data[0][3] > 0.5
示例#2
0
def test_neutral_1():
    filename = get_absolute_path(current_directory +
                                 "test_face_emotion_extra" +
                                 "ction_data/neutral1.png")
    img = cv2.imread(filename)
    face_data = classify_faces([img])
    assert len(face_data[0]) == 7
    assert face_data[0][6] > 0.5
示例#3
0
def classify_video(video_path: str, time_range=None):
    """Classifies the emotions in a given video

    Parameters
    ----------
    video_path:str
        The path of the video that is to be analyzed

    time_range:Dict[str:int]
        The time range to analyze in as a dictionary of type string:int

    Returns
    -------
    string
        Returns a csv of the emotions in the emotion set
    """

    faces = analyze_video(video_path, time_range)
    angry_sum =\
        disgust_sum =\
        fear_sum =\
        happy_sum =\
        sad_sum =\
        surprise_sum =\
        neutral_sum = 0.0
    number_of_faces = 0
    realFaces = []
    for _, value in faces.items():
        for face in value:
            realFaces.append(face)
    faces = classify_faces(realFaces)

    for emotions in faces:
        angry_sum += emotions[0]
        disgust_sum += emotions[1]
        fear_sum += emotions[2]
        happy_sum += emotions[3]
        sad_sum += emotions[4]
        surprise_sum += emotions[5]
        neutral_sum += emotions[6]
        number_of_faces = number_of_faces + 1

    return {
        "angry": angry_sum / number_of_faces,
        "disgust": disgust_sum / number_of_faces,
        "fear": fear_sum / number_of_faces,
        "happy": happy_sum / number_of_faces,
        "sad": sad_sum / number_of_faces,
        "surprise": surprise_sum / number_of_faces,
        "neutral": neutral_sum / number_of_faces
    }
示例#4
0
def test_Many_Faces():
    face_list = []

    filename1 = get_absolute_path(current_directory +
                                  "test_face_emotion_extr" +
                                  "action_data/happy1.png")
    filename2 = get_absolute_path(current_directory +
                                  "test_face_emotion_extr" +
                                  "action_data/happy2.png")
    filename3 = get_absolute_path(current_directory +
                                  "test_face_emotion_extr" +
                                  "action_data/happy3.png")

    img1 = cv2.imread(filename1)
    img2 = cv2.imread(filename2)
    img3 = cv2.imread(filename3)
    face_list.append(img1)
    face_list.append(img2)
    face_list.append(img3)
    list_with_faces = classify_faces(face_list)
    assert list_with_faces[0][3] > 0.5
    assert list_with_faces[1][3] > 0.5
    assert list_with_faces[2][3] > 0.3