Esempio n. 1
0
    def test_track_getitem(self):
        # this is the same test as test_track_find, but using the get-item
        # accessor syntax
        t = Track()
        t.append(TrackState(0))
        t.append(TrackState(1))
        t.append(TrackState(5))
        t.append(TrackState(9))

        ts = t[0]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 0)

        ts = t[1]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 1)

        ts = t[5]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 5)

        ts = t[9]
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 9)

        nose.tools.assert_raises(IndexError, t.find_state, 10)
        t.append(TrackState(10))
        nose.tools.assert_is_not_none(t[10])
        nose.tools.assert_equal(t[10].frame_id, 10)
Esempio n. 2
0
    def test_track_find(self):
        t = Track()
        t.append(TrackState(0))
        t.append(TrackState(1))
        t.append(TrackState(5))
        t.append(TrackState(9))

        ts = t.find_state(0)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 0)

        ts = t.find_state(1)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 1)

        ts = t.find_state(5)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 5)

        ts = t.find_state(9)
        nose.tools.assert_is_not_none(ts)
        nose.tools.assert_equal(ts.frame_id, 9)

        nose.tools.assert_raises(IndexError, t.find_state, 10)
        t.append(TrackState(10))
        nose.tools.assert_is_not_none(t.find_state(10))
        nose.tools.assert_equal(t.find_state(10).frame_id, 10)
Esempio n. 3
0
    def test_ts_feat_desc(self):
        t = Track()

        f0 = Feature(mag=0)
        d0 = Descriptor(4)
        d0[:] = 0
        t.append(TrackState(0, f0, d0))

        f1 = Feature(mag=1)
        d1 = Descriptor(4)
        d1[:] = 1
        t.append(TrackState(1, f1, d1))

        nose.tools.assert_equal(t.size, 2)
        nose.tools.assert_equal(len(t), 2)
        ts0 = t.find_state(0)
        nose.tools.assert_equal(ts0.feature, f0)
        numpy.testing.assert_equal(ts0.descriptor, d0)

        ts1 = t.find_state(1)
        nose.tools.assert_equal(ts1.feature, f1)
        numpy.testing.assert_equal(ts1.descriptor, d1)

        # Delete local descriptor references, get track states and check
        # descriptor values manually
        del f0, f1, d0, d1, ts0, ts1
        # Now, only the track-state in C++ has feature/descriptor references
        numpy.testing.assert_equal(t.find_state(0).descriptor, [0, 0, 0, 0])
        numpy.testing.assert_equal(t.find_state(1).descriptor, [1, 1, 1, 1])
Esempio n. 4
0
    def test_iteration(self):
        t = Track()
        t.append(TrackState(0))
        t.append(TrackState(1))
        t.append(TrackState(5))
        t.append(TrackState(9))

        nose.tools.assert_equal([ts.frame_id for ts in t], [0, 1, 5, 9])
Esempio n. 5
0
 def test_all_frame_ids_multitrack(self):
     # Across multiple tracks
     n = 10
     t1 = Track(1)
     for i in range(0, n):
         t1.append(TrackState(i))
     t2 = Track(2)
     for i in range(n, n + 5):
         t2.append(TrackState(i))
     ts = TrackSet([t1, t2])
     nt.assert_equal(ts.all_frame_ids(), set(range(n + 5)))
Esempio n. 6
0
    def test_new_ts(self):
        TrackState(0)
        TrackState(23456)

        # With feat, desc, feat/desc
        f = Feature()
        d = Descriptor()
        TrackState(0, feature=f)
        TrackState(0, descriptor=d)
        TrackState(0, f, d)

        # Only integers
        nose.tools.assert_raises(ctypes.ArgumentError, TrackState, 1.2)
        nose.tools.assert_raises(ctypes.ArgumentError, TrackState, 'foo')
Esempio n. 7
0
    def test_desc(self):
        # Some random initialized descriptor
        d = Descriptor()
        d[:] = 1
        nose.tools.assert_equal(d.sum(), d.size)

        ts = TrackState(0, descriptor=d)
        numpy.testing.assert_equal(d, ts.descriptor)
