isl-org / isl-org/Open3D

Set the Visualizer camera viewpoint reading from a json file?

Open
#6,428 4 comments 0 reactions 0 assignees View on GitHub
question
Dominant language
C++
Stars
14k
Forks
2.6k
Avg merge
5d 18h
Merged PRs (30d)
6

Description

### Checklist

- [X] I have searched for [similar issues](https://github.com/isl-org/Open3D/issues).
- [X] For Python issues, I have tested with the [latest development wheel](http://www.open3d.org/docs/latest/getting_started.html#development-version-pip).
- [X] I have checked the [release documentation](http://www.open3d.org/docs/release/) and the [latest documentation](http://www.open3d.org/docs/latest/) (for `master` branch).

### 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](https://github.com/isl-org/Open3D/issues/567) I've tried the first example linked in that [thread](https://github.com/intel-isl/Open3D/blob/master/examples/Python/Advanced/load_save_viewpoint.py). I moved the camera position in the viewer manually and then saved that camera viewpoint to json using this code:
```python
# 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:
```json
{
"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:
```python
# 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:
- Tried the second class example linked [here](https://gist.github.com/Kin-Zhang/77e8aa77a998f1a4f7495357843f24ef) But this was not using pinhole parameters
- Also tried manually manipulating the json file coordinates to see if I could get camera position to change but still had no luck

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

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.