コード例 #1
0
 def test_compose(self):
     expected = Pose3(self.pose.rotation(), Vector3(1, 5, 1))
     translate = Pose3(t=Vector3(0, 0, 4))  # translate Z axis, which is Y
     actual = self.pose.compose(translate)
     actual.assert_equal(expected)
     actual2 = self.pose * translate
     actual2.assert_equal(expected)
コード例 #2
0
    def example(cls):
        """Create a simple ProjectObjectDict."""

        pose1 = Pose3()
        pose2 = Pose3(t=Vector3(2, 2, 0))
        pose3 = Pose3(t=Vector3(4, 2, 0))

        # Be explicit about unicode literal in case this code is called from python 2
        data_path = parutil.get_dir_path(
            u"sumo/threedee/test_data")

        model1 = GltfModel.load_from_glb(os.path.join(data_path, "bed.glb"))
        model2 = GltfModel.load_from_glb(os.path.join(data_path, "bed.glb"))
        model3 = GltfModel.load_from_glb(os.path.join(data_path, "bed.glb"))

        obj1 = ProjectObject.gen_meshes_object(
            meshes=model1, id="1", pose=pose1, category="bed"
        )
        obj2 = ProjectObject.gen_meshes_object(
            meshes=model2, id="2", pose=pose2, category="chair"
        )
        obj3 = ProjectObject.gen_meshes_object(
            meshes=model3, id="3", pose=pose3, category="bed"
        )

        project_object_dict = ProjectObjectDict()
        project_object_dict[obj1.id] = obj1
        project_object_dict[obj2.id] = obj2
        project_object_dict[obj3.id] = obj3

        return project_object_dict
コード例 #3
0
    def test_from_gltf_model(self):
        """Verify bounding box computed from a GltfModel."""
        object = GltfModel.example()

        box = ComputeBbox().from_gltf_object(object)
        np.testing.assert_array_equal(box.min_corner, Vector3(-1, -1, -1))
        np.testing.assert_array_equal(box.max_corner, Vector3(1, 1, 1))
コード例 #4
0
    def test_mesh(self):
        box = Box3d(corner1=Vector3(0, 0, 0), corner2=Vector3(1, 1, 1))
        mesh = box.to_mesh()
        self.assertIsInstance(mesh, Mesh)
        self._check_mesh_helper(mesh)

        tex_mesh = box.to_textured_mesh(color=np.array([71, 57, 8], dtype=np.uint8))
        self.assertIsInstance(tex_mesh, TexturedMesh)
        self._check_mesh_helper(tex_mesh)
コード例 #5
0
    def test_unitize(self):
        v = unitize(Vector3(2, 2, 2))
        expected_v = Vector3(1, 1, 1) * (math.sqrt(3) / 3)
        np.testing.assert_array_almost_equal(v, expected_v)

        v = unitize(Vector3(100, 201, 50))
        self.assertEqual(np.linalg.norm(v), 1)

        v = unitize(Vector3(0, 0, 0))
        np.testing.assert_array_almost_equal(v, Vector3(0, 0, 0))
コード例 #6
0
 def test_register(self):
     ''' Test registering point clouds in different frames. '''
     t = Vector3(1, 1, 1)
     R = Rot3()
     T = Pose3(R, t).inverse()
     cloud = PointCloud(np.zeros((3, 1)))
     registred_cloud = PointCloud.register([(Pose3(), cloud), (T, cloud)])
     np.testing.assert_array_equal(
         registred_cloud.points(),
         np.column_stack([Vector3(0, 0, 0),
                          Vector3(-1.0, -1.0, -1.0)]))
コード例 #7
0
 def test_xml(self):
     """
     Test conversion to and from xml.  This is just a basic functionality
     test of a round trip from Box3d to xml and back.
     """
     box = Box3d(corner1=Vector3(1.5, 2.6, 3.7),
                 corner2=Vector3(5.1, 6.2, 7.9))
     box_xml = box.to_xml()
     assert (box_xml.tag == 'box3d')
     box_rt = Box3d.from_xml(box_xml)
     assert (box.almost_equal(box_rt))
