def cli(frame_sequence, file_to_load, file_to_dump, show): """ FRAME_SEQUENCE path to a video file or shell-like wildcard describing multiple images """ sequence = frameseq.read_grayscale_f32(frame_sequence) if file_to_load is not None: corner_storage = load(file_to_load) else: corner_storage = build(sequence) if file_to_dump is not None: dump(corner_storage, file_to_dump) if show: click.echo( "Press 'q' to stop, 'd' to go forward, 'a' to go backward" ) frame = 0 while True: grayscale = sequence[frame] bgr = draw(grayscale, corner_storage[frame]) cv2.imshow('Frame', bgr) key = chr(cv2.waitKey(20) & 0xFF) if key == 'a' and frame > 0: frame -= 1 if key == 'd' and frame + 1 < len(corner_storage): frame += 1 if key == 'q': break
def run_tests(config, output_dir, corners_dir): # pylint:disable=too-many-locals _make_dir_if_needed(output_dir) _make_dir_if_needed(corners_dir) corners_ok_count = 0 tracking_ok_count = 0 all_r_errors = [] all_t_errors = [] for test_name, test_info in config.items(): click.echo(test_name) test_dir = path.join(output_dir, test_name) _make_dir_if_needed(test_dir, 1) grayscale_seq = frameseq.read_grayscale_f32(test_info.rgb) inf_errors = np.full((len(grayscale_seq), ), np.inf) all_r_errors.append(inf_errors) all_t_errors.append(inf_errors) corner_storage = _load_or_calculate_corners(grayscale_seq, test_name, test_dir, corners_dir) if not corner_storage: click.echo(' corner tracking failed') continue corners_ok_count += _describe_and_check_corners(corner_storage) ground_truth = _read_ground_truth(test_info.ground_truth) track, point_cloud = _do_tracking(test_info, ground_truth, corner_storage, test_dir) if not track: click.echo(' camera tracking failed') continue _write_poses(track, path.join(test_dir, 'track.yml')) _write_point_cloud(point_cloud, path.join(test_dir, 'point_cloud.yml')) r_errors, t_errors = cmptrack.calc_errors(ground_truth, track) all_r_errors[-1] = r_errors all_t_errors[-1] = t_errors tracking_ok_count += _describe_and_check_camera_track_errors( r_errors, t_errors, test_info.translation_error_allowed, test_info.rotation_deg_error_allowed) all_r_errors = np.concatenate(all_r_errors) all_t_errors = np.concatenate(all_t_errors) error_measure = cmptrack.calc_vol_under_surface(all_r_errors, all_t_errors) click.echo('corners OK: {}/{}'.format(corners_ok_count, len(config))) click.echo('tracking OK: {}/{}'.format(tracking_ok_count, len(config))) click.echo('total error measure: {}'.format(error_measure)) _write_error_measure(error_measure, path.join(output_dir, 'error_measure.yml'))
def run_tests(config, output_dir, corners_dir): # pylint:disable=too-many-locals _make_dir_if_needed(output_dir) _make_dir_if_needed(corners_dir) all_r_errors = [] all_t_errors = [] for test_name, test_info in config.items(): click.echo(test_name) test_dir = path.join(output_dir, test_name) _make_dir_if_needed(test_dir, 1) grayscale_seq = frameseq.read_grayscale_f32(test_info.rgb) inf_errors = np.full((len(grayscale_seq),), np.inf) all_r_errors.append(inf_errors) all_t_errors.append(inf_errors) corner_storage = _load_or_calculate_corners(grayscale_seq, test_name, test_dir, corners_dir) if not corner_storage: continue ground_truth = _read_ground_truth(test_info.ground_truth) track, point_cloud = _do_tracking(test_info, ground_truth, corner_storage, test_dir) if not track: continue _write_poses(track, path.join(test_dir, 'track.yml')) _write_point_cloud(point_cloud, path.join(test_dir, 'point_cloud.yml')) r_errors, t_errors = cmptrack.calc_errors(ground_truth, track) all_r_errors[-1] = r_errors all_t_errors[-1] = t_errors click.echo(' rotation error (degrees): median={}, max={}'.format( np.median(np.degrees(r_errors)), np.degrees(r_errors).max() )) click.echo(' translation error: median={}, max={}'.format( np.median(t_errors), t_errors.max() )) click.echo(' overall error measure: {}'.format( cmptrack.calc_vol_under_surface(r_errors, t_errors) )) all_r_errors = np.concatenate(all_r_errors) all_t_errors = np.concatenate(all_t_errors) error_measure = cmptrack.calc_vol_under_surface(all_r_errors, all_t_errors) click.echo('total error measure: {}'.format(error_measure)) _write_error_measure(error_measure, path.join(output_dir, 'error_measure.yml'))
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(frame_sequence, file_to_load, file_to_dump, show): """ FRAME_SEQUENCE path to a video file or shell-like wildcard describing multiple images """ sequence = frameseq.read_grayscale_f32(frame_sequence) if file_to_load is not None: corner_storage = load(file_to_load) else: corner_storage = build(sequence) if file_to_dump is not None: dump(corner_storage, file_to_dump) if show: for i, image in enumerate(sequence): im = draw(image, corner_storage[i]) cv2.imwrite('{}.png'.format(i), (im * 255).astype(np.uint8))
def run_tests(config, output_dir, corners_dir, corners_config, min_track_len): _make_dir_if_needed(output_dir) _make_dir_if_needed(corners_dir) all_r_errors = [] all_t_errors = [] for test_name, test_info in config.items(): click.echo(test_name) test_dir = path.join(output_dir, test_name) _make_dir_if_needed(test_dir, 1) grayscale_seq = frameseq.read_grayscale_f32(test_info.rgb) inf_errors = np.full((len(grayscale_seq), ), np.inf) all_r_errors.append(inf_errors) all_t_errors.append(inf_errors) corner_storage = _load_or_calculate_corners(grayscale_seq, test_name, test_dir, corners_dir, corners_config, min_track_len) if not corner_storage: continue track, point_cloud = _do_tracking(test_info, corner_storage, test_dir) if not track: continue _write_poses(track, path.join(test_dir, 'track.yml')) _write_point_cloud(point_cloud, path.join(test_dir, 'point_cloud.yml')) ground_truth = _read_ground_truth(test_info.ground_truth) r_errors, t_errors = cmp.calc_errors(ground_truth, track) all_r_errors[-1] = r_errors all_t_errors[-1] = t_errors click.echo(' error measure: {}'.format( cmp.calc_vol_under_surface(r_errors, t_errors))) all_r_errors = np.concatenate(all_r_errors) all_t_errors = np.concatenate(all_t_errors) error_measure = cmp.calc_vol_under_surface(all_r_errors, all_t_errors) click.echo('overall error measure: {}'.format(error_measure)) _write_error_measure(error_measure, path.join(output_dir, 'error_measure.yml'))