def intialize_visualizer(self):
     '''
     Function to add geometry (cannot destroy)
     '''
     self.vis = o3.Visualizer()
     self.vis.create_window()
     self.vis.get_render_option().load_from_json(
         "static_data/renderoption.json")
     self.vis.add_geometry(self.base)
     self.trajectory = o3.read_pinhole_camera_trajectory(
         "static_data/pinholeCameraTrajectory3.json")
     self.custom_view()
     self.vis.run()
Ejemplo n.º 2
0
    def intialize_visualizer(self):
        '''
        Function to add geometry (cannot destroy)
        '''

        h, w = self._get_window_size()
        self.vis = o3.Visualizer()
        self.vis.create_window('pose',
                               width=int(w),
                               height=int(h),
                               left=50,
                               right=50)
        self.vis.add_geometry(self.base)

        self.render_option = self.vis.get_render_option().load_from_json(
            "static_data/renderoption.json")

        self.trajectory = o3.read_pinhole_camera_trajectory(
            "static_data/pinholeCameraTrajectory.json")
        self.custom_view()
        self.vis.update_renderer()
        self.vis.run()
Ejemplo n.º 3
0
      glb.vis.register_animation_callback(None)
    return False

  vis = glb.vis
  vis.create_window(width=intrinsic.width, height=intrinsic.height)
  vis.add_geometry(mesh)
  vis.register_animation_callback(callback)
  vis.run()
  vis.destroy_window()


if __name__ == "__main__":
    open3d.set_verbosity_level(open3d.VerbosityLevel.Debug)

    # Read camera pose and mesh
    camera = open3d.read_pinhole_camera_trajectory(os.path.join(path, "scene/key.log"))
    mesh = open3d.read_triangle_mesh(os.path.join(path, "scene", "integrated.ply"))

    color_image_path = get_file_list(
            os.path.join(path, "image/"), extension = ".jpg")

    if USE_Z_BUFFERING:
      depth_image_path = [osp.join('/tmp', fn.replace('jpg', 'png'))
        for fn in color_image_path]
      # generate depth maps
      save_depth_maps(mesh, camera.intrinsic, np.asarray(camera.extrinsic),
        depth_image_path)
    else:
      depth_filenames = get_file_list(
        os.path.join(path, "depth/"), extension = ".png")
      depth_image_path = []
