Reconstruct depth to 3D pointcloud with the provided focal length. Return: pcd: N X 3 array, point cloud
(depth, f)
| 128 | return torch.tensor([[last_shift]]) |
| 129 | |
| 130 | def reconstruct_3D(depth, f): |
| 131 | """ |
| 132 | Reconstruct depth to 3D pointcloud with the provided focal length. |
| 133 | Return: |
| 134 | pcd: N X 3 array, point cloud |
| 135 | """ |
| 136 | cu = depth.shape[1] / 2 |
| 137 | cv = depth.shape[0] / 2 |
| 138 | width = depth.shape[1] |
| 139 | height = depth.shape[0] |
| 140 | row = np.arange(0, width, 1) |
| 141 | u = np.array([row for i in np.arange(height)]) |
| 142 | col = np.arange(0, height, 1) |
| 143 | v = np.array([col for i in np.arange(width)]) |
| 144 | v = v.transpose(1, 0) |
| 145 | |
| 146 | if f > 1e5: |
| 147 | print('Infinit focal length!!!') |
| 148 | x = u - cu |
| 149 | y = v - cv |
| 150 | z = depth / depth.max() * x.max() |
| 151 | else: |
| 152 | x = (u - cu) * depth / f |
| 153 | y = (v - cv) * depth / f |
| 154 | z = depth |
| 155 | |
| 156 | x = np.reshape(x, (width * height, 1)).astype(float) |
| 157 | y = np.reshape(y, (width * height, 1)).astype(float) |
| 158 | z = np.reshape(z, (width * height, 1)).astype(float) |
| 159 | pcd = np.concatenate((x, y, z), axis=1) |
| 160 | pcd = pcd.astype(int) |
| 161 | return pcd |
| 162 | |
| 163 | def save_point_cloud(pcd, rgb, filename, binary=True): |
| 164 | """Save an RGB point cloud as a PLY file. |