Camera#

camera_trajectory.py#

 1# ----------------------------------------------------------------------------
 2# -                        Open3D: www.open3d.org                            -
 3# ----------------------------------------------------------------------------
 4# Copyright (c) 2018-2023 www.open3d.org
 5# SPDX-License-Identifier: MIT
 6# ----------------------------------------------------------------------------
 7
 8import numpy as np
 9import open3d as o3d
10
11if __name__ == "__main__":
12
13    print("Testing camera in open3d ...")
14    intrinsic = o3d.camera.PinholeCameraIntrinsic(
15        o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault)
16    print(intrinsic.intrinsic_matrix)
17    print(o3d.camera.PinholeCameraIntrinsic())
18    x = o3d.camera.PinholeCameraIntrinsic(640, 480, 525, 525, 320, 240)
19    print(x)
20    print(x.intrinsic_matrix)
21    o3d.io.write_pinhole_camera_intrinsic("test.json", x)
22    y = o3d.io.read_pinhole_camera_intrinsic("test.json")
23    print(y)
24    print(np.asarray(y.intrinsic_matrix))
25
26    print("Read a trajectory and combine all the RGB-D images.")
27    pcds = []
28    redwood_rgbd = o3d.data.SampleRedwoodRGBDImages()
29    trajectory = o3d.io.read_pinhole_camera_trajectory(
30        redwood_rgbd.trajectory_log_path)
31    o3d.io.write_pinhole_camera_trajectory("test.json", trajectory)
32    print(trajectory)
33    print(trajectory.parameters[0].extrinsic)
34    print(np.asarray(trajectory.parameters[0].extrinsic))
35    for i in range(5):
36        im1 = o3d.io.read_image(redwood_rgbd.depth_paths[i])
37        im2 = o3d.io.read_image(redwood_rgbd.color_paths[i])
38        im = o3d.geometry.RGBDImage.create_from_color_and_depth(
39            im2, im1, 1000.0, 5.0, False)
40        pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
41            im, trajectory.parameters[i].intrinsic,
42            trajectory.parameters[i].extrinsic)
43        pcds.append(pcd)
44    o3d.visualization.draw_geometries(pcds)