Exemple #1
0
    def test_get_typename(self):
        # Returns C++ std::type_info.name values
        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.type_name, 'd')

        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.type_name, 'f')
Exemple #2
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])
Exemple #3
0
    def test_get_color(self):
        dflt_color = RGBColor()
        f = Feature()
        nose.tools.assert_equal(f.color, dflt_color)

        c = RGBColor(5, 32, 10)
        f = Feature(rgb_color=c)
        nose.tools.assert_equal(f.color, c)
Exemple #4
0
 def feature(self):
     f_ptr = self._call_cfunc("vital_track_state_feature",
                              [self.C_TYPE_PTR], [self],
                              Feature.c_ptr_type())
     # f_ptr may be null
     if f_ptr:
         return Feature(from_cptr=f_ptr)
     else:
         return None
Exemple #5
0
    def test_get_location(self):
        f = Feature()
        numpy.testing.assert_almost_equal(f.location, [[0], [0]])

        expected = [[12.3], [643]]
        f = Feature(loc=expected)
        numpy.testing.assert_almost_equal(f.location, expected)
        # iterable form
        f = Feature(loc=(12.3, 643))
        numpy.testing.assert_almost_equal(f.location, expected)
Exemple #6
0
    def test_set_color(self):
        expected = RGBColor(4, 20, 0)

        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)

        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)
Exemple #7
0
    def test_set_scale(self):
        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.scale, 1)  # default value
        expected = random.random()
        f.scale = expected
        nose.tools.assert_almost_equal(f.scale, expected, 16)

        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.scale, 1)  # default value
        expected = random.random()
        f.scale = expected
        nose.tools.assert_almost_equal(f.scale, expected, 6)
Exemple #8
0
    def test_set_angle(self):
        f = Feature(ctype='d')
        nose.tools.assert_equal(f.angle, 0)  # default value
        expected = random.random()
        f.angle = expected
        nose.tools.assert_almost_equal(f.angle, expected, 16)

        f = Feature(ctype='f')
        nose.tools.assert_equal(f.angle, 0)  # default value
        expected = random.random()
        f.angle = expected
        nose.tools.assert_almost_equal(f.angle, expected, 6)
Exemple #9
0
    def test_set_color(self):
        expected = RGBColor(4, 20, 0)

        f = Feature(ctype='d')
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)

        f = Feature(ctype='f')
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)
Exemple #10
0
    def test_set_location(self):
        f = Feature(ctype='d')
        expected = [random.random(),
                    random.random()]
        f.location = expected
        # making sure that we went through the setter, and not just setting the
        # exact value to the property
        numpy.testing.assert_almost_equal(f.location, expected, 16)

        f = Feature(ctype='f')
        expected = [random.random(),
                    random.random()]
        f.location = expected
        numpy.testing.assert_almost_equal(f.location, expected, 6)
Exemple #11
0
    def test_set_location(self):
        f = Feature(ctype=ctypes.c_double)
        expected = [[random.random()],
                    [random.random()]]
        f.location = expected
        # making sure that we went through the setter, and not just setting the
        # exact value to the property
        nose.tools.assert_is_instance(f.location, EigenArray)
        numpy.testing.assert_almost_equal(f.location, expected, 16)

        f = Feature(ctype=ctypes.c_float)
        expected = [[random.random()],
                    [random.random()]]
        f.location = expected
        nose.tools.assert_is_instance(f.location, EigenArray)
        numpy.testing.assert_almost_equal(f.location, expected, 6)
Exemple #12
0
    def test_set_covar(self):
        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2],
                    [3, 4]]
        c = Covariance(2, ctypes.c_double, expected)
        f.covariance = c
        nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        nose.tools.assert_equal(f.covariance, c)

        # And for floats...
        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2],
                    [3, 4]]
        c = Covariance(2, ctypes.c_float, expected)
        f.covariance = c
        nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        nose.tools.assert_equal(f.covariance, c)
Exemple #13
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')
Exemple #14
0
    def _new(self, frame, feature, descriptor):
        """
        :param feature: Optional Feature instance associated with this state.
        :type feature: vital.types.Feature

        :param descriptor: Optional Descriptor instance associated with this
            state.
        :type descriptor: vital.types.Descriptor
        """
        return self._call_cfunc(
            "vital_feature_track_state_new",
            [ctypes.c_int64, Feature.c_ptr_type(), Descriptor.c_ptr_type()],
            [frame, feature, descriptor],
            self.C_TYPE_PTR
        )
Exemple #15
0
    def test_set_angle(self):
        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.angle, 0)  # default value
        expected = random.random()
        f.angle = expected
        nose.tools.assert_almost_equal(f.angle, expected, 16)

        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.angle, 0)  # default value
        expected = random.random()
        f.angle = expected
        nose.tools.assert_almost_equal(f.angle, expected, 6)
