Skip to content

Instantly share code, notes, and snippets.

@chunibyo-wly
Created February 16, 2023 03:31
Show Gist options
  • Save chunibyo-wly/d607b83c15e989355513302fc5ab0303 to your computer and use it in GitHub Desktop.
Save chunibyo-wly/d607b83c15e989355513302fc5ab0303 to your computer and use it in GitHub Desktop.
merge 7 scene dataset to point cloud
import open3d as o3d
import numpy as np
from tqdm import trange
from os.path import join
FOLDER = r"E:\workspace\dataset\24_7scene\chess"
def main():
volume = o3d.pipelines.integration.ScalableTSDFVolume(
voxel_length=2.0 / 512.0,
sdf_trunc=0.04,
color_type=o3d.pipelines.integration.TSDFVolumeColorType.RGB8,
)
intrinsic = o3d.camera.PinholeCameraIntrinsic(
o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault
)
intrinsic.set_intrinsics(640, 480, 585, 585, 320, 240)
for j in range(1, 6):
for i in trange(100):
file_name = f"frame-{str(i).zfill(6)}"
camera_pose = np.loadtxt(
join(FOLDER, f"seq-{str(j).zfill(2)}", f"{file_name}.pose.txt")
)
color = o3d.io.read_image(
join(FOLDER, f"seq-{str(j).zfill(2)}", f"{file_name}.color.png")
)
depth = o3d.io.read_image(
join(FOLDER, f"seq-{str(j).zfill(2)}", f"{file_name}.depth.png")
)
rgbd = o3d.geometry.RGBDImage.create_from_color_and_depth(
color, depth, depth_trunc=4.0, convert_rgb_to_intensity=False
)
volume.integrate(rgbd, intrinsic, np.linalg.inv(camera_pose))
pcd = volume.extract_point_cloud()
# o3d.visualization.draw_geometries([pcd])
o3d.io.write_point_cloud(join(FOLDER, "pcd.ply"), pcd)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment