Search in sources :

Example 1 with Edgel

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

the class GridRansacLineDetector method convertToLineSegment.

/**
 * Lines are found in polar form and this coverts them into line segments by finding
 * the extreme points of points on the line.
 *
 * @param matchSet Set of points belonging to the line.
 * @param model Detected line.
 * @return Line segement.
 */
private LineSegment2D_F32 convertToLineSegment(List<Edgel> matchSet, LinePolar2D_F32 model) {
    float minT = Float.MAX_VALUE;
    float maxT = -Float.MAX_VALUE;
    LineParametric2D_F32 line = UtilLine2D_F32.convert(model, (LineParametric2D_F32) null);
    Point2D_F32 p = new Point2D_F32();
    for (int edgeIdx = 0; edgeIdx < matchSet.size(); edgeIdx++) {
        Edgel e = matchSet.get(edgeIdx);
        p.setTo(e.x, e.y);
        float t = ClosestPoint2D_F32.closestPointT(line, e);
        if (minT > t)
            minT = t;
        if (maxT < t)
            maxT = t;
    }
    LineSegment2D_F32 segment = new LineSegment2D_F32();
    segment.a.x = line.p.x + line.slope.x * minT;
    segment.a.y = line.p.y + line.slope.y * minT;
    segment.b.x = line.p.x + line.slope.x * maxT;
    segment.b.y = line.p.y + line.slope.y * maxT;
    return segment;
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) Edgel(boofcv.alg.feature.detect.line.gridline.Edgel) Point2D_F32(georegression.struct.point.Point2D_F32) ClosestPoint2D_F32(georegression.metric.ClosestPoint2D_F32) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 2 with Edgel

use of boofcv.alg.feature.detect.line.gridline.Edgel 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)

Example 3 with Edgel

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

the class GridRansacLineDetector method findLinesInRegion.

/**
 * Searches for lines inside inside the region..
 *
 * @param gridLines Where the found lines are stored.
 */
private void findLinesInRegion(List<LineSegment2D_F32> gridLines) {
    List<Edgel> list = edgels.copyIntoList(null);
    int iterations = 0;
    // exit if not enough points or max iterations exceeded
    while (iterations++ < maxDetectLines) {
        if (!robustMatcher.process(list))
            break;
        // remove the found edges from the main list
        List<Edgel> matchSet = robustMatcher.getMatchSet();
        // make sure the match set is large enough
        if (matchSet.size() < minInlierSize)
            break;
        for (Edgel e : matchSet) {
            list.remove(e);
        }
        gridLines.add(convertToLineSegment(matchSet, robustMatcher.getModelParameters()));
    }
}
Also used : Edgel(boofcv.alg.feature.detect.line.gridline.Edgel)

Example 4 with Edgel

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

the class CommonGridRansacLineDetectorChecks method checkObvious.

/**
 * Give it a single straight line and see if it can detect it. Allow the region size to be changed to check
 * for issues related to that
 */
protected void checkObvious(int regionSize) {
    // System.out.println("regionSize = "+regionSize);
    int where = 25;
    GrayU8 edgeImage = new GrayU8(width, height);
    D derivX = GeneralizedImageOps.createSingleBand(derivType, width, height);
    D derivY = GeneralizedImageOps.createSingleBand(derivType, width, height);
    for (int i = 0; i < height; i++) {
        edgeImage.set(where, i, 1);
        GeneralizedImageOps.set(derivX, where, i, 20);
    }
    ModelManagerLinePolar2D_F32 manager = new ModelManagerLinePolar2D_F32();
    ModelMatcherPost<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, 25, 1, manager, Edgel.class);
    matcher.setModel(() -> new GridLineModelFitter(0.9f), () -> new GridLineModelDistance(0.9f));
    GridRansacLineDetector<D> alg = createDetector(regionSize, 5, matcher);
    alg.process(derivX, derivY, edgeImage);
    MatrixOfList<LineSegment2D_F32> lines = alg.getFoundLines();
    assertEquals(width / regionSize, lines.getWidth());
    assertEquals(height / regionSize, lines.getHeight());
    int gridCol = where / regionSize;
    for (int i = 0; i < lines.height; i++) {
        List<LineSegment2D_F32> l = lines.get(gridCol, i);
        assertEquals(l.size(), 1);
        LineSegment2D_F32 a = l.get(0);
        assertTrue(Math.abs(a.slopeY()) > 1);
        assertTrue(Math.abs(a.slopeX()) < 0.01);
    }
}
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) GridLineModelDistance(boofcv.alg.feature.detect.line.gridline.GridLineModelDistance) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) Edgel(boofcv.alg.feature.detect.line.gridline.Edgel) GrayU8(boofcv.struct.image.GrayU8) GridLineModelFitter(boofcv.alg.feature.detect.line.gridline.GridLineModelFitter)

Aggregations

Edgel (boofcv.alg.feature.detect.line.gridline.Edgel)4 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)3 GridLineModelDistance (boofcv.alg.feature.detect.line.gridline.GridLineModelDistance)2 GridLineModelFitter (boofcv.alg.feature.detect.line.gridline.GridLineModelFitter)2 GrayU8 (boofcv.struct.image.GrayU8)2 ModelManagerLinePolar2D_F32 (georegression.fitting.line.ModelManagerLinePolar2D_F32)2 LinePolar2D_F32 (georegression.struct.line.LinePolar2D_F32)2 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)2 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 ClosestPoint2D_F32 (georegression.metric.ClosestPoint2D_F32)1 LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)1 Point2D_F32 (georegression.struct.point.Point2D_F32)1 BufferedImage (java.awt.image.BufferedImage)1