-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathploting.py
More file actions
69 lines (61 loc) · 1.96 KB
/
ploting.py
File metadata and controls
69 lines (61 loc) · 1.96 KB
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import numpy as np
import matplotlib.pyplot as plt
from common import Camera
def plot_points_cloud(X: np.ndarray, colors: np.ndarray=None, cameras: list = None) -> None:
"""
Plot 3D points cloud
:param X: 3D points (3xN)
:param colors: Color of the points (3xN)
:param cameras: List of cameras
"""
fig = plt.figure()
ax = fig.add_subplot(111, projection='3d')
ax.view_init(-60, -90)
ax.set_xlim([-1.5, 1.5])
ax.set_ylim([-3, 1])
ax.set_zlim([-1, 5])
if colors is None:
# green color
colors = np.zeros((3, X.shape[1]))
colors[1] = 0.7
ax.scatter(X[0], X[1], X[2], c=colors.T, marker='o', s=1)
for camera in cameras:
C = -camera.R.T @ camera.t
ax.scatter(C[0], C[1], C[2], c='b', marker='o')
# direction vector of the camera
d = camera.get_optical_axis()
ax.quiver(C[0], C[1], C[2], d[0], d[1], d[2], color='r', length=1, normalize=True)
ax.set_xlabel('X')
ax.set_ylabel('Y')
ax.set_zlabel('Z')
plt.show()
def plot_rectified_images(img1_rect, img2_rect) -> None:
plt.figure()
plt.subplot(1, 2, 1)
plt.imshow(img1_rect, cmap='gray')
plt.title('Rectified image 1')
plt.subplot(1, 2, 2)
plt.imshow(img2_rect, cmap='gray')
plt.title('Rectified image 2')
plt.show()
def plot_disparity_map(disparity) -> None:
plt.figure()
plt.imshow(disparity, cmap='jet')
plt.colorbar()
plt.title('Disparity map')
plt.show()
if __name__ == '__main__':
# load point cloud
import open3d as o3d
point_cloud = o3d.io.read_point_cloud("scene/out_sparse.ply")
# Convert to NumPy array
X = np.asarray(point_cloud.points).T
colors = np.asarray(point_cloud.colors).T
# load cameras
cameras = []
for i in range(12):
camera = Camera(id=i)
camera.load(f"scene/cameras/camera{i}.txt")
cameras.append(camera)
# display point cloud
plot_points_cloud(X, colors, cameras=cameras)