| 72 | self.visualizer.update_renderer() |
| 73 | |
| 74 | def add_cameras(self, scale: float = 1) -> None: |
| 75 | frustums = [] |
| 76 | for img in self.reconstruction.images.values(): |
| 77 | # extrinsics |
| 78 | world_from_cam = img.cam_from_world().inverse() |
| 79 | R = world_from_cam.rotation.matrix() |
| 80 | t = world_from_cam.translation |
| 81 | |
| 82 | # intrinsics |
| 83 | cam = img.camera |
| 84 | if cam.model in ( |
| 85 | pycolmap.CameraModelId.SIMPLE_PINHOLE, |
| 86 | pycolmap.CameraModelId.SIMPLE_RADIAL, |
| 87 | pycolmap.CameraModelId.RADIAL, |
| 88 | ): |
| 89 | fx = fy = cam.params[0] |
| 90 | cx = cam.params[1] |
| 91 | cy = cam.params[2] |
| 92 | elif cam.model in ( |
| 93 | pycolmap.CameraModelId.PINHOLE, |
| 94 | pycolmap.CameraModelId.OPENCV, |
| 95 | pycolmap.CameraModelId.OPENCV_FISHEYE, |
| 96 | pycolmap.CameraModelId.FULL_OPENCV, |
| 97 | ): |
| 98 | fx = cam.params[0] |
| 99 | fy = cam.params[1] |
| 100 | cx = cam.params[2] |
| 101 | cy = cam.params[3] |
| 102 | else: |
| 103 | raise Exception("Camera model not supported") |
| 104 | |
| 105 | # intrinsics |
| 106 | K = np.identity(3) |
| 107 | K[0, 0] = fx |
| 108 | K[1, 1] = fy |
| 109 | K[0, 2] = cx |
| 110 | K[1, 2] = cy |
| 111 | |
| 112 | # create axis, plane and pyramid geometries that will be drawn |
| 113 | cam_model = draw_camera(K, R, t, cam.width, cam.height, scale) |
| 114 | frustums.extend(cam_model) |
| 115 | |
| 116 | # add geometries to visualizer |
| 117 | for i in frustums: |
| 118 | self.visualizer.add_geometry(i) |
| 119 | |
| 120 | def create_window(self) -> None: |
| 121 | self.visualizer = open3d.visualization.Visualizer() |