コード例 #8
0
 def test_transform(self):
     cP = Vector3(0, 0, 5)
     wP = self.pose.transform_from(cP)
     np.testing.assert_array_equal(wP, Vector3(1, 6, 1))
     np.testing.assert_array_equal(self.pose.transform_to(wP), cP)
     np.testing.assert_array_equal(wP, self.pose * cP)
     w_points = np.stack([wP, wP], axis=1)
     c_points = np.stack([cP, cP], axis=1)
     np.testing.assert_array_equal(c_points,
                                   self.pose.transform_all_to(w_points))
     np.testing.assert_array_equal(w_points,
                                   self.pose.transform_all_from(c_points))
     np.testing.assert_array_equal(w_points, self.pose * c_points)
コード例 #9
0
 def test_random_points(self):
     """ Make two random points and verify the bounding box's corners
         are correct
     """
     corner1 = Vector3(-1, -2, -3)
     corner2 = Vector3(1, 2, 3)
     box = Box3d(corner1, corner2)
     corners = box.corners()
     corners_target = np.column_stack([[-1.0, -2.0, 3.0], [1.0, -2.0, 3.0],
                                       [1.0, 2.0, 3.0], [-1.0, 2.0, 3.0],
                                       [-1.0, -2.0, -3.0],
                                       [1.0, -2.0, -3.0], [1.0, 2.0, -3.0],
                                       [-1.0, 2.0, -3.0]])
     np.testing.assert_array_equal(corners, corners_target)
コード例 #10
0
 def test_unit_cube(self):
     """ Make two points inside a unit cube and verify the bounding box's
         corners are correct
     """
     corner1 = Vector3(0, 0, 0)
     corner2 = Vector3(1, 1, 1)
     box = Box3d(corner1, corner2)
     corners = box.corners()
     corners_target = np.column_stack([[0.0, 0.0, 1.0], [1.0, 0.0, 1.0],
                                       [1.0, 1.0, 1.0], [0.0, 1.0, 1.0],
                                       [0.0, 0.0, 0.0], [1.0, 0.0, 0.0],
                                       [1.0, 1.0, 0.0], [0.0, 1.0, 0.0]])
     np.testing.assert_array_almost_equal(corners, corners_target)
     np.testing.assert_array_almost_equal(box.min_corner, corner1)
     np.testing.assert_array_almost_equal(box.max_corner, corner2)
コード例 #11
0
 def test_transform_from(self):
     '''Test transform_from.'''
     t = Vector3(1, 1, 1)
     R = Rot3()
     T = Pose3(R, t).inverse()
     cloud = PointCloud(np.zeros((3, 1)))
     new_cloud = cloud.transform_from(T)
     np.testing.assert_array_equal(new_cloud.points(),
                                   [[-1.0], [-1.0], [-1.0]])
コード例 #12
0
 def test_update_textured_material(self):
     mesh = TexturedMesh.example()
     model = GltfModel.from_textured_mesh(mesh)
     self.assertEqual(model.num_images(), 2)
     uri = "Cube_BaseColor.png"
     base_dir = TEST_PATH
     material = {"color": Vector3(0, 0, 0), "uri": uri}
     model.update_materials(base_dir, [material])
     self.assertEqual(model.num_images(), 3)
コード例 #13
0
 def example(cls, id="1"):
     """Create a simple ProjectObject of project_type = meshes."""
     meshes = GltfModel.example()
     pose = Pose3(t=Vector3(1, 2, 3))
     symmetry = ObjectSymmetry.example()
     return cls.gen_meshes_object(id=id,
                                  pose=pose,
                                  category="chair",
                                  meshes=meshes,
                                  symmetry=symmetry,
                                  score=0.57)
