Search in sources :

Example 6 with LineSegment2D_F32

use of georegression.struct.line.LineSegment2D_F32 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 (Edgel e : matchSet) {
        p.set(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 7 with LineSegment2D_F32

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

the class ImageLinePruneMerge method pruneSimilar.

public void pruneSimilar(float toleranceAngle, float toleranceDist, int imgWidth, int imgHeight) {
    sortByIntensity();
    float[] theta = new float[lines.size()];
    List<LineSegment2D_F32> segments = new ArrayList<>(lines.size());
    for (int i = 0; i < lines.size(); i++) {
        Data d = lines.get(i);
        LineParametric2D_F32 l = d.line;
        theta[i] = UtilAngle.atanSafe(l.getSlopeY(), l.getSlopeX());
        segments.add(LineImageOps.convert(l, imgWidth, imgHeight));
    }
    for (int i = 0; i < segments.size(); i++) {
        LineSegment2D_F32 a = segments.get(i);
        if (a == null)
            continue;
        for (int j = i + 1; j < segments.size(); j++) {
            LineSegment2D_F32 b = segments.get(j);
            if (b == null)
                continue;
            // see if they are nearly parallel
            if (UtilAngle.distHalf(theta[i], theta[j]) > toleranceAngle)
                continue;
            Point2D_F32 p = Intersection2D_F32.intersection(a, b, null);
            // see if it is nearly parallel and intersects inside the image
            if (p != null && p.x >= 0 && p.y >= 0 && p.x < imgWidth && p.y < imgHeight) {
                segments.set(j, null);
            } else {
                // now just see if they are very close
                float distA = Distance2D_F32.distance(a, b.a);
                float distB = Distance2D_F32.distance(a, b.b);
                if (distA <= toleranceDist || distB < toleranceDist) {
                    segments.set(j, null);
                }
            }
        }
    }
    List<Data> filtered = new ArrayList<>();
    for (int i = 0; i < segments.size(); i++) {
        if (segments.get(i) != null) {
            filtered.add(lines.get(i));
        }
    }
    lines = filtered;
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ArrayList(java.util.ArrayList) Point2D_F32(georegression.struct.point.Point2D_F32) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

Example 8 with LineSegment2D_F32

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

the class LineImageOps method mergeSimilar.

public static void mergeSimilar(List<LineSegment2D_F32> lines, float thresholdAngle, float thresholdDist) {
    for (int i = 0; i < lines.size(); i++) {
        LineSegment2D_F32 a = lines.get(i);
        double thetaA = UtilAngle.atanSafe(a.slopeY(), a.slopeX());
        // could speed up by just picking the first match, but results would depend on input order
        while (true) {
            int indexBest = -1;
            double distanceBest = thresholdDist;
            for (int j = i + 1; j < lines.size(); j++) {
                LineSegment2D_F32 b = lines.get(j);
                double thetaB = UtilAngle.atanSafe(b.slopeY(), b.slopeX());
                // see if they are nearly parallel
                if (UtilAngle.distHalf(thetaA, thetaB) > thresholdAngle)
                    continue;
                float distA = Distance2D_F32.distance(a, b.a);
                float distB = Distance2D_F32.distance(a, b.b);
                float dist = Math.min(distA, distB);
                if (dist < distanceBest) {
                    distanceBest = dist;
                    indexBest = j;
                }
            }
            if (indexBest != -1) {
                mergeIntoA(a, lines.remove(indexBest));
                thetaA = UtilAngle.atanSafe(a.slopeY(), a.slopeX());
            } else {
                break;
            }
        }
    }
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32)

Example 9 with LineSegment2D_F32

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

the class TestConnectLinesGrid method checkConnectNeighbor.

private void checkConnectNeighbor(int x, int y) {
    MatrixOfList<LineSegment2D_F32> grid = new MatrixOfList<>(3, 3);
    grid.get(1, 1).add(new LineSegment2D_F32(0, 0, 2, 3));
    grid.get(x, y).add(new LineSegment2D_F32(2, 3, 4, 6));
    ConnectLinesGrid app = new ConnectLinesGrid(0.1, 1, 1);
    app.process(grid);
    List<LineSegment2D_F32> list = grid.createSingleList();
    assertEquals(1, list.size());
    LineSegment2D_F32 l = list.get(0);
    if (l.a.x == 4) {
        Point2D_F32 temp = l.a;
        l.a = l.b;
        l.b = temp;
    }
    assertEquals(0, l.a.x, 1e-8);
    assertEquals(0, l.a.y, 1e-8);
    assertEquals(4, l.b.x, 1e-8);
    assertEquals(6, l.b.y, 1e-8);
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) MatrixOfList(boofcv.struct.feature.MatrixOfList) Point2D_F32(georegression.struct.point.Point2D_F32)

Example 10 with LineSegment2D_F32

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

the class TestConnectLinesGrid method checkParallelTolerance.

/**
 * Makes sure the parallel distance tolerance parameter is correctly set and processed
 */
@Test
public void checkParallelTolerance() {
    MatrixOfList<LineSegment2D_F32> grid = new MatrixOfList<>(1, 1);
    grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 2, 0));
    grid.get(0, 0).add(new LineSegment2D_F32(3, 0, 5, 0));
    // have the tolerance be too tight
    ConnectLinesGrid app = new ConnectLinesGrid(2, 2, 0.1);
    app.process(grid);
    assertEquals(2, grid.createSingleList().size());
    // now make the tolerance broader
    app = new ConnectLinesGrid(2, 2, 1.1);
    app.process(grid);
    assertEquals(1, grid.createSingleList().size());
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) MatrixOfList(boofcv.struct.feature.MatrixOfList) Test(org.junit.Test)

Aggregations

LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)20 Point2D_F32 (georegression.struct.point.Point2D_F32)8 MatrixOfList (boofcv.struct.feature.MatrixOfList)6 Test (org.junit.Test)5 Edgel (boofcv.alg.feature.detect.line.gridline.Edgel)3 ClosestPoint2D_F32 (georegression.metric.ClosestPoint2D_F32)3 LineParametric2D_F32 (georegression.struct.line.LineParametric2D_F32)3 ArrayList (java.util.ArrayList)3 GridLineModelDistance (boofcv.alg.feature.detect.line.gridline.GridLineModelDistance)2 GridLineModelFitter (boofcv.alg.feature.detect.line.gridline.GridLineModelFitter)2 ImageLinePanel (boofcv.gui.feature.ImageLinePanel)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 ConnectLinesGrid (boofcv.alg.feature.detect.line.ConnectLinesGrid)1 ImplGridRansacLineDetector_F32 (boofcv.alg.feature.detect.line.gridline.ImplGridRansacLineDetector_F32)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayF32 (boofcv.struct.image.GrayF32)1 GrayS8 (boofcv.struct.image.GrayS8)1