Search in sources :

Example 1 with LinePolar2D_F32

use of georegression.struct.line.LinePolar2D_F32 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)

Example 2 with LinePolar2D_F32

use of georegression.struct.line.LinePolar2D_F32 in project BoofCV by lessthanoptimal.

the class FactoryDetectLineAlgs method lineRansac.

/**
 * Detects line segments inside an image using the {@link DetectLineSegmentsGridRansac} algorithm.
 *
 * @param config Configuration for line detector
 * @param imageType Type of single band input image.
 * @param derivType Image derivative type.
 * @return Line segment detector
 * @see DetectLineSegmentsGridRansac
 */
public static <I extends ImageGray<I>, D extends ImageGray<D>> DetectLineSegmentsGridRansac<I, D> lineRansac(@Nullable ConfigLineRansac config, Class<I> imageType, Class<D> derivType) {
    if (config == null)
        config = new ConfigLineRansac();
    ConfigLineRansac _config = config;
    ImageGradient<I, D> gradient = FactoryDerivative.sobel(imageType, derivType);
    ModelManagerLinePolar2D_F32 manager = new ModelManagerLinePolar2D_F32();
    ModelMatcherPost<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, 25, 1, manager, Edgel.class);
    matcher.setModel(() -> new GridLineModelFitter((float) _config.thresholdAngle), () -> new GridLineModelDistance((float) _config.thresholdAngle));
    GridRansacLineDetector<D> alg;
    if (derivType == GrayF32.class) {
        alg = (GridRansacLineDetector) new ImplGridRansacLineDetector_F32(config.regionSize, 10, matcher);
    } else if (derivType == GrayS16.class) {
        alg = (GridRansacLineDetector) new ImplGridRansacLineDetector_S16(config.regionSize, 10, matcher);
    } else {
        throw new IllegalArgumentException("Unsupported derivative type");
    }
    ConnectLinesGrid connect = null;
    if (config.connectLines)
        connect = new ConnectLinesGrid(Math.PI * 0.01, 1, 8);
    return new DetectLineSegmentsGridRansac<>(alg, connect, gradient, config.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) DetectLineSegmentsGridRansac(boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) DetectLineSegmentsGridRansac(boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac)

Example 3 with LinePolar2D_F32

use of georegression.struct.line.LinePolar2D_F32 in project BoofCV by lessthanoptimal.

the class TestGridLineModelFitter method checkFit.

@Test
void checkFit() {
    GridLineModelFitter alg = new GridLineModelFitter(0.1f);
    // angle test should use half-circle and this should pass
    List<Edgel> l = new ArrayList<>();
    l.add(new Edgel(1, 0, 0f));
    l.add(new Edgel(1, 2, (float) Math.PI));
    LinePolar2D_F32 model = new LinePolar2D_F32();
    assertTrue(alg.generate(l, model));
    assertEquals(1, model.distance, 1e-4f);
    assertTrue(UtilAngle.distHalf(0, model.angle) < 1e-4f);
    // three points
    l.add(new Edgel(1, 3, (float) -Math.PI / 2f));
    assertTrue(alg.generate(l, model));
    assertEquals(1, model.distance, 1e-4f);
    assertTrue(UtilAngle.distHalf(0, model.angle) < 1e-4f);
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) ArrayList(java.util.ArrayList) Test(org.junit.jupiter.api.Test)

Example 4 with LinePolar2D_F32

use of georegression.struct.line.LinePolar2D_F32 in project BoofCV by lessthanoptimal.

the class TestGridLineModelDistance method maxAngle.

/**
 * Check to see that if two points exceed a max angle the distance is infinite
 */
@Test
void maxAngle() {
    LinePolar2D_F32 l = new LinePolar2D_F32((float) (Math.sqrt(2 * 5 * 5)), (float) (Math.PI / 4.0));
    GridLineModelDistance alg = new GridLineModelDistance(0.2f);
    alg.setModel(l);
    // standard out of bounds
    assertEquals(Double.MAX_VALUE, alg.distance(new Edgel(5, 5, (float) (Math.PI / 4.0) + 0.3f)), 1e-4);
    // standard in bounds
    assertEquals(0, alg.distance(new Edgel(5, 5, (float) (Math.PI / 4.0) + 0.1f)), 1e-4);
    // see if it respects half angle
    assertEquals(0, alg.distance(new Edgel(5, 5, (float) UtilAngle.bound(Math.PI / 4.0 + Math.PI))), 1e-4);
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) Test(org.junit.jupiter.api.Test)

Example 5 with LinePolar2D_F32

use of georegression.struct.line.LinePolar2D_F32 in project BoofCV by lessthanoptimal.

the class VisualizeLineRansac method process.

