コード例 #1
0
ファイル: test_rotation.py プロジェクト: vanthaiunghoa/kwiver
    def test_interpolated_rotations(self):
        x = Rotation.from_axis_angle([1, 0, 0], 0)
        a = math.pi / 2
        y = Rotation.from_axis_angle([0, 1, 0], a)
        i_list = Rotation.interpolated_rotations(x, y, 3)
        nose.tools.assert_equal([i._ctype for i in i_list], ['d'] * 3)

        i0_e_axis, i0_e_angle = [0, 1, 0], a * 0.25
        i1_e_axis, i1_e_angle = [0, 1, 0], a * 0.50
        i2_e_axis, i2_e_angle = [0, 1, 0], a * 0.75

        numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 14)

        numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 14)

        numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 14)

        # Mixed types
        a = math.pi / 2
        x = Rotation.from_axis_angle([1, 0, 0], 0, 'f')
        y = Rotation.from_axis_angle([0, 1, 0], a)
        i_list = Rotation.interpolated_rotations(x, y, 3)
        nose.tools.assert_equal([i._ctype for i in i_list], ['f'] * 3)

        numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 6)

        numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 6)

        numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 6)
コード例 #2
0
ファイル: test_camera.py プロジェクト: Kitware/kwiver
 def test_translation_initialized(self):
     center = EigenArray.from_array([[1],[2],[3]])
     rotation = Rotation.from_axis_angle([0, 1, 0], math.pi / 2.)
     cam = Camera(center, rotation)
     numpy.testing.assert_array_equal(
         cam.translation,
         -(rotation * center.get_matrix())
     )
コード例 #3
0
ファイル: test_rotation.py プロジェクト: nagyist/kwiver
    def test_from_aa(self):
        # Axis should come out of rotation normalized
        angle = 0.8
        axis = numpy.array([[-3], [2], [1]])
        axis_norm = axis / numpy.linalg.norm(axis)

        r = Rotation.from_axis_angle(axis, angle)
        nose.tools.assert_equal(angle, r.angle())
        numpy.testing.assert_equal(axis_norm, r.axis())
コード例 #4
0
ファイル: test_rotation.py プロジェクト: Kitware/kwiver
    def test_from_aa(self):
        # Axis should come out of rotation normalized
        angle = 0.8
        axis = [-3,2,1]
        axis_norm = array_normalize(axis)

        r = Rotation.from_axis_angle(axis, angle)
        nose.tools.assert_equal(angle, r.angle())
        numpy.testing.assert_equal(axis_norm, r.axis())
コード例 #5
0
ファイル: test_rotation.py プロジェクト: vanthaiunghoa/kwiver
    def test_from_aa(self):
        # Axis should come out of rotation normalized
        angle = 0.8
        axis = [-3, 2, 1]
        axis_norm = array_normalize(axis)

        r = Rotation.from_axis_angle(axis, angle)
        nose.tools.assert_equal(angle, r.angle())
        numpy.testing.assert_equal(axis_norm, r.axis())
コード例 #6
0
ファイル: test_rotation.py プロジェクト: ALouis38/vital
    def test_from_aa(self):
        # Axis should come out of rotation normalized
        angle = 0.8
        axis = numpy.array([[-3],
                            [2],
                            [1]])
        axis_norm = axis / numpy.linalg.norm(axis)

        r = Rotation.from_axis_angle(axis, angle)
        nose.tools.assert_equal(angle, r.angle())
        numpy.testing.assert_equal(axis_norm, r.axis())
コード例 #7
0
ファイル: test_camera.py プロジェクト: nagyist/vital
    def test_equal(self):
        cam1 = Camera()
        cam2 = Camera()
        nose.tools.assert_equal(cam1, cam1)
        nose.tools.assert_equal(cam1, cam2)

        center = EigenArray.from_iterable([[1], [2], [3]])
        rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.)
        cam1 = Camera(center, rotation)
        cam2 = Camera(center, rotation)
        nose.tools.assert_equal(cam1, cam1)
        nose.tools.assert_equal(cam1, cam2)
コード例 #8
0
ファイル: test_camera.py プロジェクト: Kitware/kwiver
    def test_equal(self):
        cam1 = Camera()
        cam2 = Camera()
        nose.tools.assert_equal(cam1, cam1)
        nose.tools.assert_equal(cam1, cam2)

        center = EigenArray.from_array([[1],[2],[3]])
        rotation = Rotation.from_axis_angle([0, 1, 0], math.pi / 2.)
        cam1 = Camera(center, rotation)
        cam2 = Camera(center, rotation)
        nose.tools.assert_equal(cam1, cam1)
        nose.tools.assert_equal(cam1, cam2)
