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

本文介绍了如何使用Open3D库读取SUNrgbd数据集中的图像和深度信息,将其转换为RGBDImage,然后创建并显示一个点云,展示了从原始数据到三维可视化的过程。
摘要由CSDN通过智能技术生成
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])

  • 23
    点赞
  • 21
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值