Пример #1
0
 def setUp(self):
     self.track_state = TrackState(15)
     self.track = Track(23)
     self.track.append(TrackState(1))
     self.track.append(self.track_state)
     self._track_arr = [Track(15), Track(1),
                                 Track(150), Track(9),
                                 self.track]
Пример #2
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)))
Пример #3
0
    def test_initial_id(self):
        t = Track()
        nose.tools.assert_equal(t.id, 0)

        t = Track(0)
        nose.tools.assert_equal(t.id, 0)

        t = Track(-1)
        nose.tools.assert_equal(t.id, -1)

        t = Track(15)
        nose.tools.assert_equal(t.id, 15)
Пример #4
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)
Пример #5
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)
Пример #6
0
    def test_first_frame(self):
        # no tracks
        ts = TrackSet()
        nt.assert_equal(ts.first_frame(), 0)

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

        # two tracks
        t2 = Track(2)
        t2.append(TrackState(3))
        ts = TrackSet([t, t2])
        nt.assert_equal(ts.first_frame(), 1)
Пример #7
0
 def _create_object_track_set(self):
     bbox = BoundingBox(10, 10, 20, 20)
     dot = DetectedObjectType("test", 0.4)
     do = DetectedObject(bbox, 0.4, dot)
     track = Track()
     for i in range(10):
         track.append(ObjectTrackState(i, i, do))
     return ObjectTrackSet([track])
Пример #8
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])
Пример #9
0
    def test_set_id(self):
        t = Track()
        nose.tools.assert_equal(t.id, 0)

        t.id = 2
        nose.tools.assert_equal(t.id, 2)

        t.id = 1345634
        nose.tools.assert_equal(t.id, 1345634)
Пример #10
0
    def test_tracklist_accessor(self):
        n = 10
        tracks = [Track(i) for i in range(n)]
        ts = TrackSet(tracks)
        ts_tracks = ts.tracks()

        nt.assert_equal(len(ts_tracks), n)
        for i, t in enumerate(ts_tracks):
            nt.assert_equal(t.id, i)
Пример #11
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)))
Пример #12
0
def ts2ot_list(track_set):
    ot_list = [Track(id=t.track_id) for t in track_set]

    for idx, t in enumerate(track_set):
        ot = ot_list[idx]
        for ti in t:
            ot_state = ObjectTrackState(ti.sys_frame_id, ti.sys_frame_time,
                                        ti.detected_object)
            if not ot.append(ot_state):
                print('Error: Cannot add ObjectTrackState')
    return ot_list
Пример #13
0
def to_ObjectTrackSet(tracks):
    """Create an ObjectTrackSet from a dict whose keys are track IDs
    and values are lists of pairs of Kwiver timestamps and Kwiver DetectedObjects"""
    # Modeled after similar code in srnn_tracker.py
    result = []
    for tid, states in tracks.items():
        t = Track(id=tid)
        for ts, do in states:
            ots = ObjectTrackState(ts.get_frame(), ts.get_time_usec(), do)
            if not t.append(ots):
                raise ValueError("Unsorted input to to_ObjectTrackSet")
        result.append(t)
    return ObjectTrackSet(result)
Пример #14
0
 def _create_track(self):
     """
     Helper function to create a track
     :return: Track with 10 object track state. Every track state has same
                 detected object however the fram number and time varies from
                 [0, 10)
     """
     bbox = BoundingBox(10, 10, 20, 20)
     cm = ClassMap("test", 0.4)
     do = DetectedObject(bbox, 0.4, cm)
     track = Track()
     for i in range(10):
         track.append(ObjectTrackState(i, i, do))
     return track
Пример #15
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})
Пример #16
0
 def setUp(self):
     bbox = BoundingBox(10, 10, 20, 20)
     dot = DetectedObjectType("test", 0.4)
     do = DetectedObject(bbox, 0.4, dot)
     track = Track()
     for i in range(10):
         track.append(ObjectTrackState(i, i, do))
     self.track_ = track
     self.time_1 = Timestamp()
     self.time_1.set_time_seconds(1234)
     self.time_2 = Timestamp()
     self.time_2.set_time_seconds(4321)
     self.obj_ts = ObjectTrackSet([self.track_])
     self.act_type = ActivityType("self_act", 0.87)
     self.act = Activity(1, "self_act", 0.87, self.act_type, self.time_1,
                         self.time_2, self.obj_ts)