コード例 #9
0
ファイル: test_rotation.py プロジェクト: vanthaiunghoa/kwiver
    def test_interpolation(self):
        x_d = Rotation.from_axis_angle([1, 0, 0], 0, 'd')
        y_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'd')
        r_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'd')

        x_f = Rotation.from_axis_angle([1, 0, 0], 0, 'f')
        y_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'f')
        r_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'f')

        z_d = Rotation.interpolate(x_d, y_d, 0.5)
        z_f = Rotation.interpolate(x_f, y_f, 0.5)
        nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14)
        nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6)

        # Should auto-convert different y-type into x's type for computation.
        # Return should be of x's type.
        z_d = Rotation.interpolate(x_d, y_f, 0.5)
        nose.tools.assert_is(z_d._ctype, x_d._ctype)
        nose.tools.assert_is_not(z_d._ctype, y_f._ctype)
        nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14)

        z_f = Rotation.interpolate(x_f, y_d, 0.5)
        nose.tools.assert_is(z_f._ctype, x_f._ctype)
        nose.tools.assert_is_not(z_f._ctype, y_d._ctype)
        nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6)
コード例 #10
0
ファイル: test_rotation.py プロジェクト: Kitware/kwiver
    def test_interpolation(self):
        x_d = Rotation.from_axis_angle([1, 0, 0], 0, 'd')
        y_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'd')
        r_d = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'd')

        x_f = Rotation.from_axis_angle([1, 0, 0], 0, 'f')
        y_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 2, 'f')
        r_f = Rotation.from_axis_angle([0, 1, 0], math.pi / 4, 'f')

        z_d = Rotation.interpolate(x_d, y_d, 0.5)
        z_f = Rotation.interpolate(x_f, y_f, 0.5)
        nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14)
        nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6)

        # Should auto-convert different y-type into x's type for computation.
        # Return should be of x's type.
        z_d = Rotation.interpolate(x_d, y_f, 0.5)
        nose.tools.assert_is(z_d._ctype, x_d._ctype)
        nose.tools.assert_is_not(z_d._ctype, y_f._ctype)
        nose.tools.assert_almost_equal((z_d.inverse() * r_d).angle(), 0, 14)

        z_f = Rotation.interpolate(x_f, y_d, 0.5)
        nose.tools.assert_is(z_f._ctype, x_f._ctype)
        nose.tools.assert_is_not(z_f._ctype, y_d._ctype)
        nose.tools.assert_almost_equal((z_f.inverse() * r_f).angle(), 0, 6)
コード例 #11
0
ファイル: test_rotation.py プロジェクト: Kitware/kwiver
    def test_interpolated_rotations(self):
        x = Rotation.from_axis_angle([1, 0, 0], 0)
        a = math.pi / 2
        y = Rotation.from_axis_angle([0, 1, 0], a)
        i_list = Rotation.interpolated_rotations(x, y, 3)
        nose.tools.assert_equal([i._ctype for i in i_list],
                                ['d'] * 3)

        i0_e_axis, i0_e_angle = [0, 1, 0], a * 0.25
        i1_e_axis, i1_e_angle = [0, 1, 0], a * 0.50
        i2_e_axis, i2_e_angle = [0, 1, 0], a * 0.75

        numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 14)

        numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 14)

        numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 14)

        # Mixed types
        a = math.pi / 2
        x = Rotation.from_axis_angle([1, 0, 0], 0, 'f')
        y = Rotation.from_axis_angle([0, 1, 0], a)
        i_list = Rotation.interpolated_rotations(x, y, 3)
        nose.tools.assert_equal([i._ctype for i in i_list],
                                ['f'] * 3)

        numpy.testing.assert_almost_equal(i_list[0].axis(), i0_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[0].angle(), i0_e_angle, 6)

        numpy.testing.assert_almost_equal(i_list[1].axis(), i1_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[1].angle(), i1_e_angle, 6)

        numpy.testing.assert_almost_equal(i_list[2].axis(), i2_e_axis, 14)
        numpy.testing.assert_almost_equal(i_list[2].angle(), i2_e_angle, 6)
コード例 #12
0
ファイル: test_rotation.py プロジェクト: vanthaiunghoa/kwiver
    def test_rotation_vector(self):
        vec = [1, 0, 0]
        vec_expected = [0, 1, 0]

        r_axis = [0, 0, 1]
        r_angle = math.pi / 2.
        r = Rotation.from_axis_angle(r_axis, r_angle)
        vec_rotated = r.rotate_vector(vec)

        numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated)

        # should be able to multiply a rotation as a left-hand side arg with a
        # 3x1 vector as the right-hand side arg
        vec_rotated = r * vec
        numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated)
