isl-org / Open3D

Open3D: A Modern Library for 3D Data Processing
http://www.open3d.org
Other
11.4k stars 2.3k forks source link

Set the Visualizer camera viewpoint reading from a json file? #6428

Open DrewScatterday opened 1 year ago

DrewScatterday commented 1 year ago

Checklist

My Question

What I'm trying to do:

I have a ply mesh and I want to set the Visualizer camera viewpoint reading from a json file

My Code:

I found this issue thread here I've tried the first example linked in that thread. I moved the camera position in the viewer manually and then saved that camera viewpoint to json using this code:

# WRITE CAMERA PARAMS:
pcd = o3d.io.read_triangle_mesh("C:/Users/dre11620/Downloads/Meta/data/merged/floor1crop_mesh.ply")
vis = o3d.visualization.Visualizer()
vis.create_window()
vis.add_geometry(pcd)
vis.run()
ctr = vis.get_view_control()
filename = "test.json"
param = ctr.convert_to_pinhole_camera_parameters()
o3d.io.write_pinhole_camera_parameters(filename, param)
vis.destroy_window()

That code produced this viewpoint json file:

{
    "class_name" : "PinholeCameraParameters",
    "extrinsic" : 
    [
        0.35575640512030332,
        -0.13610610677064994,
        -0.924614788934081,
        0.0,
        0.88390356490160737,
        -0.27235126166383977,
        0.38018321665263533,
        0.0,
        -0.30356526179737464,
        -0.95252292254299642,
        0.023413967199949572,
        0.0,
        15517.160451773407,
        -841.85716878030598,
        18774.216773767057,
        1.0
    ],
    "intrinsic" : 
    {
        "height" : 1061,
        "intrinsic_matrix" : 
        [
            918.85295341528945,
            0.0,
            0.0,
            0.0,
            918.85295341528945,
            0.0,
            959.5,
            530.0,
            1.0
        ],
        "width" : 1920
    },
    "version_major" : 1,
    "version_minor" : 0
}

Then I used this code and tried reading in that json file to set the viewpoint:

# READ CAMERA PARAMS:
pcd = o3d.io.read_triangle_mesh("C:/Users/dre11620/Downloads/Meta/data/merged/floor1crop_mesh.ply")
vis = o3d.visualization.Visualizer()
vis.create_window()
ctr = vis.get_view_control()
filename = "test.json"
param = o3d.io.read_pinhole_camera_parameters(filename)
vis.add_geometry(pcd)
ctr.convert_from_pinhole_camera_parameters(param)
vis.run()
vis.destroy_window()

But that doesn't set the camera position of the window

Other things I've tried:

What am I missing? What is the correct way to set the viewpoint from a json file?

DrewScatterday commented 1 year ago

Okay I think this is actually a bug with maybe read_pinhole_camera_parameters in 0.17.0

I downgraded to open3d==0.16.0 and ran this same exact code and it worked with no issues

For reference I'm on: Windows 10 64 bit Build 19045 Python 3.8.17 Using a conda env with conda version 23.3.1

co1one commented 1 year ago

Okay I think this is actually a bug with maybe read_pinhole_camera_parameters in 0.17.0

I downgraded to open3d==0.16.0 and ran this same exact code and it worked with no issues

For reference I'm on: Windows 10 64 bit Build 19045 Python 3.8.17 Using a conda env with conda version 23.3.1

my man, you are my hero!!!!!

DrewScatterday commented 1 year ago

@co1one glad I could help! Took me way too long to figure that one out haha. Hopefully someone fixes it in the latest version

saurabheights commented 1 year ago

@DrewScatterday @co1one The issue was fixed in master branch some months ago. If you install via latest http://www.open3d.org/docs/latest/getting_started.html#development-version-pip, you should not face the issue.

Main issue is due to vis.get_view_control() returning copy of view control and changes to it are not reflected in visualizer.