-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathcolored_point_cloud.py
40 lines (35 loc) · 1.36 KB
/
colored_point_cloud.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
colors = []
pcd = []
for i in range(height):
for j in range(width):
"""
Convert the pixel from depth coordinate system
to depth sensor 3D coordinate system
"""
z = depth_image[i][j]
x = (j - CX_DEPTH) * z / FX_DEPTH
y = (i - CY_DEPTH) * z / FY_DEPTH
"""
Convert the point from depth sensor 3D coordinate system
to rgb camera coordinate system:
"""
[x_RGB, y_RGB, z_RGB] = np.linalg.inv(R).dot([x, y, z]) - np.linalg.inv(R).dot(T)
"""
Convert from rgb camera coordinates system
to rgb image coordinates system:
"""
j_rgb = int((x_RGB * FX_RGB) / z_RGB + CX_RGB + width / 2)
i_rgb = int((y_RGB * FY_RGB) / z_RGB + CY_RGB)
# Add point to point cloud:
pcd.append([x, y, z])
# Add the color of the pixel if it exists:
if 0 <= j_rgb < width and 0 <= i_rgb < height:
colors.append(rgb_image[i_rgb][j_rgb] / 255)
else:
colors.append([0., 0., 0.])
# Convert to Open3D.PointCLoud:
pcd_o3d = o3d.geometry.PointCloud() # create a point cloud object
pcd_o3d.points = o3d.utility.Vector3dVector(pcd)
pcd_o3d.colors = o3d.utility.Vector3dVector(colors)
# Visualize:
o3d.visualization.draw_geometries([pcd_o3d])