예제 #1
0
def test_centered_line_on_x_axis():
    '''Test get_red_mask function from patty.segmentation.segRedStick'''
    # Arrange
    ar = np.asarray([[0, 0, 0, 210, 25, 30],
                     [0, 0, 0, 0, 0, 150],
                     [0, 0, 0, 0, 150, 70]], dtype=np.float32)
    pc = pcl.PointCloudXYZRGB(ar)

    expected = 1

    # Act
    reds = get_red_mask(pc)

    # Assert
    assert_almost_equal(sum(reds), expected)
예제 #2
0
def test_centered_line_on_x_axis():
    '''Test get_red_mask function from patty.segmentation.segRedStick'''
    # Arrange
    ar = np.asarray(
        [[0, 0, 0, 210, 25, 30], [0, 0, 0, 0, 0, 150], [0, 0, 0, 0, 150, 70]],
        dtype=np.float32)
    pc = pcl.PointCloudXYZRGB(ar)

    expected = 1

    # Act
    reds = get_red_mask(pc)

    # Assert
    assert_almost_equal(sum(reds), expected)
예제 #3
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
예제 #4
0
#!/usr/bin/env python
"""Segment points by colour from a pointcloud file and saves all reddish points
target pointcloud file. Autodectects ply, pcd and las files.

Usage: redstickdetection.py  [-h] <infile> <outfile>
"""

from docopt import docopt
from patty.segmentation.segRedStick import get_red_mask
from patty.utils import extract_mask, load, save

if __name__ == '__main__':
    args = docopt(__doc__)

    pc = load(args['<infile>'])
    red_pc = extract_mask(pc, get_red_mask(pc))
    save(red_pc, args['<outfile>'])