示例#1
0
def test_saving_calibrations(extension, make_temp_file):
    original_params = get_fake_calibration_parameters(200)
    calibrations_file = Path(make_temp_file("." + extension))
    save_calibrations(original_params, calibrations_file)
    read_params = parse_calibration_file(calibrations_file)
    assert read_params[0].tolist() == original_params[0].tolist()
    assert read_params[1].tolist() == original_params[1].tolist()
示例#2
0
def main():
    args = parse_args()
    logging.basicConfig(
        level=logging.NOTSET if args.verbose else logging.INFO,
        format="[%(levelname)s]: %(message)s",
    )
    logging.info("Creating calibration image...")
    camera = Camera(args.id, marker_dict=MarkerDict.DICT_6X6_250)

    board_image, board = create_board(camera, board_size=5)
    cv2.imshow("Calibration Board", board_image)
    cv2.waitKey(1)

    logging.info("Waiting until markers in view...")
    wait_for_markers(camera)

    logging.info("Capturing frames...")
    all_ids, all_corners = capture_frames(args.frames, camera, board)

    cv2.destroyAllWindows()
    image_size = cv2.cvtColor(camera.capture_frame(), cv2.COLOR_BGR2GRAY).shape
    del camera  # Explicitly close the camera so the light turns off

    logging.info("Processing frames...")
    camera_matrix, distance_coefficients = process_frames(
        all_ids, all_corners, image_size, board)

    logging.info("Saving calibration...")
    calibration_params = CalibrationParameters(camera_matrix,
                                               distance_coefficients)

    save_calibrations(calibration_params, "calibrations.xml")
    logging.info("Calibrations saved to 'calibrations.xml'")
示例#3
0
def test_parse_calibrations_json(
    benchmark: Callable,
    fake_calibration_params: CalibrationParameters,
    make_temp_file: Callable[[str], Path],
) -> None:
    temp_file = Path(make_temp_file(".json"))
    save_calibrations(fake_calibration_params, temp_file)
    benchmark(parse_calibration_file.__wrapped__, temp_file)
示例#4
0
def test_parse_calibrations_json(benchmark, fake_calibration_params, make_temp_file):
    temp_file = Path(make_temp_file(".json"))
    save_calibrations(fake_calibration_params, temp_file)
    benchmark(parse_calibration_file.__wrapped__, temp_file)
示例#5
0
def test_cant_save_invalid_extension():
    with pytest.raises(ValueError) as e:
        save_calibrations(get_fake_calibration_parameters(200),
                          Path("test.unknown"))
    assert "Unknown calibration file format" in e.value.args[0]