Ejemplo n.º 4
0
def reconstruct(room_name, cam_poses):
    # prepare the result file
    result_file = os.path.join(
        proj_path, "result", "{}_{}_{}.json".format(dataset_name, room_name,
                                                    vox_num_option))

    print(result_file)
    if ft.file_exist(result_file):
        # load data
        print("load result json file ...")
        data_result = io.load_json(result_file)
    else:
        print("No result file, please check your folder again!")
        return
    if VIS_ALL or VIS_FINAL:
        vis = o3d.Visualizer()
        vis.create_window()
        print("created a window")

    for start_index_key in start_key_list:
        print("start index", start_index_key)
        result_pcd_folder = os.path.join(proj_path, "result", "pcd",
                                         start_index_key)
        if not os.path.exists(result_pcd_folder):
            os.makedirs(result_pcd_folder)
        # regarding the view point for the visualiser
        viewpoint_file = os.path.join(result_pcd_folder, "view_point.json")

        for method in NBV_strategy:
            print("method", method)
            result_pcd_file = os.path.join(
                result_pcd_folder,
                "{}_{}_{}.ply".format(dataset_name, room_name, method))
            result_pcd_folder_method = os.path.join(proj_path, "result",
                                                    start_index_key, method)

            if (not os.path.exists(result_pcd_file)) or (
                    VIS_ALL and
                (not os.path.exists(result_pcd_folder_method))):
                if VIS_ALL:
                    trajectory = o3d.read_pinhole_camera_trajectory(
                        viewpoint_file)
                    print("created a window")
                if VIS_ALL and (not os.path.exists(result_pcd_folder_method)):
                    os.makedirs(os.path.join(result_pcd_folder_method, "pcd"))
                    os.makedirs(os.path.join(result_pcd_folder_method,
                                             "depth"))
                    os.makedirs(os.path.join(result_pcd_folder_method, "rgb"))
                    print("created folders")
                nbv_ids = data_result[start_index_key][method]["NBV_ids"]
                volume = o3d.ScalableTSDFVolume(
                    voxel_length=0.01,
                    sdf_trunc=0.03,
                    color_type=o3d.TSDFVolumeColorType.RGB8)  # 4.0 / 512.0
                count = 0

                for pose_id in range(len(nbv_ids)):
                    print("Integrate frame at {:d}".format(pose_id))
                    current_pose = cam_poses[nbv_ids[pose_id]]
                    rgb_path = os.path.join(
                        proj_path, config["dataset_folder"], dataset_name,
                        room_name, "image",
                        "rgb{:d}.png".format(nbv_ids[pose_id]))
                    depth_path = os.path.join(
                        proj_path, config["dataset_folder"], dataset_name,
                        room_name, "depth",
                        "depth{:d}.png".format(nbv_ids[pose_id]))
                    color = o3d.read_image(rgb_path)
                    depth = o3d.read_image(depth_path)
                    rgbd = o3d.create_rgbd_image_from_color_and_depth(
                        color,
                        depth,
                        depth_trunc=4.5,
                        convert_rgb_to_intensity=False)
                    volume.integrate(rgbd, intrinsic,
                                     np.linalg.inv(current_pose))
                    pcd_scene = volume.extract_point_cloud(
                    )  # note the points are not isometric
                    if VIS_ALL:
                        print("Visualise each frame")
                        result_pcd_file_temp = os.path.join(
                            result_pcd_folder_method, "pcd",
                            "{}_{}_{:03d}.png".format(dataset_name, room_name,
                                                      count))
                        result_depth_file_temp = os.path.join(
                            result_pcd_folder_method, "depth",
                            "{}_{}_{:03d}.png".format(dataset_name, room_name,
                                                      count))
                        result_rgb_file_temp = os.path.join(
                            result_pcd_folder_method, "rgb",
                            "{}_{}_{:03d}.png".format(dataset_name, room_name,
                                                      count))

                        copyfile(depth_path, result_depth_file_temp)
                        copyfile(rgb_path, result_rgb_file_temp)

                        vis.add_geometry(pcd_scene)
                        mesh_frame = local_plt.o3d_coordinate(current_pose)
                        vis.add_geometry(mesh_frame)

                        ctr = vis.get_view_control()
                        #if count == 0:
                        ctr.convert_from_pinhole_camera_parameters(
                            trajectory.intrinsic, trajectory.extrinsic[0])
                        vis.update_geometry()
                        vis.poll_events()
                        vis.update_renderer()

                        vis.capture_screen_image(result_pcd_file_temp)
                        # crop border
                        img = improc.crop_border(result_pcd_file_temp, 0.08,
                                                 0.4)
                        # img = improc.imscale(img, 1.5)
                        improc.imwrite(result_pcd_file_temp, img)

                        time.sleep(0.5)

                        pcd_scene.points = o3d.Vector3dVector([])
                        pcd_scene.colors = o3d.Vector3dVector([])

                        vis.update_geometry()
                        vis.poll_events()
                        vis.update_renderer()

                    count = count + 1

                if not os.path.exists(result_pcd_file):
                    pcd_scene = volume.extract_point_cloud(
                    )  #note the points are not isometric
                    o3d.write_point_cloud(result_pcd_file, pcd_scene)
            else:
                if VIS_FINAL:

                    print("created a visualiser")
                    pcd_scene = o3d.read_point_cloud(result_pcd_file)
                    # only trigger the view point set when there is no tarjectory file
                    if not os.path.exists(viewpoint_file):
                        print(
                            "Please manipulate the visualiser for a better view point, close to save!"
                        )
                        save_view_point(vis, pcd_scene, viewpoint_file)
                        return

                    image_name = os.path.join(result_pcd_folder,
                                              "{}_pcd.png".format(method))

                    trajectory = o3d.read_pinhole_camera_trajectory(
                        viewpoint_file)
                    print("read the view point")

                    vis.add_geometry(pcd_scene)
                    print("Added the view point")

                    ctr = vis.get_view_control()
                    print("obtained view control")
                    ctr.convert_from_pinhole_camera_parameters(
                        trajectory.intrinsic, trajectory.extrinsic[0])

                    print("changed the view point")

                    vis.update_geometry()
                    vis.poll_events()
                    vis.update_renderer()
                    print("updated the rendering")
                    vis.capture_screen_image(image_name)
                    print("captured the screenshot")
                    # crop border
                    img = improc.crop_border(image_name, 0.08, 0.4)
                    #img = improc.imscale(img, 1.5)
                    improc.imwrite(image_name, img)

                    time.sleep(2)

                    pcd_scene.points = o3d.Vector3dVector([])
                    pcd_scene.colors = o3d.Vector3dVector([])

                    vis.update_geometry()
                    vis.poll_events()
                    vis.update_renderer()
                    print("reset the point to empty")
    if VIS_ALL or VIS_FINAL:
        vis.destroy_window()
        print("closed window and visualiser")
Ejemplo n.º 5
0
 def setView(self):
     ctr = vis.get_view_control()
     trajectory = o3d.read_pinhole_camera_trajectory("test.json")
     ctr.convert_from_pinhole_camera_parameters(trajectory.intrinsic,
                                                trajectory.extrinsic[0])