def get_scale_factor(query_bbox, points3d_scaled, intrinsics, width=360, height=480): points2d_px_result = geo.project_3d_to_2d(points3d_scaled, intrinsics) #points2d_px_query = geo.project_3d_to_2d(points_3d_query, intrinsics) result_bbox = geo.get_bbox(points2d_px_result, width, height) #query_bbox = geo.get_bbox(points2d_px_query, width, height) scale = geo.get_bbox_area(query_bbox) / geo.get_bbox_area(result_bbox) return scale
def get_match_snapped_points(idx, match_idx, info_df, train_info_df, ground_truth=False, rescale=True, align_axis=True): assert type(match_idx)==int plane_center, plane_normal = get_plane(info_df, idx) points2d, points3d = get_points(info_df,idx) points3d_result_rotated, points3d_result = get_match_aligned_points(idx, match_idx, info_df, train_info_df, ground_truth = ground_truth) snapped, intersect = geo.snap_box_to_plane(points3d_result_rotated, plane_normal, plane_center, align_axis=align_axis) result = snapped if rescale: points2d_result, _ = get_points(train_info_df,match_idx) #points3d_result = np.array(points3d_result) camera = get_camera(info_df, idx) intrinsics = get_intrinsics(camera) intrinsics = geo.scale_intrinsics(intrinsics, 0.25, 0.25) points2d_px = geo.project_3d_to_2d(snapped, intrinsics) dest_bbox = geo.get_bbox(points2d_px, 360, 480) points2d_valid, points3d_valid = get_points(info_df, idx) valid_image = Image.open(info_df.iloc[idx]["filepath_full"]) points2d_valid_px = geo.points_2d_to_points2d_px(points2d_valid, valid_image.width, valid_image.height) valid_bbox = geo.get_bbox(points2d_valid_px, valid_image.width, valid_image.height) scale_x, scale_y = geo.get_scale_factors(dest_bbox, valid_bbox) scale_factor = (scale_x + scale_y)/2 #print(scale_factor) fixed_point = snapped[0] snapped_rotated = snapped.copy() #scale_factor = 1.2 snapped_rotated=(snapped_rotated-fixed_point)*scale_factor+fixed_point snapped_rotated, intersect=geo.snap_box_to_plane(snapped_rotated, plane_normal, plane_center) result = snapped_rotated return result, points3d_result