Open3D Python加载点云RGBD生成彩色点云

发布时间:2024年01月10日
import open3d as o3d
import numpy as np
import matplotlib.pyplot as plt
import os
import sys

# monkey patches visualization and provides helpers to load geometries
sys.path.append('..')
# import open3d_tutorial as o3dtut
# change to True if you want to interact with the visualization windows
# o3dtut.interactive = not "CI" in os.environ

print("Read SUN dataset")
color_raw = o3d.io.read_image(
    r"D:\sunrgbd\sunrgbd_trainval\image\000001.jpg")
depth_raw = o3d.io.read_image(
    r"D:sunrgbd\sunrgbd_trainval\depth_png\000001.png")
rgbd_image = o3d.geometry.RGBDImage.create_from_sun_format(color_raw, depth_raw)
print(rgbd_image)

# attention, the depth is nonzero, the point will be constructed
rows, columns = np.nonzero(np.asarray(rgbd_image.depth))

plt.subplot(1, 2, 1)
plt.title('SUN grayscale image')
plt.imshow(rgbd_image.color)
plt.subplot(1, 2, 2)
plt.title('SUN depth image')
plt.imshow(rgbd_image.depth)
plt.show()

pcd = o3d.geometry.PointCloud.create_from_rgbd_image(
    rgbd_image,
    o3d.camera.PinholeCameraIntrinsic(
        o3d.camera.PinholeCameraIntrinsicParameters.PrimeSenseDefault))
# Flip it, otherwise the pointcloud will be upside down
pcd.transform([[1, 0, 0, 0], [0, -1, 0, 0], [0, 0, -1, 0], [0, 0, 0, 1]])

color_condidate = []
# get the rgb color
color_list = np.asarray(color_raw)/255
# according the index information, to fill the color at the point
for x, y in zip(rows, columns):
    color_condidate.append(color_list[x][y])

point_cloud = o3d.geometry.PointCloud()
point_cloud.points = o3d.utility.Vector3dVector(np.asarray(pcd.points)) # 
# color = [1, 0, 0]
# colors = [color for i in range(len(np.asarray(pcd.points)))]
point_cloud.colors = o3d.utility.Vector3dVector(color_condidate) # 

o3d.visualization.draw_geometries([point_cloud])

文章来源:https://blog.csdn.net/physuleo/article/details/135508635
本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。