isl-org / Open3D

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

Can not append camera views to camera.PinholeCameraTrajectory() #3390

Open HM102 opened 3 years ago

HM102 commented 3 years ago

I am trying to append the current camera view to a trajectory class

import numpy as np
import open3d as o3d

trajectory = o3d.camera.PinholeCameraTrajectory()

def key_callback(vis):
    ctr = vis.get_view_control()
    param = ctr.convert_to_pinhole_camera_parameters()
    trajectory.parameters.append(param)
    print(np.asarray(trajectory.parameters))

points = np.random.rand(100000, 3)
point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(points)

vis = o3d.visualization.VisualizerWithKeyCallback()
vis.create_window()
vis.add_geometry(point_cloud)
vis.register_key_callback(ord("S"), key_callback)

vis.run()
vis.destroy_window()

when I press "S" I always get an empty list []

The trajectory is always empty, I checked the param it has intrinsic and extrinsic so it is not empty!

print(np.asarray(param.extrinsic))

[[ 0.98384893  0.00565312  0.17891152 -0.58419041]
 [-0.00457813 -0.99837954  0.05672158  0.47312568]
 [ 0.17894225 -0.05662455 -0.98222876  2.09271794]
 [ 0.          0.          0.          1.        ]]
HM102 commented 3 years ago

As a follow up.I tired something similar in c++ and it works, however can not figured out how to do it in python:

auto point_cloud = open3d::geometry::PointCloud();
open3d::io::ReadPointCloud("cloud_bin_0.pcd", point_cloud);
auto cloud_ptr = std::make_shared<open3d::geometry::PointCloud>(point_cloud);

open3d::camera::PinholeCameraTrajectory trajec;
int cnt = 0;
visualization::DrawGeometriesWithKeyCallbacks(
            {cloud_ptr},
            {{GLFW_KEY_SPACE,
                     [&](visualization::Visualizer *vis) {
                         open3d::visualization::ViewControl view_control = vis->GetViewControl();
                         auto view_params = open3d::camera::PinholeCameraParameters();
                         view_control.ConvertToPinholeCameraParameters(view_params);
                         trajec.parameters_.push_back(view_params);
                         std::cout<<trajec.parameters_[cnt].extrinsic_<<std::endl;
                         cnt++;
                         std::this_thread::sleep_for(
                                 std::chrono::milliseconds(30));
                         return false;
                     }}},
            "Press Space to save trajectory", 1600, 900);
heethesh commented 3 years ago

+1 any solutions for this?

heethesh commented 3 years ago

This solution worked.

trajectory = o3d.camera.PinholeCameraTrajectory()
trajectory_list = []
trajectory_list.append(camera_parameter)
trajectory.parameters = trajectory_list