Beispiel #1
0
    def test_orthographic(self):
        cameras = OrthographicCameras()
        P = cameras.get_projection_transform()

        vertices = torch.randn([3, 4, 3], dtype=torch.float32)
        projected_verts = vertices.clone()
        v1 = P.transform_points(vertices)
        v2 = orthographic_project_naive(vertices)

        self.assertClose(v1[..., :2], v2[..., :2])
        self.assertClose(v1, projected_verts)
Beispiel #2
0
 def test_orthographic_kwargs(self):
     cameras = OrthographicCameras(focal_length=5.0,
                                   principal_point=((2.5, 2.5), ))
     P = cameras.get_projection_transform(focal_length=2.0,
                                          principal_point=((2.5, 3.5), ))
     vertices = torch.randn([3, 4, 3], dtype=torch.float32)
     projected_verts = vertices.clone()
     projected_verts[:, :, :2] *= 2.0
     projected_verts[:, :, 0] += 2.5
     projected_verts[:, :, 1] += 3.5
     v1 = P.transform_points(vertices)
     self.assertClose(v1, projected_verts)
Beispiel #3
0
    def test_orthographic_scaled(self):
        focal_length_x = 10.0
        focal_length_y = 15.0

        cameras = OrthographicCameras(focal_length=((focal_length_x, focal_length_y),))
        P = cameras.get_projection_transform()

        vertices = torch.randn([3, 4, 3], dtype=torch.float32)
        projected_verts = vertices.clone()
        projected_verts[:, :, 0] *= focal_length_x
        projected_verts[:, :, 1] *= focal_length_y
        v1 = P.transform_points(vertices)
        v2 = orthographic_project_naive(
            vertices, scale_xyz=(focal_length_x, focal_length_y, 1.0)
        )
        v3 = cameras.transform_points(vertices)
        self.assertClose(v1[..., :2], v2[..., :2])
        self.assertClose(v3[..., :2], v2[..., :2])
        self.assertClose(v1, projected_verts)