Example #1
0
    def test_analyze_video(self):

        base_path = os.path.join("..", "test_files", "video_indexing")

        resource_path = os.path.join(base_path, "fic.02.mpg")

        resource_id = "fic.02.mpg"

        params = {c.VIDEO_INDEXING_PATH_KEY: base_path}

        fe = VideoFaceExtractor(resource_path, resource_id, params)

        fe.analyze_video()
Example #2
0
    def test_merge_consecutive_segments(self):

        params = {c.MIN_SEGMENT_DURATION_KEY: 1}

        fe = VideoFaceExtractor("path", "id", params)

        segments = [
            {
                c.SEGMENT_START_KEY: 0,
                c.SEGMENT_DURATION_KEY: 10000,
                c.SEGMENT_COUNTER_KEY: 0,
                c.FRAMES_KEY: [0, 1, 2, 3],
            },
            {c.SEGMENT_START_KEY: 10500, c.SEGMENT_DURATION_KEY: 4500, c.SEGMENT_COUNTER_KEY: 1, c.FRAMES_KEY: [4, 5]},
            {c.SEGMENT_START_KEY: 15900, c.SEGMENT_DURATION_KEY: 14100, c.SEGMENT_COUNTER_KEY: 2, c.FRAMES_KEY: [6]},
            {
                c.SEGMENT_START_KEY: 32000,
                c.SEGMENT_DURATION_KEY: 8000,
                c.SEGMENT_COUNTER_KEY: 3,
                c.FRAMES_KEY: [7, 8, 9],
            },
            {
                c.SEGMENT_START_KEY: 45000,
                c.SEGMENT_DURATION_KEY: 5000,
                c.SEGMENT_COUNTER_KEY: 4,
                c.FRAMES_KEY: [10, 11, 12, 13, 14, 15],
            },
            {
                c.SEGMENT_START_KEY: 50000,
                c.SEGMENT_DURATION_KEY: 5000,
                c.SEGMENT_COUNTER_KEY: 5,
                c.FRAMES_KEY: [16, 17],
            },
        ]

        fe.recognized_faces = [{c.ASSIGNED_LABEL_KEY: 1, c.SEGMENTS_KEY: segments}]

        fe.merge_consecutive_segments()

        segments = fe.recognized_faces[0][c.SEGMENTS_KEY]

        self.assertEqual(len(segments), 3)

        self.assertEqual(segments[0][c.SEGMENT_DURATION_KEY], 30000)

        self.assertEqual(len(segments[0][c.FRAMES_KEY]), 7)
Example #3
0
    def test_delete_analysis_results(self):

        self.test_analyze_video()

        base_path = os.path.join("..", "test_files", "video_indexing")

        resource_path = os.path.join(base_path, "fic.02.mpg")

        resource_id = "fic.02"

        params = {c.VIDEO_INDEXING_PATH_KEY: base_path}

        fe = VideoFaceExtractor(resource_path, resource_id, params)

        fe.delete_analysis_results()

        exists = os.path.exists(fe.video_path)

        self.assertFalse(exists)
Example #4
0
    def test_add_keyfaces_to_models(self):

        self.test_analyze_video()

        base_path = os.path.join("..", "test_files", "video_indexing")

        resource_path = os.path.join(base_path, "fic.02.mpg")

        resource_id = "fic.02"

        params = {c.VIDEO_INDEXING_PATH_KEY: base_path}

        fe = VideoFaceExtractor(resource_path, resource_id, params)

        people = fe.get_people()

        for person_dict in people:
            label = person_dict[c.PERSON_COUNTER_KEY]

            tag = str(label)

            fe.add_keyface_to_models(label, label, tag)
Example #5
0
    def test_merge_labels(self):

        fe = VideoFaceExtractor("path", "id")

        segments_1 = ["1a", "1b", "1c"]
        segments_2 = ["2a", "2b", "2c"]
        segments_3 = ["3a", "3b", "3c"]

        fe.recognized_faces = [
            {c.ASSIGNED_LABEL_KEY: 1, c.SEGMENTS_KEY: segments_1},
            {c.ASSIGNED_LABEL_KEY: 2, c.SEGMENTS_KEY: segments_2},
            {c.ASSIGNED_LABEL_KEY: 1, c.SEGMENTS_KEY: segments_1},
            {c.ASSIGNED_LABEL_KEY: 3, c.SEGMENTS_KEY: segments_3},
            {c.ASSIGNED_LABEL_KEY: 1, c.SEGMENTS_KEY: segments_1},
            {c.ASSIGNED_LABEL_KEY: 2, c.SEGMENTS_KEY: segments_2},
        ]

        fe.merge_labels()

        self.assertEqual(len(fe.recognized_faces), 3)

        self.assertEqual(len(fe.recognized_faces[0][c.SEGMENTS_KEY]), 9)
Example #6
0
    def test_track_people_in_video(self):

        base_path = os.path.join("..", "test_files", "video_indexing")

        resource_path = os.path.join(base_path, "fic.02.mpg")

        resource_id = "fic.02.mpg"

        params = {c.VIDEO_INDEXING_PATH_KEY: base_path}

        fe = VideoFaceExtractor(resource_path, resource_id, params)

        fe.fps = 25.0

        fe.cluster_faces_in_video()

        fe.track_people_in_video()

        fe.save_rec_people()