Esempio n. 8
0
    def test_last_frame(self):
        # no tracks
        ts = TrackSet()
        nt.assert_equal(ts.last_frame(), 0)

        # one track
        t = Track(1)
        t.append(TrackState(1))
        t.append(TrackState(2))
        ts = TrackSet([t])
        nt.assert_equal(ts.last_frame(), 2)

        # two tracks
        t2 = Track(2)
        t2.append(TrackState(3))
        ts = TrackSet([t, t2])
        nt.assert_equal(ts.last_frame(), 3)
Esempio n. 9
0
    def test_all_frame_ids_single_track(self):
        # From a single track
        n = 10
        t = Track(1)
        for i in range(n):
            t.append(TrackState(i))
        ts = TrackSet([t])

        nt.assert_equal(ts.all_frame_ids(), set(range(10)))
Esempio n. 10
0
    def test_ts_append(self):
        t = Track()
        nose.tools.assert_equal(t.size, 0)
        nose.tools.assert_equal(len(t), 0)

        ts = TrackState(10)
        nose.tools.assert_true(t.append(ts))
        nose.tools.assert_equal(t.size, 1)
        nose.tools.assert_equal(len(t), 1)

        ts = TrackState(11)
        nose.tools.assert_true(t.append(ts))
        nose.tools.assert_equal(t.size, 2)
        nose.tools.assert_equal(len(t), 2)

        # Other properties that should not be different than default
        nose.tools.assert_equal(t.first_frame, 10)
        nose.tools.assert_equal(t.last_frame, 11)
        nose.tools.assert_false(t.is_empty)
Esempio n. 11
0
    def test_ts_append_outoforder(self):
        t = Track()
        nose.tools.assert_true(t.append(TrackState(10)))
        nose.tools.assert_false(t.append(TrackState(10)))
        nose.tools.assert_false(t.append(TrackState(9)))
        nose.tools.assert_false(t.append(TrackState(0)))
        nose.tools.assert_false(t.append(TrackState(-1)))

        nose.tools.assert_true(t.append(TrackState(11)))
        nose.tools.assert_false(t.append(TrackState(11)))

        # After all that there should only be two states in there for frames 10
        # and 11.
        nose.tools.assert_equal(t.size, 2)
        nose.tools.assert_equal(len(t), 2)
        nose.tools.assert_equal(t.all_frame_ids(), {10, 11})
Esempio n. 12
0
def projected_tracks(lmap, cmap):
    """
    Use the cameras to project the landmarks back into their images.
    :type lmap: LandmarkMap
    :type cmap: CameraMap
    """
    tracks = []

    cam_d = cmap.as_dict()
    landmark_d = lmap.as_dict()

    for lid, l in landmark_d.iteritems():
        t = Track(lid)
        tracks.append(t)

        # Sort camera iteration to make sure that we go in order of frame IDs
        for fid in sorted(cam_d):
            cam = cam_d[fid]
            f = Feature(cam.project(l.loc))
            t.append(TrackState(fid, f))

        assert t.size == len(cam_d)

    return TrackSet(tracks)
Esempio n. 13
0
    def test_frame_id(self):
        ts = TrackState(0)
        nose.tools.assert_equal(ts.frame_id, 0)

        ts = TrackState(14691234578)
        nose.tools.assert_equal(ts.frame_id, 14691234578)
Esempio n. 14
0
 def test_desc_empty(self):
     ts = TrackState(0)
     nose.tools.assert_is_none(ts.descriptor)
Esempio n. 15
0
 def test_new_ts(self):
     TrackState(0)
     TrackState(23456)
Esempio n. 16
0
 def test_feat(self):
     f = Feature()
     ts = TrackState(0, f)
     nose.tools.assert_equal(ts.feature, f)
Esempio n. 17
0
 def test_feat_empty(self):
     ts = TrackState(0)
     nose.tools.assert_is_none(ts.feature)