1010import open3d as o3d
1111import tqdm
1212
13- from roman .map .map import Submap , SubmapParams , submaps_from_roman_map , load_roman_map
13+ from roman .map .map import ROMANMap
1414from roman .align .results import SubmapAlignResults , plot_align_results , submaps_from_align_results
1515from roman .params .data_params import DataParams
1616from roman .viz import visualize_segment_on_img
1717from roman .align .align_viz import create_association_geometries , create_ptcld_geometries
1818
1919from robotdatapy import transform
2020from robotdatapy .exceptions import NoDataNearTimeException
21+ import robotdatapy as rdp
2122
2223@dataclass
2324class VideoParams :
@@ -90,6 +91,8 @@ def rotate_pixel_coords(coords, img_w, img_h, rotation_code):
9091 pkl_file .close ()
9192
9293 submaps = submaps_from_align_results (results )
94+ roman_map_paths = results .submap_io .inputs
95+ roman_maps = [ROMANMap .from_pickle (roman_map_paths [i ]) for i in range (2 )]
9396
9497 print (f'Loaded { len (submaps [0 ])} and { len (submaps [1 ])} submaps.' )
9598
@@ -152,8 +155,13 @@ def rotate_pixel_coords(coords, img_w, img_h, rotation_code):
152155 pose_data = []
153156 for i in range (2 ):
154157 os .environ [data_params [i ].run_env ] = args .runs [i ]
155- pose_data .append (data_params [i ].load_pose_data ())
156- pose_data [- 1 ].time_tol = 20.0
158+ # for now, use the sparser trajectory from roman map for faster load time
159+ # pose_data.append(data_params[i].load_pose_data())
160+ # pose_data[-1].time_tol = 20.0
161+ new_pose_data = rdp .data .PoseData .from_times_and_poses (roman_maps [i ].times , roman_maps [i ].trajectory )
162+ new_pose_data .time_tol = 20.0
163+ new_pose_data .T_postmultiply = np .linalg .inv (data_params [i ].pose_data_params .T_camera_flu )
164+ pose_data .append (new_pose_data )
157165
158166 print (f"Loading image data..." )
159167 img_data = []
@@ -166,6 +174,8 @@ def rotate_pixel_coords(coords, img_w, img_h, rotation_code):
166174 img_h = img_data [0 ].camera_params .height
167175 o3d_h = img_data [0 ].camera_params .height * 2
168176 o3d_w = int (o3d_h * vid_params .img_ratio - img_w )
177+ # Assumes both cameras have the same width/height aspect ratio
178+ img1_scale = img_w / img_data [1 ].camera_params .width
169179 if vid_params .camera_only :
170180 vid_w = img_w * 2
171181 vid_h = img_h
@@ -233,6 +243,8 @@ def rotate_pixel_coords(coords, img_w, img_h, rotation_code):
233243 # rotate image if specified
234244 if vid_params .img_rotations [i ] is not None :
235245 img_i = cv .rotate (img_i , vid_params .img_rotations [i ])
246+ if i == 1 and not np .isclose (img1_scale , 1.0 ):
247+ img_i = cv .resize (img_i , dsize = (img_w , img_h ))
236248 if not vid_params .camera_only :
237249 viz_img [img_h * i :img_h * (i + 1 ), o3d_w :] = img_i
238250 else :
@@ -254,6 +266,8 @@ def rotate_pixel_coords(coords, img_w, img_h, rotation_code):
254266 continue
255267 if vid_params .img_rotations [i ] is not None :
256268 new_outline = rotate_pixel_coords (new_outline , img_w , img_h , vid_params .img_rotations [i ])
269+ if i == 1 :
270+ new_outline *= img1_scale
257271 seg_pixels .append (new_outline + pixel_offset )
258272 if not success :
259273 continue
0 commit comments