public void process(@Nullable BufferedImage image) {
    Objects.requireNonNull(image);
    // int regionSize = 40;
    I input = GeneralizedImageOps.createSingleBand(imageType, image.getWidth(), image.getHeight());
    D derivX = GeneralizedImageOps.createSingleBand(derivType, image.getWidth(), image.getHeight());
    D derivY = GeneralizedImageOps.createSingleBand(derivType, image.getWidth(), image.getHeight());
    GrayF32 edgeIntensity = new GrayF32(input.width, input.height);
    // GrayF32 suppressed =  new GrayF32(input.width,input.height);
    // GrayF32 orientation =  new GrayF32(input.width,input.height);
    // GrayS8 direction = new GrayS8(input.width,input.height);
    GrayU8 detected = new GrayU8(input.width, input.height);
    ModelManager<LinePolar2D_F32> manager = new ModelManagerLinePolar2D_F32();
    ModelMatcherPost<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, 25, 1, manager, Edgel.class);
    matcher.setModel(() -> new GridLineModelFitter((float) (Math.PI * 0.75)), () -> new GridLineModelDistance((float) (Math.PI * 0.75)));
    ImageGradient<I, D> gradient = FactoryDerivative.sobel(imageType, derivType);
    System.out.println("Image width " + input.width + " height " + input.height);
    ConvertBufferedImage.convertFromSingle(image, input, imageType);
    gradient.process(input, derivX, derivY);
    GGradientToEdgeFeatures.intensityAbs(derivX, derivY, edgeIntensity);
    // non-max suppression on the lines
    // GGradientToEdgeFeatures.direction(derivX,derivY,orientation);
    // GradientToEdgeFeatures.discretizeDirection4(orientation,direction);
    // GradientToEdgeFeatures.nonMaxSuppression4(edgeIntensity,direction,suppressed);
    GThresholdImageOps.threshold(edgeIntensity, detected, 30, false);
    GridRansacLineDetector<GrayF32> alg = new ImplGridRansacLineDetector_F32(40, 10, matcher);
    alg.process((GrayF32) derivX, (GrayF32) derivY, detected);
    MatrixOfList<LineSegment2D_F32> gridLine = alg.getFoundLines();
    // ConnectLinesGrid connect = new ConnectLinesGrid(Math.PI*0.01,1,8);
    // connect.process(gridLine);
    // LineImageOps.pruneClutteredGrids(gridLine,3);
    List<LineSegment2D_F32> found = gridLine.createSingleList();
    System.out.println("size = " + found.size());
    LineImageOps.mergeSimilar(found, (float) (Math.PI * 0.03), 5f);
    // LineImageOps.pruneSmall(found,40);
    System.out.println("after size = " + found.size());
    ImageLinePanel gui = new ImageLinePanel();
    gui.setImage(image);
    gui.setLineSegments(found);
    gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    BufferedImage renderedBinary = VisualizeBinaryData.renderBinary(detected, false, null);
    ShowImages.showWindow(renderedBinary, "Detected Edges");
    ShowImages.showWindow(gui, "Detected Lines");
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ModelManagerLinePolar2D_F32(georegression.fitting.line.ModelManagerLinePolar2D_F32) ImageLinePanel(boofcv.gui.feature.ImageLinePanel) GridLineModelDistance(boofcv.alg.feature.detect.line.gridline.GridLineModelDistance) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) Edgel(boofcv.alg.feature.detect.line.gridline.Edgel) ImplGridRansacLineDetector_F32(boofcv.alg.feature.detect.line.gridline.ImplGridRansacLineDetector_F32) GrayU8(boofcv.struct.image.GrayU8) GridLineModelFitter(boofcv.alg.feature.detect.line.gridline.GridLineModelFitter)

Aggregations

LinePolar2D_F32 (georegression.struct.line.LinePolar2D_F32)10 Test (org.junit.jupiter.api.Test)5 ModelManagerLinePolar2D_F32 (georegression.fitting.line.ModelManagerLinePolar2D_F32)4 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)4 ArrayList (java.util.ArrayList)3 DetectLineSegmentsGridRansac (boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac)2 Edgel (boofcv.alg.feature.detect.line.gridline.Edgel)2 GridLineModelDistance (boofcv.alg.feature.detect.line.gridline.GridLineModelDistance)2 GridLineModelFitter (boofcv.alg.feature.detect.line.gridline.GridLineModelFitter)2 GrayS16 (boofcv.struct.image.GrayS16)2 GrayU8 (boofcv.struct.image.GrayU8)2 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)2 ConnectLinesGrid (boofcv.alg.feature.detect.line.ConnectLinesGrid)1 GridRansacLineDetector (boofcv.alg.feature.detect.line.GridRansacLineDetector)1 ImplGridRansacLineDetector_F32 (boofcv.alg.feature.detect.line.gridline.ImplGridRansacLineDetector_F32)1 ImageLinePanel (boofcv.gui.feature.ImageLinePanel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayF32 (boofcv.struct.image.GrayF32)1 BufferedImage (java.awt.image.BufferedImage)1