test_utils.py 1.18 KB
Newer Older
Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
1
2
from bob.io.base.test_utils import datafile
import numpy as np
3
4
5
6
7
import bob.bio.video

regenerate_refs = False


Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
8
9
def test_video_as_array():
    path = datafile("testvideo.avi", "bob.bio.video.test")
10

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
11
12
13
    video = bob.bio.video.VideoAsArray(path, selection_style="all")
    assert len(video) == 83, len(video)
    assert video.indices == range(83), video.indices
14

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
15
16
17
    video = bob.bio.video.VideoAsArray(path, selection_style="spread", max_number_of_frames=3)
    assert len(video) == 3, len(video)
    assert video.indices == [13, 41, 69], video.indices
18
19


Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
20
21
def test_video_like_container():
    path = datafile("testvideo.avi", "bob.bio.video.test")
22

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
23
24
    video = bob.bio.video.VideoAsArray(path, selection_style="spread", max_number_of_frames=3)
    container = bob.bio.video.VideoLikeContainer(video, video.indices)
25

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
26
    container_path = datafile("video_like.hdf5", "bob.bio.video.test")
27

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
28
29
    if regenerate_refs:
        container.save(container_path)
30

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
31
    loaded_container = bob.bio.video.VideoLikeContainer.load(container_path)
32

Amir MOHAMMADI's avatar
Amir MOHAMMADI committed
33
34
    np.testing.assert_equal(np.array(container.data), np.array(loaded_container.data))
    np.testing.assert_equal(np.array(container.indices), np.array(loaded_container.indices))