Search in sources :

Example 1 with GridRansacLineDetector

use of boofcv.alg.feature.detect.line.GridRansacLineDetector in project BoofCV by lessthanoptimal.

the class FactoryDetectLineAlgs method lineRansac.

/**
 * Detects line segments inside an image using the {@link DetectLineSegmentsGridRansac} algorithm.
 *
 * @see DetectLineSegmentsGridRansac
 *
 * @param regionSize Size of the region considered.  Try 40 and tune.
 * @param thresholdEdge Threshold for determining which pixels belong to an edge or not. Try 30 and tune.
 * @param thresholdAngle Tolerance in angle for allowing two edgels to be paired up, in radians.  Try 2.36
 * @param connectLines Should lines be connected and optimized.
 * @param imageType Type of single band input image.
 * @param derivType Image derivative type.
 * @return Line segment detector
 */
public static <I extends ImageGray<I>, D extends ImageGray<D>> DetectLineSegmentsGridRansac<I, D> lineRansac(int regionSize, double thresholdEdge, double thresholdAngle, boolean connectLines, Class<I> imageType, Class<D> derivType) {
    ImageGradient<I, D> gradient = FactoryDerivative.sobel(imageType, derivType);
    ModelManagerLinePolar2D_F32 manager = new ModelManagerLinePolar2D_F32();
    GridLineModelDistance distance = new GridLineModelDistance((float) thresholdAngle);
    GridLineModelFitter fitter = new GridLineModelFitter((float) thresholdAngle);
    ModelMatcher<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, manager, fitter, distance, 25, 1);
    GridRansacLineDetector<D> alg;
    if (derivType == GrayF32.class) {
        alg = (GridRansacLineDetector) new ImplGridRansacLineDetector_F32(regionSize, 10, matcher);
    } else if (derivType == GrayS16.class) {
        alg = (GridRansacLineDetector) new ImplGridRansacLineDetector_S16(regionSize, 10, matcher);
    } else {
        throw new IllegalArgumentException("Unsupported derivative type");
    }
    ConnectLinesGrid connect = null;
    if (connectLines)
        connect = new ConnectLinesGrid(Math.PI * 0.01, 1, 8);
    return new DetectLineSegmentsGridRansac<>(alg, connect, gradient, thresholdEdge, imageType, derivType);
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) GrayS16(boofcv.struct.image.GrayS16) GridRansacLineDetector(boofcv.alg.feature.detect.line.GridRansacLineDetector) DetectLineSegmentsGridRansac(boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) DetectLineSegmentsGridRansac(boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac) ConnectLinesGrid(boofcv.alg.feature.detect.line.ConnectLinesGrid)

Aggregations

DetectLineSegmentsGridRansac (boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac)1 ConnectLinesGrid (boofcv.alg.feature.detect.line.ConnectLinesGrid)1 GridRansacLineDetector (boofcv.alg.feature.detect.line.GridRansacLineDetector)1 GrayS16 (boofcv.struct.image.GrayS16)1 ModelManagerLinePolar2D_F32 (georegression.fitting.line.ModelManagerLinePolar2D_F32)1 LinePolar2D_F32 (georegression.struct.line.LinePolar2D_F32)1 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)1