我在 python 中使用 Open3D 库。除了 XYZ 坐标,还有与之相关的 RGB 值。我的代码能够识别 RGB 值,当它是 255 或 0、1 到 254 之间的任何值时,代码无法识别并且点没有关联的颜色。
import numpy as np
import open3d as o3d
import pandas as pd
import matplotlib.pyplot as plt
if __name__ == "__main__":
data = pd.read_csv("C:\\Users\\User\\Downloads\\OneDrive-2019-12-06\\3D TUNNEL SCAN.txt", sep="\t", header=None)
data.columns = ["X", "Y", "Z", "R", "G", "B"]
X = data["X"].to_numpy()
Y = data["Y"].to_numpy()
Z = data["Z"].to_numpy()
R = data["R"].to_numpy()
G = data["G"].to_numpy()
B = data["B"].to_numpy()
rgb = np.asarray([R,G,B])
rgb_t = np.transpose(rgb)
print()
print(rgb_t)
xyz = np.asarray([X,Y,Z])
xyz_t = np.transpose(xyz)
print(xyz_t)
pcd = o3d.geometry.PointCloud()
pcd = o3d.PointCloud.colors()
pcd.points = o3d.utility.Vector3dVector(xyz_t)
pcd.colors = o3d.utility.Vector3dVector(rgb_t)
o3d.io.write_point_cloud("C:\\Users\\User\\PycharmProjects\\open_3d\\Open3D-master\\examples\\TestData\\3D_scanned_data.ply", pcd)
pcd_2 = o3d.io.read_point_cloud("C:\\Users\\User\\PycharmProjects\\open_3d\\Open3D-master\\examples\\TestData\\3D_scanned_data.ply")
o3d.visualization.draw_geometries([pcd_2],window_name="Tunnel", width=700,height=700,left=50,top=50)