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

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])

相关推荐

  1. OPEN3D』1.7 拟合问题

    2024-01-10 18:02:01       77 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-01-10 18:02:01       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-01-10 18:02:01       100 阅读
  3. 在Django里面运行非项目文件

    2024-01-10 18:02:01       82 阅读
  4. Python语言-面向对象

    2024-01-10 18:02:01       91 阅读

热门阅读

  1. C++牛客知识点3

    2024-01-10 18:02:01       53 阅读
  2. Msql 8.0.3X my.cnf配置字典查询

    2024-01-10 18:02:01       46 阅读
  3. sql 修改update,删除delete语句

    2024-01-10 18:02:01       48 阅读
  4. 848. 有向图的拓扑序列(拓扑排序模板题)

    2024-01-10 18:02:01       62 阅读
  5. 连续整数相加C++

    2024-01-10 18:02:01       59 阅读
  6. Linux服务器安全配置基线

    2024-01-10 18:02:01       46 阅读
  7. Golang 异常处理

    2024-01-10 18:02:01       57 阅读