Пример #1
0
def test_single_point():
    '''Test measure_length function from patty.utils'''
    with np.errstate(all='raise'):
        line = np.array([[0, -1., 0]])
        expected = 0
        length = measure_length(line)
        assert_almost_equal(expected, length)
Пример #2
0
def get_stick_scale(pointcloud, eps=0.1, min_samples=20):
    """Takes a point cloud, as a numpy array, looks for red segments
    of scale sticks and returns the scale estimation with most support.
    Method:
    pointcloud --dbscan--> clusters --lengthEstimation-->
        lengths --ransac--> best length

    Arguments:
        pointcloud    Point cloud containing only measuring stick segments
                      (only the red, or only the white parts)
        eps           DBSCAN parameter: Maximum distance between two samples
                      for them to be considered as in the same neighborhood.
        min_samples   DBSCAN parameter: The number of samples in a neighborhood
                      for a point to be considered as a core point.
    Returns:
        scale         Estimate of the size of one actual meter in expressed
                      in units of the pointcloud's coordinates.
        confidence    A number expressing the reliability of the estimated
                      scale. Confidence is in [0, 1]. With a confidence greater
                      than .5, the estimate can be considered useable for
                      further calculations.
    """

    # quickly return for trivial case
    if pointcloud.size == 0:
        return 1, 0

    # find the red segments to measure
    pc_reds = extract_mask(pointcloud, get_red_mask(pointcloud))
    if len(pc_reds) == 0:
        # unit scale, zero confidence (ie. any other estimation is better)
        return 1.0, 0.0

    cluster_generator = segment_dbscan(
        pc_reds, eps, min_samples, algorithm='kd_tree')

    sizes = [{'len': len(cluster),
              'meter': measure_length(cluster) * SEGMENTS_PER_METER}
             for cluster in cluster_generator]

    if len(sizes) == 0:
        return 1.0, 0.0

    scale, votes, n_clusters = ransac(sizes)
    confidence = get_confidence_level(votes, n_clusters)
    return scale, confidence
Пример #3
0
def test_centered_line_on_x_axis():
    '''Test measure_length function from patty.utils'''
    line = np.array([[-5., 0, 0], [0, 0, 0], [5., 0, 0]])
    expected = 10
    length = measure_length(line)
    assert_almost_equal(expected, length)
Пример #4
0
def test_no_points():
    '''Test measure_length function from patty.utils'''
    line = np.array([])
    expected = 0
    length = measure_length(line)
    assert_almost_equal(expected, length)
Пример #5
0
def test_rectangle_in_y_z_plane():
    '''Test measure_length function from patty.utils'''
    line = np.array([[0, -1., 0], [0, 9., 0], [0, -1., 4], [0, 9., 4]])
    expected = 10
    length = measure_length(line)
    assert_almost_equal(expected, length)