コード例 #14
0
 def test_xml(self):
     """
     Test conversion to and from xml.  This is just a basic functionality
     test of a round trip from Pose3 to xml and back.
     """
     pose = Pose3(t=Vector3(1.5, 2.6, 3.7),
                  R=np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]]))
     pose_xml = pose.to_xml()
     self.assertEqual(pose_xml.tag, 'pose')
     pose_rt = Pose3.from_xml(pose_xml)
     pose.assert_almost_equal(pose_rt)
コード例 #15
0
 def test_unit_cube(self):
     """ Make three points inside a unit cube and verify the bounding box's
         corners are correct
     """
     point1 = Vector3(1, 0, 0)
     point2 = Vector3(0, 1, 0)
     point3 = Vector3(0, 0, 1)
     points = np.column_stack([point1, point2, point3])
     box = ComputeBbox().from_point_cloud(points)
     corners = box.corners()
     corners_target = np.column_stack([
         [0.0, 0.0, 1.0],
         [1.0, 0.0, 1.0],
         [1.0, 1.0, 1.0],
         [0.0, 1.0, 1.0],
         [0.0, 0.0, 0.0],
         [1.0, 0.0, 0.0],
         [1.0, 1.0, 0.0],
         [0.0, 1.0, 0.0],
     ])
     np.testing.assert_array_equal(corners, corners_target)
コード例 #16
0
    def test_surreal(self):
        """Read from a Surreal json file."""

        # Expected pose.
        expected_pose = Pose3(t=Vector3(1, 2, 3))

        # Read json file
        path_to_json_linear = os.path.join(PATH, 'pose3_test.json')
        data = json.load(open(path_to_json_linear))
        pose = Pose3.from_surreal(data['T_cr'])

        # Test pose
        pose.assert_almost_equal(expected_pose)
コード例 #17
0
    def test_equal(self):
        """
        Test == operator.
        """

        box1 = Box3d(Vector3(1, 2, 3), Vector3(0, 4, 2))
        box2 = Box3d(Vector3(1, 2, 3), Vector3(0, 4, 2))
        box3 = Box3d(Vector3(1, 2.1, 3), Vector3(0, 4, 2))

        assert (box1 == box2)
        assert (box2 != box3)
コード例 #18
0
    def test_almost_equal(self):
        """
        Test almost_equal function.
        """

        box1 = Box3d(Vector3(1.000000001, 2.000000001, 3.000001),
                     Vector3(-0.00000001, 3.99999999, 2.000001))
        box2 = Box3d(Vector3(1.0, 2, 3), Vector3(0, 4, 2))

        box3 = Box3d(Vector3(-1, -1, -1), Vector3(1, 1, 1))

        self.assertTrue(box1.almost_equal(box2, atol=0.01))
        self.assertFalse(box1.almost_equal(box2, atol=0.000000000001))
        self.assertFalse(box1.almost_equal(box3))
コード例 #19
0
ファイル: sumo-api-example.py プロジェクト: kuixu/Linux
from sumo.base.colored_category import ColoredCategory
import matplotlib.pyplot as plt

CSV_PATH = parutil.get_file_path(
    '/mnt/lustre/sunjiankai/Dataset/sample_data/metadata/categories.csv')
colored_category = ColoredCategory(CSV_PATH)
print('colored_category.category_id_to_rgb(133):\n',
      colored_category.category_id_to_rgb(133))
print('colored_category.category_name_to_rgb(\'shoes\'):\n',
      colored_category.category_name_to_rgb('shoes'))
print('colored_category.LUT:\n', colored_category.LUT)
lut = colored_category.LUT
print('lut.shape[0]: ', lut.shape[0], 'lut.shape[1]: ', lut.shape[1])

from sumo.base.vector import Vector2, Vector2f, Vector3, Vector3f, on_left, unitize
print('unitize(Vector3(100, 201, 50)): ', unitize(Vector3(100, 201, 50)))

