Exemplo n.º 1
0
 def generate_normals(self, z_batch, cam_pos, camera):
     """Generate normals from depth."""
     W, H = camera['viewport'][2:]
     normals = []
     for z, eye in zip(z_batch, cam_pos):
         camera['eye'] = eye
         pcl = z_to_pcl_CC(z.squeeze(), camera)
         n = self.netG2(pcl.view(H, W, 3).permute(2, 0, 1)[np.newaxis, ...])
         n = n.squeeze().permute(1, 2, 0).view(-1, 3).contiguous()
         normals.append(n)
     return torch.stack(normals)
Exemplo n.º 2
0
def test_depth_to_world_consistency(scene, batch_size):
    res = render_scene(scene)

    scene = make_torch_var(load_scene(scene))

    pos_wc1 = res['pos'].reshape(-1, res['pos'].shape[-1])

    pos_cc1 = world_to_cam(pos_wc1, None, scene['camera'])['pos']
    # First test the non-batched z_to_pcl_CC method:
    # NOTE: z_to_pcl_CC takes as input the Z dimension in the camera coordinate
    # and gets the full (X, Y, Z) in the camera coordinate.
    pos_cc2 = z_to_pcl_CC(pos_cc1[:, 2], scene['camera'])
    pos_wc2 = cam_to_world(pos_cc2, None, scene['camera'])['pos']

    # Test Z -> (X, Y, Z)
    np.testing.assert_array_almost_equal(get_data(pos_cc1[..., :3]),
                                         get_data(pos_cc2[..., :3]))
    # Test world -> camera -> Z -> (X, Y, Z) in camera -> world
    np.testing.assert_array_almost_equal(get_data(pos_wc1[..., :3]),
                                         get_data(pos_wc2[..., :3]))

    # Then test the batched version:
    camera = scene['camera']
    camera['eye'] = camera['eye'].repeat(batch_size, 1)
    camera['at'] = camera['at'].repeat(batch_size, 1)
    camera['up'] = camera['up'].repeat(batch_size, 1)

    pos_wc1 = pos_wc1.repeat(batch_size, 1, 1)
    pos_cc1 = world_to_cam_batched(pos_wc1, None, scene['camera'])['pos']
    pos_cc2 = z_to_pcl_CC_batched(pos_cc1[..., 2], camera)  # NOTE: z = -depth
    pos_wc2 = cam_to_world_batched(pos_cc2, None, camera)['pos']

    # Test Z -> (X, Y, Z)
    np.testing.assert_array_almost_equal(get_data(pos_cc1[..., :3]),
                                         get_data(pos_cc2[..., :3]))
    # Test world -> camera -> Z -> (X, Y, Z) in camera -> world
    np.testing.assert_array_almost_equal(get_data(pos_wc1[..., :3]),
                                         get_data(pos_wc2[..., :3]))
Exemplo n.º 3
0
def generate_normals(z, camera, norm_est_net_fn):
    W, H = camera['viewport'][2:]
    pcl = z_to_pcl_CC(z.squeeze(), camera)
    n = norm_est_net_fn(pcl.view(H, W, 3).permute(2, 0, 1)[np.newaxis, ...])
    return n.squeeze().permute(1, 2, 0).contiguous().view(-1, 3)