Exemple #16
0
    def test_set_color(self):
        expected = RGBColor(4, 20, 0)

        f = Feature(ctype='d')
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)

        f = Feature(ctype='f')
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)
Exemple #17
0
    def test_set_location(self):
        f = Feature(ctype='d')
        expected = [random.random(), random.random()]
        f.location = expected
        # making sure that we went through the setter, and not just setting the
        # exact value to the property
        numpy.testing.assert_almost_equal(f.location, expected, 16)

        f = Feature(ctype='f')
        expected = [random.random(), random.random()]
        f.location = expected
        numpy.testing.assert_almost_equal(f.location, expected, 6)
Exemple #18
0
    def test_set_scale(self):
        f = Feature(ctype='d')
        nose.tools.assert_equal(f.scale, 1)  # default value
        expected = random.random()
        f.scale = expected
        nose.tools.assert_almost_equal(f.scale, expected, 16)

        f = Feature(ctype='f')
        nose.tools.assert_equal(f.scale, 1)  # default value
        expected = random.random()
        f.scale = expected
        nose.tools.assert_almost_equal(f.scale, expected, 6)
Exemple #19
0
    def test_set_color(self):
        expected = RGBColor(4, 20, 0)

        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)

        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.color, RGBColor())
        f.color = expected
        nose.tools.assert_equal(f.color, expected)
Exemple #20
0
    def test_set_location(self):
        f = Feature(ctype=ctypes.c_double)
        expected = [[random.random()], [random.random()]]
        f.location = expected
        # making sure that we went through the setter, and not just setting the
        # exact value to the property
        nose.tools.assert_is_instance(f.location, EigenArray)
        numpy.testing.assert_almost_equal(f.location, expected, 16)

        f = Feature(ctype=ctypes.c_float)
        expected = [[random.random()], [random.random()]]
        f.location = expected
        nose.tools.assert_is_instance(f.location, EigenArray)
        numpy.testing.assert_almost_equal(f.location, expected, 6)
Exemple #21
0
    def test_set_covar(self):
        f = Feature(ctype='d')
        #nose.tools.assert_equal(f.covariance, Covariance.new_covar())

        expected = [[1, 2], [3, 4]]
        c = Covariance.from_matrix(2, 'd', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        #nose.tools.assert_equal(f.covariance, c)

        # And for floats...
        f = Feature(ctype='f')
        #nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2], [3, 4]]
        c = Covariance.from_matrix(2, 'f', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
Exemple #22
0
    def test_set_covar(self):
        f = Feature(ctype=ctypes.c_double)
        nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2], [3, 4]]
        c = Covariance(2, ctypes.c_double, expected)
        f.covariance = c
        nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        nose.tools.assert_equal(f.covariance, c)

        # And for floats...
        f = Feature(ctype=ctypes.c_float)
        nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2], [3, 4]]
        c = Covariance(2, ctypes.c_float, expected)
        f.covariance = c
        nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        nose.tools.assert_equal(f.covariance, c)
Exemple #23
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)
Exemple #24
0
    def test_set_covar(self):
        f = Feature(ctype='d')
        #nose.tools.assert_equal(f.covariance, Covariance.new_covar())

        expected = [[1, 2],
                    [3, 4]]
        c = Covariance.from_matrix(2, 'd', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
        #nose.tools.assert_equal(f.covariance, c)

        # And for floats...
        f = Feature(ctype='f')
        #nose.tools.assert_equal(f.covariance, Covariance())

        expected = [[1, 2],
                    [3, 4]]
        c = Covariance.from_matrix(2, 'f', expected)
        f.covariance = c
        #nose.tools.assert_equal(f.covariance, c)
        # Should also work if we just give it the raw iterable
        f.covariance = expected
Exemple #25
0
 def test_get_covar(self):
     dflt_covar = Covariance.new_covar(2)
     f = Feature()
Exemple #26
0
 def test_get_covar(self):
     dflt_covar = Covariance(2)
     f = Feature()
     nose.tools.assert_equal(f.covariance, dflt_covar)
Exemple #27
0
    def test_get_angle(self):
        f = Feature()
        nose.tools.assert_equal(f.angle, 0)

        f = Feature(angle=1.1)
        nose.tools.assert_equal(f.angle, 1.1)
Exemple #28
0
    def test_get_scale(self):
        f = Feature()
        nose.tools.assert_equal(f.scale, 1)

        f = Feature(scale=2.1)
        nose.tools.assert_equal(f.scale, 2.1)
Exemple #29
0
    def test_get_mag(self):
        f = Feature()
        nose.tools.assert_equal(f.magnitude, 0)

        f = Feature(mag=1.1)
        nose.tools.assert_equal(f.magnitude, 1.1)
Exemple #30
0
 def test_new(self):
     f1 = Feature()
     f2 = Feature([1, 1], 1, 2, 1)
Exemple #31
0
 def test_feat(self):
     f = Feature()
     ts = TrackState(0, f)
     nose.tools.assert_equal(ts.feature, f)