|
a |
|
b/src/evaluation/visualize_gt.py |
|
|
1 |
# Visualiza ground-truth in 2D image to see whether they are accurate |
|
|
2 |
|
|
|
3 |
import os |
|
|
4 |
import pickle |
|
|
5 |
import cv2 |
|
|
6 |
import matplotlib.pyplot as plt |
|
|
7 |
from utils.triangulation import * |
|
|
8 |
from utils.trajectory_io import * |
|
|
9 |
|
|
|
10 |
|
|
|
11 |
def draw_target_point(folder_path, target_point1, target_point2): |
|
|
12 |
image1 = plt.imread(folder_path + '/color_images/cam_1.jpg') |
|
|
13 |
cv2.circle(image1, (int(target_point1[0]), int(target_point1[1])), 2, (36, 255, 12), 2, -1) |
|
|
14 |
|
|
|
15 |
plt.subplot(121) |
|
|
16 |
plt.imshow(image1) |
|
|
17 |
|
|
|
18 |
image2 = plt.imread(folder_path + '/color_images/cam_2.jpg') |
|
|
19 |
cv2.circle(image2, (int(target_point2[0]), int(target_point2[1])), 2, (36, 255, 12), 2, -1) |
|
|
20 |
|
|
|
21 |
plt.subplot(122) |
|
|
22 |
plt.imshow(image2) |
|
|
23 |
|
|
|
24 |
plt.show() |
|
|
25 |
|
|
|
26 |
|
|
|
27 |
if __name__ == '__main__': |
|
|
28 |
|
|
|
29 |
data_path = '../data' |
|
|
30 |
|
|
|
31 |
# loop through the data folder |
|
|
32 |
for SUBJECT_NAME in os.listdir(data_path): |
|
|
33 |
print("subject: ", SUBJECT_NAME) |
|
|
34 |
subject_folder_path = os.path.join(data_path, SUBJECT_NAME) |
|
|
35 |
if os.path.isfile(subject_folder_path): |
|
|
36 |
continue |
|
|
37 |
|
|
|
38 |
scan_pose = 'side' |
|
|
39 |
with open(subject_folder_path + '/' + scan_pose + '/cam_2_gt.pickle', 'rb') as f: |
|
|
40 |
ground_truth = pickle.load(f) |
|
|
41 |
target4_GT = ground_truth['target_4'] |
|
|
42 |
|
|
|
43 |
# read RGB intrinsics |
|
|
44 |
with open(subject_folder_path + '/' + scan_pose + '/intrinsics/cam_1_intrinsics.pickle', 'rb') as f: |
|
|
45 |
cam1_intr = pickle.load(f) |
|
|
46 |
|
|
|
47 |
with open(subject_folder_path + '/' + scan_pose + '/intrinsics/cam_2_intrinsics.pickle', 'rb') as f: |
|
|
48 |
cam2_intr = pickle.load(f) |
|
|
49 |
|
|
|
50 |
# read extrinsics |
|
|
51 |
camera_poses = read_trajectory(subject_folder_path + '/' + scan_pose + "/odometry.log") |
|
|
52 |
T_cam1_base = camera_poses[0].pose |
|
|
53 |
T_base_cam1 = np.linalg.inv(T_cam1_base) |
|
|
54 |
T_cam2_base = camera_poses[1].pose |
|
|
55 |
T_base_cam2 = np.linalg.inv(T_cam2_base) |
|
|
56 |
|
|
|
57 |
target4_2d_cam1 = from_homog(cam1_intr @ T_base_cam1[0:3, :] @ to_homog(target4_GT)).squeeze() |
|
|
58 |
target4_2d_cam2 = from_homog(cam2_intr @ T_base_cam2[0:3, :] @ to_homog(target4_GT)).squeeze() |
|
|
59 |
|
|
|
60 |
draw_target_point(subject_folder_path + '/' + scan_pose, target4_2d_cam1, target4_2d_cam2) |
|
|
61 |
|
|
|
62 |
scan_pose = 'front' |
|
|
63 |
with open(subject_folder_path + '/' + scan_pose + '/cam_2_gt.pickle', 'rb') as f: |
|
|
64 |
ground_truth = pickle.load(f) |
|
|
65 |
target1_GT = ground_truth['target_1'] |
|
|
66 |
target2_GT = ground_truth['target_2'] |
|
|
67 |
|
|
|
68 |
# read RGB intrinsics |
|
|
69 |
with open(subject_folder_path + '/' + scan_pose + '/intrinsics/cam_1_intrinsics.pickle', 'rb') as f: |
|
|
70 |
cam1_intr = pickle.load(f) |
|
|
71 |
|
|
|
72 |
with open(subject_folder_path + '/' + scan_pose + '/intrinsics/cam_2_intrinsics.pickle', 'rb') as f: |
|
|
73 |
cam2_intr = pickle.load(f) |
|
|
74 |
|
|
|
75 |
# read extrinsics |
|
|
76 |
camera_poses = read_trajectory(subject_folder_path + '/' + scan_pose + "/odometry.log") |
|
|
77 |
T_cam1_base = camera_poses[0].pose |
|
|
78 |
T_base_cam1 = np.linalg.inv(T_cam1_base) |
|
|
79 |
T_cam2_base = camera_poses[1].pose |
|
|
80 |
T_base_cam2 = np.linalg.inv(T_cam2_base) |
|
|
81 |
|
|
|
82 |
target1_2d_cam1 = from_homog(cam1_intr @ T_base_cam1[0:3, :] @ to_homog(target1_GT)).squeeze() |
|
|
83 |
target1_2d_cam2 = from_homog(cam2_intr @ T_base_cam2[0:3, :] @ to_homog(target1_GT)).squeeze() |
|
|
84 |
|
|
|
85 |
target2_2d_cam1 = from_homog(cam1_intr @ T_base_cam1[0:3, :] @ to_homog(target2_GT)).squeeze() |
|
|
86 |
target2_2d_cam2 = from_homog(cam2_intr @ T_base_cam2[0:3, :] @ to_homog(target2_GT)).squeeze() |
|
|
87 |
|
|
|
88 |
draw_target_point(subject_folder_path + '/' + scan_pose, target1_2d_cam1, target1_2d_cam2) |
|
|
89 |
draw_target_point(subject_folder_path + '/' + scan_pose, target2_2d_cam1, target2_2d_cam2) |