def test_bbb_repo_iter_frames_filtered(tmpdir):
    repo = Repository(str(tmpdir.join('frames_from_to_filtered')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    timestamps = [f[0].timestamp for f in repo.iter_frames(begin, end)]
    selected_timestamps = set(np.random.choice(timestamps, size=5, replace=False))

    class TimestepFilter():
        def __init__(self, timesteps):
            self.timesteps = timesteps

        def __call__(self, frame):
            return frame.timestamp in self.timesteps

    filtered_frames = list(repo.iter_frames(begin, end,
                                            frame_filter=TimestepFilter(selected_timestamps)))
    filtered_timestamps = set([f[0].timestamp for f in filtered_frames])

    assert(filtered_timestamps == selected_timestamps)
Esempio n. 2
0
def test_bbb_iter_frames_from_to(tmpdir):
    """Tests that only frames in given range are iterated."""
    repo = Repository(str(tmpdir.join('frames_from_to')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    def check_tstamp_invariant(begin, end):
        """Helper to check if begin <= tstamp < end is true for all frames."""
        for frame, fc in repo.iter_frames(begin, end):
            # frame container invariant
            assert begin < fc.toTimestamp
            assert fc.fromTimestamp < end
            # frame invariant
            assert begin <= frame.timestamp < end

    # repo_start < start < end < repo_end
    check_tstamp_invariant(repo_start + 10, repo_end - 10)
    # start < repo_start < end < repo_end
    check_tstamp_invariant(repo_start - 10, repo_end - 10)
    # start < end < repo_start < repo_end
    check_tstamp_invariant(repo_start - 20, repo_start - 10)
    # repo_start < start < repo_end < end
    check_tstamp_invariant(repo_start + 10, repo_end + 10)
    # repo_start < repo_end < start < end
    check_tstamp_invariant(repo_end + 10, repo_end + 20)

    # check whole length
    all_frames = [f for f, _ in repo.iter_frames()]
    assert len(all_frames) == nFrames
    # check with begin = None
    skip_end = [f for f, _ in repo.iter_frames(end=repo_end - span)]
    assert len(skip_end) == nFrames - span
    # check with end = None
    skip_start = [f for f, _ in repo.iter_frames(begin=span)]
    assert len(skip_start) == nFrames - span
def test_bbb_iter_frames_from_to(tmpdir):
    """Tests that only frames in given range are iterated."""
    repo = Repository(str(tmpdir.join('frames_from_to')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    def check_tstamp_invariant(begin, end):
        """Helper to check if begin <= tstamp < end is true for all frames."""
        for frame, fc in repo.iter_frames(begin, end):
            # frame container invariant
            assert begin < fc.toTimestamp
            assert fc.fromTimestamp < end
            # frame invariant
            assert begin <= frame.timestamp < end

    # repo_start < start < end < repo_end
    check_tstamp_invariant(repo_start + 10, repo_end - 10)
    # start < repo_start < end < repo_end
    check_tstamp_invariant(repo_start - 10, repo_end - 10)
    # start < end < repo_start < repo_end
    check_tstamp_invariant(repo_start - 20, repo_start - 10)
    # repo_start < start < repo_end < end
    check_tstamp_invariant(repo_start + 10, repo_end + 10)
    # repo_start < repo_end < start < end
    check_tstamp_invariant(repo_end + 10, repo_end + 20)

    # check whole length
    all_frames = [f for f, _ in repo.iter_frames()]
    assert len(all_frames) == nFrames
    # check with begin = None
    skip_end = [f for f, _ in repo.iter_frames(end=repo_end - span)]
    assert len(skip_end) == nFrames - span
    # check with end = None
    skip_start = [f for f, _ in repo.iter_frames(begin=span)]
    assert len(skip_start) == nFrames - span
Esempio n. 4
0
def test_bbb_iter_small_frame_window(tmpdir):
    """Tests that iter_frame returns frames if time window is small."""
    repo = Repository(str(tmpdir.join('frames_from_to_small_window')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    begin = 1
    end = 10
    fnames = list(repo.iter_frames(begin, end))
    assert (len(fnames) > 0)

    begin = 1001
    end = 1011
    fnames = list(repo.iter_fnames(begin, end))
    assert (len(fnames) > 0)
def test_bbb_iter_small_frame_window(tmpdir):
    """Tests that iter_frame returns frames if time window is small."""
    repo = Repository(str(tmpdir.join('frames_from_to_small_window')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    begin = 1
    end = 10
    fnames = list(repo.iter_frames(begin, end))
    assert(len(fnames) > 0)

    begin = 1001
    end = 1011
    fnames = list(repo.iter_fnames(begin, end))
    assert(len(fnames) > 0)
Esempio n. 6
0
def test_bbb_repo_iter_frames_filtered(tmpdir):
    repo = Repository(str(tmpdir.join('frames_from_to_filtered')))
    repo_start = 0
    nFC = 10
    span = 1000
    nFrames = nFC * span
    repo_end = repo_start + nFrames
    begin_end_cam_id = [(ts, ts + span, 0)
                        for ts in range(repo_start, repo_end, span)]
    for begin, end, cam_id in begin_end_cam_id:
        fc = build_frame_container(begin, end, cam_id)
        fc.init('frames', span)
        for i, tstamp in enumerate(range(begin, end)):
            frame = fc.frames[i]
            frame.id = tstamp
            frame.timestamp = tstamp
        repo.add(fc)

    timestamps = [f[0].timestamp for f in repo.iter_frames(begin, end)]
    selected_timestamps = set(
        np.random.choice(timestamps, size=5, replace=False))

    class TimestepFilter():
        def __init__(self, timesteps):
            self.timesteps = timesteps

        def __call__(self, frame):
            return frame.timestamp in self.timesteps

    filtered_frames = list(
        repo.iter_frames(begin,
                         end,
                         frame_filter=TimestepFilter(selected_timestamps)))
    filtered_timestamps = set([f[0].timestamp for f in filtered_frames])

    assert (filtered_timestamps == selected_timestamps)
Esempio n. 7
0
def getDF(path, b, e, camID):
    repo = Repository(path)

    tpls = []
    myid = 0

    for frame, fc in repo.iter_frames(begin=b, end=e, cam=camID):
        for d in frame.detectionsUnion.detectionsDP:
            d = Detection10(d.idx, d.xpos, d.ypos, d.radius, d.zRotation,
                            list(d.decodedId), myid, frame.timestamp, fc.camId,
                            fc.id, frame.id)
            tpls.append(d)
        myid += 1

    df = DataFrame(tpls)
    return df