コード例 #13
0
ファイル: test_rotation.py プロジェクト: Kitware/kwiver
    def test_rotation_vector(self):
        vec = [1, 0, 0]
        vec_expected = [0, 1, 0]

        r_axis = [0, 0, 1]
        r_angle = math.pi / 2.
        r = Rotation.from_axis_angle(r_axis, r_angle)
        vec_rotated = r.rotate_vector(vec)

        numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated)

        # should be able to multiply a rotation as a left-hand side arg with a
        # 3x1 vector as the right-hand side arg
        vec_rotated = r * vec
        numpy.testing.assert_array_almost_equal(vec_expected, vec_rotated)
コード例 #14
0
ファイル: test_camera.py プロジェクト: nagyist/vital
    def test_to_from_string(self):
        cam = Camera()
        cam_s = cam.as_string()
        cam2 = Camera.from_string(cam_s)
        print "Default camera string:\n%s" % cam_s
        print "Default newcam string:\n%s" % cam2.as_string()
        nose.tools.assert_equal(cam, cam2)

        center = EigenArray.from_iterable([[1], [2], [3]])
        rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.)
        cam = Camera(center, rotation)
        cam_s = cam.as_string()
        cam2 = Camera.from_string(cam_s)
        print "Custom camera string:\n%s" % cam_s
        print "Custom newcam string:\n%s" % cam2.as_string()
        nose.tools.assert_equal(cam, cam2)
コード例 #15
0
ファイル: test_camera.py プロジェクト: ALouis38/vital
    def test_to_from_string(self):
        cam = Camera()
        cam_s = cam.as_string()
        cam2 = Camera.from_string(cam_s)
        print "Default camera string:\n%s" % cam_s
        print "Default newcam string:\n%s" % cam2.as_string()
        nose.tools.assert_equal(cam, cam2)

        center = EigenArray.from_iterable([[1],
                                           [2],
                                           [3]])
        rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.)
        cam = Camera(center, rotation)
        cam_s = cam.as_string()
        cam2 = Camera.from_string(cam_s)
        print "Custom camera string:\n%s" % cam_s
        print "Custom newcam string:\n%s" % cam2.as_string()
        nose.tools.assert_equal(cam, cam2)
コード例 #16
0
ファイル: test_camera.py プロジェクト: ALouis38/vital
 def test_rotation_initialized(self):
     r_expected = Rotation.from_axis_angle([[0],[1],[0]], math.pi / 8)
     cam = Camera(rotation=r_expected)
     nose.tools.assert_is_not(cam.rotation, r_expected)
     nose.tools.assert_equal(cam.rotation, r_expected)
コード例 #17
0
ファイル: test_camera.py プロジェクト: nagyist/vital
 def test_rotation_initialized(self):
     r_expected = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 8)
     cam = Camera(rotation=r_expected)
     nose.tools.assert_is_not(cam.rotation, r_expected)
     nose.tools.assert_equal(cam.rotation, r_expected)
コード例 #18
0
ファイル: test_camera.py プロジェクト: nagyist/vital
 def test_translation_initialized(self):
     center = EigenArray.from_iterable([[1], [2], [3]])
     rotation = Rotation.from_axis_angle([[0], [1], [0]], math.pi / 2.)
     cam = Camera(center, rotation)
     numpy.testing.assert_array_equal(cam.translation, -(rotation * center))
コード例 #19
0
ファイル: test_camera.py プロジェクト: vanthaiunghoa/kwiver
 def test_rotation_initialized(self):
     center = EigenArray.from_array([[1], [2], [3]])
     r_expected = Rotation.from_axis_angle([0, 1, 0], math.pi / 8)
     cam = Camera(center, r_expected)
     nose.tools.assert_is_not(cam.rotation, r_expected)
     nose.tools.assert_equal(cam.rotation, r_expected)
コード例 #20
0
ファイル: test_camera.py プロジェクト: Kitware/kwiver
 def test_rotation_initialized(self):
     center = EigenArray.from_array([[1],[2],[3]])
     r_expected = Rotation.from_axis_angle([0,1,0], math.pi / 8)
     cam = Camera(center, r_expected)
     nose.tools.assert_is_not(cam.rotation, r_expected)
     nose.tools.assert_equal(cam.rotation, r_expected)