# rot3_tests
from sumo.geometry.rot3 import Rot3, ENU_R_CAMERA
import numpy as np
wRc = np.transpose(np.array([[1, 0, 0], [0, 0, -1], [0, 1, 0]], dtype=float))
rot = Rot3(wRc)
print(rot.matrix())

# MultiImageTiff
from sumo.geometry.inverse_depth import depth_image_of_inverse_depth_map
from sumo.images.multi_image_tiff import MultiImageTiff, MultiImagePageType

tiff_path = parutil.get_file_path(
    '/mnt/lustre/sunjiankai/Dataset/sample_data/sumo-input/sumo-input.tif')
multi = MultiImageTiff.load(tiff_path)
コード例 #20
0
 def test_update_material(self):
     mesh = TexturedMesh.example()
     model = GltfModel.from_textured_mesh(mesh)
     material = {"color": Vector3(0.5, 0.5, 0.5), "uri": ""}
     model.update_materials("", [material])
コード例 #21
0
ファイル: rot3_tests.py プロジェクト: qicny/sumo-challenge
 def test_rotate(self):
     cP = Vector3(0, 0, 5)
     wP = self.rot.rotate(cP)
     np.testing.assert_array_equal(wP, Vector3(0, 5, 0))
     np.testing.assert_array_equal(self.rot * cP, Vector3(0, 5, 0))
     np.testing.assert_array_equal(self.rot.unrotate(wP), cP)
コード例 #22
0
ファイル: rot3_tests.py プロジェクト: qicny/sumo-challenge
This source code is licensed under the MIT license found in the
LICENSE file in the root directory of this source tree.


Rot3 unit tests.
'''

import unittest
import numpy as np
import xml.etree.cElementTree as ET

from sumo.base.vector import Vector3
from sumo.geometry.rot3 import Rot3, ENU_R_CAMERA

UNIT_X = Vector3(1, 0, 0)
UNIT_Y = Vector3(0, 1, 0)
UNIT_Z = Vector3(0, 0, 1)


class TestRot3(unittest.TestCase):
    def setUp(self):
        # Camera with z-axis looking at world y-axis
        wRc = np.transpose(
            np.array([[1, 0, 0], [0, 0, -1], [0, 1, 0]], dtype=float)
        )
        self.rot = Rot3(wRc)

    def test_RollPitchYaw(self):
        roll, pitch, yaw = 0.1, 0.2, 0.3
        np.testing.assert_array_equal(
コード例 #23
0
 def test_Vector3(self):
     vector = Vector3(1, 2, 3)
     self.assertEqual(vector.shape, (3, ))
     self.assertEqual(vector.dtype, np.float64)
コード例 #24
0
 def test_on_left(self):
     N = Vector3(0, 0, 1)
     p = Vector3(0, 2, 0)
     a = Vector3(0, 0, 0)
     b = Vector3(1, 0, 0)
     self.assertTrue(on_left(N, p, a, b))
コード例 #25
0
 def test_merge(self):
     box1 = Box3d(corner1=Vector3f(0, 1, 0), corner2=Vector3f(1, 2, 1))
     box2 = Box3d(corner1=Vector3f(1, 0, 0), corner2=Vector3f(2, 1, 2))
     merged = Box3d.merge([box1, box2])
     np.testing.assert_array_equal(merged.min_corner, Vector3(0, 0, 0))
     np.testing.assert_array_equal(merged.max_corner, Vector3(2, 2, 2))
コード例 #26
0
 def setUp(self):
     # Camera with z-axis looking at world y-axis
     wRc = np.transpose(
         np.array([[1, 0, 0], [0, 0, -1], [0, 1, 0]], dtype=float))
     t = Vector3(1, 1, 1)
     self.pose = Pose3(wRc, t)
コード例 #27
0
 def test_ENU_camera(self):
     Pose3.ENU_camera(position=Vector3(1, 1, 1)).assert_equal(self.pose)