コード例 #1
0
ファイル: test_pivot.py プロジェクト: mianasbat/surgerycore
def test_rank_lt_six():

    with pytest.raises(ValueError):
        file_names = glob(
            'tests/data/PivotCalibration/1378476416922755200.txt')
        arrays = [np.loadtxt(f) for f in file_names]
        matrices = np.concatenate(arrays)
        number_of_matrices = int(matrices.size / 16)
        matrices = matrices.reshape(number_of_matrices, 4, 4)
        p.pivot_calibration(matrices)
コード例 #2
0
ファイル: test_pivot.py プロジェクト: mianasbat/surgerycore
def test_rank_if_condition():

    # This test will be checking a specific if condition.
    # But at the moment I dont know what data I need
    # To get proper s_values to cover that if condition.
    with pytest.raises(ValueError):
        file_names = glob('tests/data/test_case_data.txt')
        arrays = [np.loadtxt(f) for f in file_names]
        matrices = np.concatenate(arrays)
        number_of_matrices = int(matrices.size / 16)
        matrices = matrices.reshape(number_of_matrices, 4, 4)
        p.pivot_calibration(matrices)
コード例 #3
0
ファイル: test_pivot.py プロジェクト: mianasbat/surgerycore
def test_return_value():

    file_names = glob('tests/data/PivotCalibration/*')
    arrays = [np.loadtxt(f) for f in file_names]
    matrices = np.concatenate(arrays)
    number_of_matrices = int(matrices.size / 16)
    matrices = matrices.reshape(number_of_matrices, 4, 4)
    x_values, residual_error = p.pivot_calibration(matrices)
    assert 1.838 == round(residual_error, 3)
    assert -14.476 == round(x_values[0, 0], 3)
    assert 395.143 == round(x_values[1, 0], 3)
    assert -7.558 == round(x_values[2, 0], 3)
    assert -805.285 == round(x_values[3, 0], 3)
    assert -85.448 == round(x_values[4, 0], 3)
    assert -2112.066 == round(x_values[5, 0], 3)
コード例 #4
0
ファイル: test_pivot.py プロジェクト: mianasbat/surgerycore
def test_pivot_with_ransac():

    file_names = glob('tests/data/PivotCalibration/*')
    arrays = [np.loadtxt(f) for f in file_names]
    matrices = np.concatenate(arrays)
    number_of_matrices = int(matrices.size / 16)
    matrices = matrices.reshape(number_of_matrices, 4, 4)
    model_1, residual_1 = p.pivot_calibration(matrices)
    print("Without RANSAC:" + str(model_1) + ", RMS=" + str(residual_1))
    model_2, residual_2 = p.pivot_calibration_with_ransac(
        matrices, 10, 4, 0.25)
    print("With RANSAC:" + str(model_2) + ", RMS=" + str(residual_2))
    assert residual_2 < residual_1
    model_3, residual_3 = p.pivot_calibration_with_ransac(matrices,
                                                          10,
                                                          4,
                                                          0.25,
                                                          early_exit=True)
    print("With Early Exit RANSAC:" + str(model_3) + ", RMS=" +
          str(residual_3))
コード例 #5
0
ファイル: test_pivot.py プロジェクト: mianasbat/doctest
def test_pivot():
    """Raise Not implemented error"""
    with pytest.raises(NotImplementedError):
        p.pivot_calibration(None)
コード例 #6
0
ファイル: test_pivot.py プロジェクト: mianasbat/surgerycore
def test_empty_matrices():

    with pytest.raises(TypeError):
        p.pivot_calibration(None)
コード例 #7
0
ファイル: test_pivot.py プロジェクト: mianasbat/surgerycore
def test_four_rows_matrices4x4():

    with pytest.raises(ValueError):
        p.pivot_calibration(np.arange(2, 11, dtype=float).reshape(3, 3))
コード例 #8
0
def run_pivot_calibration(tracker_type, pointer, reference, fps, number, dump):
    """
    Runs a simple grabbing loop, to sample data from a tracked pointer
    and tracked calibration object (like Medtronic, CASCination etc),
    and does pivot calibration.

    :param tracker_type: string [vega|aurora|aruco]
    :param pointer: .rom file, port number or ArUco tag number for pointer
    :param reference: .rom file, port number or ArUco tag number for reference
    :param fps: number of frames per second
    :param number: number of samples
    :param dump: if specified, file to dump data to
    """

    print("Grab Pointer: ")
    print("  tracker_type = ", tracker_type)
    print("  pointer = ", pointer)
    print("  reference = ", reference)
    print("  fps = ", fps)
    print("  number = ", number)
    print("  dump = ", dump)

    if int(number) < 1:
        raise ValueError("The number of samples must be >=1")
    if float(fps) > 500:
        raise ValueError("The number of frames per second must be <= 500")

    tracker = tf.create_tracker(tracker_type, pointer, reference)

    frames_per_second = float(fps)
    ms_per_loop = 1000.0 / frames_per_second
    number_of_samples = int(number)

    counter = 0
    samples = np.ndarray((number_of_samples, 4, 4))

    print('Starting acquisition of ' + str(number_of_samples) \
          + ' points in ' + str(ms_per_loop / 1000) + ' seconds...')

    while counter < number_of_samples:
        start = datetime.now()

        tracker_frame = tracker.get_frame()

        tracking_pointer, tracking_reference, pointer_index, reference_index \
            = pp.check_tracker_data(tracker_frame,
                                    tracker_type,
                                    pointer,
                                    reference)

        if tracking_pointer and tracking_reference:

            pointer_matrix = tracker_frame[3][pointer_index]
            reference_matrix = tracker_frame[3][reference_index]

            # Compute relative tracker position (i.e. pointer-to-reference).
            pointer_to_reference = \
                np.linalg.inv(reference_matrix) @ pointer_matrix

            samples[counter, :, :] = pointer_to_reference
            counter = counter + 1

        # This timing stuff is just to delay the loop, so we get
        # approximately the right sampling rate, without extra threads.
        end = datetime.now()
        elapsed = end - start
        sleeptime_ms = ms_per_loop - (elapsed.total_seconds() * 1000.0)

        if sleeptime_ms > 0:
            time.sleep(sleeptime_ms / 1000)

    # Now compute pivot calibration.
    pointer_offset, rms = pivot_calibration(samples)

    # Save offset.
    if dump:
        np.savetxt(dump, pointer_offset.T)

    print("Pointer offset from pivot calibration: " + str(pointer_offset.T) +
          ", RMS=" + str(rms))