def _cli(ground_truth_file, estimate_file, plot): # pylint:disable=too-many-locals gt_track = read_poses(ground_truth_file) e_track = read_poses(estimate_file) r_errors, t_errors = calc_errors(gt_track, e_track) r_errors = np.degrees(r_errors) # pylint:disable=assignment-from-no-return r_max = r_errors.max() r_median = np.median(r_errors) r_auc = calc_auc(r_errors, MAX_ROTATION_ERR_DEG) t_max = t_errors.max() t_median = np.median(t_errors) t_auc = calc_auc(t_errors, MAX_TRANSLATION_ERR) r_line_template = 'Rotation errors (degrees)' \ '\n max = {}\n median = {}\n AUC = {}' click.echo(r_line_template.format(r_max, r_median, r_auc)) t_line_template = 'Translation errors' \ '\n max = {}\n median = {}\n AUC = {}' click.echo(t_line_template.format(t_max, t_median, t_auc)) click.echo('Volume under surface = {}'.format( calc_vol_under_surface(r_errors, t_errors, MAX_ROTATION_ERR_DEG) )) if not plot: return import matplotlib.pyplot as plt # pylint:disable=import-outside-toplevel plt.figure(1) plt.subplot(2, 2, 1) plt.plot(r_errors, 'g') plt.xlim([0, r_errors.size]) plt.xlabel('Frame') plt.ylabel('Rotation error (degrees)') plt.subplot(2, 2, 2) plt.plot(*_build_error_curve(r_errors, MAX_ROTATION_ERR_DEG), 'r') plt.xlim([0.0, MAX_ROTATION_ERR_DEG]) plt.ylim([0.0, 1.0]) plt.xlabel('Rotation error (degrees)') plt.ylabel('Frame rate') plt.subplot(2, 2, 3) plt.plot(t_errors, 'g') plt.xlim([0, t_errors.size]) plt.xlabel('Frame') plt.ylabel('Translation error') plt.subplot(2, 2, 4) plt.plot(*_build_error_curve(t_errors, MAX_TRANSLATION_ERR), 'r') plt.xlim([0.0, MAX_TRANSLATION_ERR]) plt.ylim([0.0, 1.0]) plt.xlabel('Translation error') plt.ylabel('Frame rate') plt.show()
def cli(frame_sequence, camera, track_destination, point_cloud_destination, file_to_load_corners, show, camera_poses_file, frame_1, frame_2): """ FRAME_SEQUENCE path to a video file or shell-like wildcard describing multiple images\n CAMERA intrinsic parameters of camera\n TRACK_DESTINATION path to file for dumping result camera track\n POINT_CLOUD_DESTINATION path to file for dumping result point cloud """ sequence = frameseq.read_grayscale_f32(frame_sequence) if file_to_load_corners is not None: corner_storage = load(file_to_load_corners) else: corner_storage = build(sequence) if camera_poses_file is not None and frame_1 is not None and frame_2 is not None: known_camera_poses = read_poses(camera_poses_file) known_view_1 = frame_1, known_camera_poses[frame_1] known_view_2 = frame_2, known_camera_poses[frame_2] else: known_view_1 = None known_view_2 = None camera_parameters = read_camera_parameters(camera) poses, point_cloud = track_and_calc_colors( camera_parameters, corner_storage, frame_sequence, known_view_1, known_view_2 ) write_poses(poses, track_destination) write_point_cloud(point_cloud, point_cloud_destination) if show: click.echo( "Press 'q' to stop, 'd' to go forward, 'a' to go backward, " "'r' to restart" ) frame = 0 while True: grayscale = sequence[frame] bgra = draw_residuals(grayscale, corner_storage[frame], point_cloud, camera_parameters, poses[frame]) cv2.imshow('Frame', bgra) key = chr(cv2.waitKey(20) & 0xFF) if key == 'r': frame = 0 if key == 'a' and frame > 0: frame -= 1 if key == 'd' and frame + 1 < len(corner_storage): frame += 1 if key == 'q': break
def cli(camera_parameters, poses, point_cloud): script_path = os.path.abspath(os.path.dirname(__file__)) camera_model_files = (os.path.join(script_path, 'camera_model/geometry.obj'), os.path.join(script_path, 'camera_model/texture.jpg')) renderer = CameraTrackRendererApp( camera_model_files, read_camera_parameters(camera_parameters), read_poses(poses), read_point_cloud(point_cloud)) renderer.show()
def _read_ground_truth(ground_truth_path): with open(ground_truth_path, 'r') as gt_file: return data3d.read_poses(gt_file)