def generate_current_image(self, next_image, current_depth, transformation_from_current_to_next):
     generated_current_image = kornia.warp_frame_depth(next_image,
                                                       current_depth,
                                                       transformation_from_current_to_next,
                                                       self.camera_matrix)
     return generated_current_image
Ejemplo n.º 2
0
    def _get_synthesized_image(self):
        self._model.eval()
        data_point = self._dataset_manager.get_validation_dataset(
            with_normalize=True)[0]
        with torch.no_grad():
            left_current_depth = self._model.depth(
                data_point["left_current_image"][None].to(self._device))
            right_current_depth = self._model.depth(
                data_point["right_current_image"][None].to(self._device))
        data_point = self._dataset_manager.get_validation_dataset(
            with_normalize=False)[0]
        left_current_image = data_point["left_current_image"][None].to(
            self._device)
        right_current_image = data_point["right_current_image"][None].to(
            self._device)
        cameras_calibration = self._dataset_manager.get_cameras_calibration(
            device=self._device)
        with torch.no_grad():
            generated_left_image = kornia.warp_frame_depth(
                right_current_image, left_current_depth,
                torch.inverse(
                    cameras_calibration.transform_from_left_to_right),
                cameras_calibration.left_camera_matrix)
            generated_right_image = kornia.warp_frame_depth(
                left_current_image, right_current_depth,
                cameras_calibration.transform_from_left_to_right,
                cameras_calibration.left_camera_matrix)

        figure = plt.figure(dpi=200, figsize=(9, 6))

        plt.subplot(3, 2, 1)
        image = left_current_image[0].cpu().permute(1, 2, 0).detach().numpy()
        plt.imshow(np.clip(image, 0, 1))
        self.set_title("Left current image")

        plt.subplot(3, 2, 2)
        image = right_current_image[0].cpu().permute(1, 2, 0).detach().numpy()
        plt.imshow(np.clip(image, 0, 1))
        self.set_title("Right current image")

        plt.subplot(3, 2, 3)
        depth_image = left_current_depth[0].detach().cpu().permute(
            1, 2, 0).numpy()[:, :, 0]
        plt.imshow(np.clip(1.0 / depth_image, 0, 100) / 100, cmap="inferno")
        self.set_title("Left current depth")

        plt.subplot(3, 2, 4)
        depth_image = right_current_depth[0].detach().cpu().permute(
            1, 2, 0).numpy()[:, :, 0]
        plt.imshow(np.clip(1.0 / depth_image, 0, 100) / 100, cmap="inferno")
        self.set_title("Right current depth")

        plt.subplot(3, 2, 5)
        image = generated_left_image[0].cpu().permute(1, 2, 0).detach().numpy()
        plt.imshow(np.clip(image, 0, 1))
        self.set_title("Generated left image")

        plt.subplot(3, 2, 6)
        image = generated_right_image[0].cpu().permute(1, 2,
                                                       0).detach().numpy()
        plt.imshow(np.clip(image, 0, 1))
        self.set_title("Generated right image")
        return {"generated": figure}