Пример #17
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)
Пример #18
0
 def test_id(self):
     a = self.act
     self.assertEqual(a.id, 1)
     a.id = 10
     self.assertEqual(a.id, 10)
     self.assertEqual(a.label, "self_act")
     a.label = "second_act"
     self.assertEqual(a.label, "second_act")
     self.assertEqual(a.activity_type.score("self_act"), 0.87)
     a.activity_type = ActivityType()
     self.assertEqual(a.confidence, 0.87)
     a.confidence = 1
     self.assertEqual(a.confidence, 1)
     self.assertEqual(a.start_time.get_time_seconds(), 1234)
     tmp_time = Timestamp().set_time_seconds(1237)
     a.start_time = tmp_time
     self.assertEqual(a.start_time.get_time_seconds(), 1237)
     self.assertEqual(a.end_time.get_time_seconds(), 4321)
     tmp_time = Timestamp()
     tmp_time.set_time_seconds(4322)
     a.end_time = tmp_time
     self.assertEqual(a.end_time.get_time_seconds(), 4322)
     self.assertEqual(a.participants.all_frame_ids(), set(range(10)))
     bbox = BoundingBox(10, 10, 20, 20)
     dot = DetectedObjectType("test", 0.4)
     do = DetectedObject(bbox, 0.4, dot)
     track = Track()
     for i in range(5):
         track.append(ObjectTrackState(i, i, do))
     new_t = track
     new_ots = ObjectTrackSet([new_t])
     a.participants = new_ots
     self.assertEqual(a.participants.all_frame_ids(), set(range(5)))
     self.assertEqual(a.duration[0].get_time_seconds(),
                      a.start_time.get_time_seconds())
     self.assertEqual(a.duration[1].get_time_seconds(),
                      a.end_time.get_time_seconds())
Пример #19
0
def subset_tracks(trackset, keep_fraction=0.75):
    """
    randomly drop a fraction of the track states per track in the given set,
    creating and returning new tracks in a new track-set.

    :type trackset: TrackSet
    :type keep_fraction: float
    """
    log = logging.getLogger(__name__)

    new_tracks = []
    for t in trackset.tracks():
        nt = Track(t.id)

        msg = 'track %d:' % t.id,
        for ts in t:
            if np.random.rand() < keep_fraction:
                nt.append(ts)
                msg += '.',
            else:
                msg += 'X',
        log.info(' '.join(msg))
        new_tracks.append(nt)
    return TrackSet(new_tracks)
Пример #20
0
 def test_initial_size(self):
     t = Track()
     nose.tools.assert_equal(t.size, 0)
     nose.tools.assert_equal(len(t), 0)
Пример #21
0
 def test_new(self):
     t = Track()
Пример #22
0
 def test_new_nonempty(self):
     n = 10
     tracks = [Track(i) for i in range(n)]
     ts = TrackSet(tracks)
     nt.assert_equal(len(ts), n)
     nt.assert_equal(ts.size(), n)
Пример #23
0
 def test_initial_is_empty(self):
     t = Track()
     nose.tools.assert_true(t.is_empty)
Пример #24
0
 def test_get_track_missing(self):
     # test failure to get track from set when set does have contents, but
     # TID is not present
     ts = TrackSet([Track(0), Track(1), Track(3)])
     nt.assert_raises(IndexError, ts.get_track, 2)
Пример #25
0
 def test_initial_firstlast_frame(self):
     t = Track()
     nose.tools.assert_equal(t.first_frame, 0)
     nose.tools.assert_equal(t.last_frame, 0)
Пример #26
0
 def test_initial_all_frame_ids(self):
     t = Track()
     s = t.all_frame_ids()
     nose.tools.assert_equal(len(s), 0)
Пример #27
0
def create_track():
    track = Track()
    track.append(create_track_state())
    return track
Пример #28
0
 def test_get_track_single(self):
     # get track when only track
     t = Track(0)
     ts = TrackSet([t])
     u = ts.get_track(0)