目录
安装:
open3d显示点云
open3d python加载点云RGBD
SUN dataset转点云:
TUM dataset
NYU dataset
pip install open3d
import os
import open3d
import numpy as np
from random import random
import json
def loadPCD(path):
points = np.fromfile(path, dtype=np.float32).reshape(-1, 5)
points = points[:, :3]
return points
def getPointCloud(pcd: np.ndarray, colors=None):
assert len(pcd.shape) == 2 and pcd.shape[1] == 3, "invalid pcd shape: {}".format(
pcd.shape)
point_cloud = open3d.geometry.PointCloud()
point_cloud.points = open3d.utility.Vector3dVector(pcd)
if colors is not None:
assert len(colors.shape) == 2 and colors.shape[1] == 3, "invalid colors shape: {}".format(
colors.shape)
point_cloud.colors = open3d.utility.Vector3dVector(colors)
return point_cloud
def create_color_map(config_path=None, use_list=[]):
color_map = {_:[random(), random(), random()] for _ in range(32)}
if config_path:
with open(config_path,'r') as f:
tmp_map = {int(k):v for k,v in json.load(f).items()}
for _ in use_list: color_map[_] = tmp_map[_]
del tmp_map
return color_map
# # cannot show 2d image with open3d
# def getRGBImage(image: np.ndarray):
# assert len(image.shape) == 3 and (image.shape[-1]==1 or image.shape[-1] ==3), "invalid image shape: {}".format(
# image.shape)
# # print(image)
# img = open3d.geometry.Image(image)
# # print(img)
# return img
if __name__ == "__main__":
test_pcd = np.random.randn(1000, 3)
point_cloud = getPointCloud(test_pcd)
open3d.visualization.draw_geometries([point_cloud])
import open3d
import numpy as np
pcd = open3d.geometry.PointCloud()
np_points = np.random.rand(100,3)
# np_points = np.random.rand(4000,3)
pcd.points = open3d.utility.Vector3dVector(np_points)
# open3d.visualization.draw_geometries([pcd.points])
open3d.visualization.draw_geometries([pcd])
不能这样用:open3d.visualization.draw_geometries([pcd.points])
直接draw points会报错:
Did you forget to `#include `? Or ,
, , etc. Some automatic
conversions are optional and require extra headers to be included
when compiling your pybind11 module.
参考:在googlecolab使用open3d库时的open3d.visualization.draw_geometries()函数报错及解决方法_dtuyg的博客-CSDN博客
rgbd测试数据下载:
https://download.csdn.net/download/qq_41623632/13185597
1. 用Open3D分别读取RGB图片和深度图片
彩色图:
深度图:
2. 把Open3D中的RGBD图片转化pcd格式并储存
3. 显示点云
看完整代码:
这个代码不报错,但是结果不对,可能是相机标定的不对
import open3d as o3d
import matplotlib.pyplot as plt
if __name__ == "__main__":
print("Read Redwood dataset")
# color_raw = o3d.io.read_image("color.jpg")
color_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\rgbd_dataset_freiburg3_walking_xyz\rgb\1341846313.553992.png")
depth_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\rgbd_dataset_freiburg3_walking_xyz\depth\1341846313.592088.png")
# rgbd_image = o3d.geometry.RGBDImage.create_rgbd_image_from_color_and_depth(
rgbd_image = o3d.geometry.RGBDImage.create_from_color_and_depth(
color_raw, depth_raw)
print(rgbd_image)
plt.subplot(1, 2, 1)
plt.title('grayscale image')
plt.imshow(rgbd_image.color)
plt.subplot(1, 2, 2)
plt.title('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]])
o3d.io.write_point_cloud("data.ply", pcd)
o3d.visualization.draw_geometries([pcd])
# o3d.visualization.draw_geometries([pcd], zoom=0.5)
原文链接:https://blog.csdn.net/Guo_Python/article/details/106406871
def sun():
print("Read SUN dataset")
color_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\SUNRGBDLSUNTest\SUNRGBDv2Test\11082015\2015-11-08T13.42.16.610-0000006334\image\2015-11-08T13.42.16.610-0000006334.jpg")
depth_raw = o3d.io.read_image(r"F:\project\3d\Open3D-master\examples\python\SUNRGBDLSUNTest\SUNRGBDv2Test\11082015\2015-11-08T13.42.16.610-0000006334\depth\2015-11-08T13.42.16.610-0000006334.png")
rgbd_image = o3d.geometry.RGBDImage.create_from_sun_format(color_raw, depth_raw)
print(rgbd_image)
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]])
o3d.visualization.draw_geometries([pcd])
原文:
Open3d学习计划——6(RGBD图像)_o3d.geometry.image_梦醒blue的博客-CSDN博客
原文中还有: