python, Open3D: Is there a way to set parameters of vizualization without closing the window?

209 Views Asked by At

I have successive pointcloud-data coming frame by frame from my time-of-flight camera, and I want to display it with Python 3.10, and the open3d library.

The goal is to show the incoming data as a live preview of the camera. This works well with the manufacturer py-script which uses the asyncio-library as the frames are awaitables.

However, my problem is the following:

This script uses the o3d.visualization.Visualizer.add_geometry(pcd,True) command from the o3d library after creating a window. I can use my mouse in the window to adjust the view and use ctrl+c to copy the current view status into the clipboard. Using the mouse every time to set the view status is cumbersome as there will always be differences in the views I get. I would like to get the same view status every time I open the window to get comparable results.

So, does anyone know how to set the view status after the o3d.visualization.Visualizer.add_geometry(pcd,True) has been started?

pcd ... my point cloud data

as shown in the open3d doc the view status can be copied which yields in my case:

{
    "class_name" : "ViewTrajectory",
    "interval" : 29,
    "is_loop" : false,
    "trajectory" : 
    [
        {
            "boundingbox_max" : [ 2.4493699073791504, 1.9389574527740479, 2.1757895946502686 ],
            "boundingbox_min" : [ -2.5847299098968506, -1.8458751440048218, 0.0 ],
            "field_of_view" : 60.0,
            "front" : [ 0.16044233442547645, 0.064093449935902075, -0.9849620738888466 ],
            "lookat" : [ 0.14832833824513739, -0.30275783432427361, 1.1003512211054685 ],
            "up" : [ 0.0019829908400814389, -0.99790843426770126, -0.064612882343332012 ],
            "zoom" : 0.29999999999999993
        }
    ],
    "version_major" : 1,
    "version_minor" : 0
}

Now I can use this information to display the pointcloud with the command o3d.visualization.draw_geometries([ pcd], zoom=0.29999999999999993, front=[ 0.16044233442547645, 0.064093449935902075, -0.9849620738888466 ], ... , height=1080). This works fine.

But this is the command "o3d.visualization.draw_geometries" and not "o3d.visualization.Visualizer.add_geometry" as before.

So does anyone know if such view status arguments can also be handed to the latter command or how to update the view after the pointcloud was loaded with .add_geometry ?

I came across o3d.visualization.Visualizer.get_view_control and o3d.visualization.Visualizer.update_renderer but didn't know how to use them.

Thanks a lot in advance.

1

There are 1 best solutions below

4
saurabheights On

Start with Open3d tutorial on Non-Blocking Visualization. update_renderer is usually called when you are done adding/removing/updating various geometries. This is supposed to be done for each frame, like updating the screen after you are done drawing the current frame in a game.

Next, the update_geometries method is just a wrapper function built on top of the Visualizer class. Visualizer stores its view options in an object of ViewControl class. Changing this visualizer.get_view_control() fields will reflect in your Visualizer window.

See https://stackoverflow.com/a/77506153/1874627 if you are using Open3D version 0.17.0.

Now to set fields such as lookat, front, etc. try:-

vis.get_view_control().set_front(front)
vis.get_view_control().set_lookat(lookat)
vis.get_view_control().set_up(up)
vis.get_view_control().set_zoom(zoom)

See documentation of ViewControl here - https://www.open3d.org/docs/latest/python_api/open3d.visualization.ViewControl.html

Also, see https://stackoverflow.com/a/77506153/1874627 which shows an example usage of vis.get_render_option() which allows changing rendering attributes instead of changing camera view attributes.