IO

image_io.py

 1# ----------------------------------------------------------------------------
 2# -                        Open3D: www.open3d.org                            -
 3# ----------------------------------------------------------------------------
 4# Copyright (c) 2018-2023 www.open3d.org
 5# SPDX-License-Identifier: MIT
 6# ----------------------------------------------------------------------------
 7
 8import open3d as o3d
 9
10if __name__ == "__main__":
11    img_data = o3d.data.JuneauImage()
12    print(f"Reading image from file: Juneau.jpg stored at {img_data.path}")
13    img = o3d.io.read_image(img_data.path)
14    print(img)
15    print("Saving image to file: copy_of_Juneau.jpg")
16    o3d.io.write_image("copy_of_Juneau.jpg", img)

point_cloud_io.py

 1# ----------------------------------------------------------------------------
 2# -                        Open3D: www.open3d.org                            -
 3# ----------------------------------------------------------------------------
 4# Copyright (c) 2018-2023 www.open3d.org
 5# SPDX-License-Identifier: MIT
 6# ----------------------------------------------------------------------------
 7
 8import open3d as o3d
 9
10if __name__ == "__main__":
11    pcd_data = o3d.data.PCDPointCloud()
12    print(
13        f"Reading pointcloud from file: fragment.pcd stored at {pcd_data.path}")
14    pcd = o3d.io.read_point_cloud(pcd_data.path)
15    print(pcd)
16    print("Saving pointcloud to file: copy_of_fragment.pcd")
17    o3d.io.write_point_cloud("copy_of_fragment.pcd", pcd)

realsense_io.py

 1# ----------------------------------------------------------------------------
 2# -                        Open3D: www.open3d.org                            -
 3# ----------------------------------------------------------------------------
 4# Copyright (c) 2018-2023 www.open3d.org
 5# SPDX-License-Identifier: MIT
 6# ----------------------------------------------------------------------------
 7"""Demonstrate RealSense camera discovery and frame capture"""
 8
 9import open3d as o3d
10
11if __name__ == "__main__":
12
13    o3d.t.io.RealSenseSensor.list_devices()
14    rscam = o3d.t.io.RealSenseSensor()
15    rscam.start_capture()
16    print(rscam.get_metadata())
17    for fid in range(5):
18        rgbd_frame = rscam.capture_frame()
19        o3d.io.write_image(f"color{fid:05d}.jpg", rgbd_frame.color.to_legacy())
20        o3d.io.write_image(f"depth{fid:05d}.png", rgbd_frame.depth.to_legacy())
21        print("Frame: {}, time: {}s".format(fid, rscam.get_timestamp() * 1e-6))
22
23    rscam.stop_capture()

triangle_mesh_io.py

 1# ----------------------------------------------------------------------------
 2# -                        Open3D: www.open3d.org                            -
 3# ----------------------------------------------------------------------------
 4# Copyright (c) 2018-2023 www.open3d.org
 5# SPDX-License-Identifier: MIT
 6# ----------------------------------------------------------------------------
 7
 8import open3d as o3d
 9
10if __name__ == "__main__":
11    knot_data = o3d.data.KnotMesh()
12    print(f"Reading mesh from file: knot.ply stored at {knot_data.path}")
13    mesh = o3d.io.read_triangle_mesh(knot_data.path)
14    print(mesh)
15    print("Saving mesh to file: copy_of_knot.ply")
16    o3d.io.write_triangle_mesh("copy_of_knot.ply", mesh)