1# ----------------------------------------------------------------------------
2# - Open3D: www.open3d.org -
3# ----------------------------------------------------------------------------
4# The MIT License (MIT)
5#
6# Copyright (c) 2018-2021 www.open3d.org
7#
8# Permission is hereby granted, free of charge, to any person obtaining a copy
9# of this software and associated documentation files (the "Software"), to deal
10# in the Software without restriction, including without limitation the rights
11# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
12# copies of the Software, and to permit persons to whom the Software is
13# furnished to do so, subject to the following conditions:
14#
15# The above copyright notice and this permission notice shall be included in
16# all copies or substantial portions of the Software.
17#
18# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
21# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
22# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
23# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
24# IN THE SOFTWARE.
25# ----------------------------------------------------------------------------
26
27import numpy as np
28import open3d as o3d
29
30if __name__ == "__main__":
31
32 print("Testing camera in open3d ...")
33 intrinsic = o3d.camera.PinholeCameraIntrinsic(
34 o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault)
35 print(intrinsic.intrinsic_matrix)
36 print(o3d.camera.PinholeCameraIntrinsic())
37 x = o3d.camera.PinholeCameraIntrinsic(640, 480, 525, 525, 320, 240)
38 print(x)
39 print(x.intrinsic_matrix)
40 o3d.io.write_pinhole_camera_intrinsic("test.json", x)
41 y = o3d.io.read_pinhole_camera_intrinsic("test.json")
42 print(y)
43 print(np.asarray(y.intrinsic_matrix))
44
45 print("Read a trajectory and combine all the RGB-D images.")
46 pcds = []
47 redwood_rgbd = o3d.data.SampleRedwoodRGBDImages()
48 trajectory = o3d.io.read_pinhole_camera_trajectory(
49 redwood_rgbd.trajectory_log_path)
50 o3d.io.write_pinhole_camera_trajectory("test.json", trajectory)
51 print(trajectory)
52 print(trajectory.parameters[0].extrinsic)
53 print(np.asarray(trajectory.parameters[0].extrinsic))
54 for i in range(5):
55 im1 = o3d.io.read_image(redwood_rgbd.depth_paths[i])
56 im2 = o3d.io.read_image(redwood_rgbd.color_paths[i])
57 im = o3d.geometry.RGBDImage.create_from_color_and_depth(
58 im2, im1, 1000.0, 5.0, False)
59 pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
60 im, trajectory.parameters[i].intrinsic,
61 trajectory.parameters[i].extrinsic)
62 pcds.append(pcd)
63 o3d.visualization.draw_geometries(pcds)