Search in sources :

Example 11 with LineSegment2D_F32

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

the class TestConnectLinesGrid method checkHalfCircleAngle.

/**
 * Orientation of two lines should be compared using the half circle angle.
 *
 * The test is designed to test that both angles are computed using atan() and compared
 * between 0 and 180 degrees
 */
@Test
public void checkHalfCircleAngle() {
    MatrixOfList<LineSegment2D_F32> grid = new MatrixOfList<>(1, 1);
    grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 0, 2));
    grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 0.001f, -2));
    ConnectLinesGrid app = new ConnectLinesGrid(0.1, 1, 1);
    app.process(grid);
    List<LineSegment2D_F32> list = grid.createSingleList();
    assertEquals(1, list.size());
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) MatrixOfList(boofcv.struct.feature.MatrixOfList) Test(org.junit.Test)

Example 12 with LineSegment2D_F32

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

the class TestConnectLinesGrid method checkTangentTolerance.

/**
 * Makes sure the tangent distance tolerance parameter is correctly set and processed
 */
@Test
public void checkTangentTolerance() {
    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(2, 1, 4, 1));
    // have the tolerance be too tight
    ConnectLinesGrid app = new ConnectLinesGrid(2, 0.1, 2);
    app.process(grid);
    assertEquals(2, grid.createSingleList().size());
    // now make the tolerance broader
    app = new ConnectLinesGrid(2, 1.1, 2);
    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)

Example 13 with LineSegment2D_F32

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

the class TestConnectLinesGrid method connectInSameRegion.

/**
 * Very basic check which sees if lines are being connected in the same region
 */
@Test
public void connectInSameRegion() {
    MatrixOfList<LineSegment2D_F32> grid = new MatrixOfList<>(1, 1);
    grid.get(0, 0).add(new LineSegment2D_F32(0, 0, 2, 3));
    grid.get(0, 0).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);
    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) Test(org.junit.Test)

Example 14 with LineSegment2D_F32

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

the class ExampleLineDetection method detectLineSegments.

/**
 * Detects segments inside the image
 *
 * @param image Input image.
 * @param imageType Type of image processed by line detector.
 * @param derivType Type of image derivative.
 */
public static <T extends ImageGray<T>, D extends ImageGray<D>> void detectLineSegments(BufferedImage image, Class<T> imageType, Class<D> derivType) {
    // convert the line into a single band image
    T input = ConvertBufferedImage.convertFromSingle(image, null, imageType);
    // Comment/uncomment to try a different type of line detector
    DetectLineSegmentsGridRansac<T, D> detector = FactoryDetectLineAlgs.lineRansac(40, 30, 2.36, true, imageType, derivType);
    List<LineSegment2D_F32> found = detector.detect(input);
    // display the results
    ImageLinePanel gui = new ImageLinePanel();
    gui.setBackground(image);
    gui.setLineSegments(found);
    gui.setPreferredSize(new Dimension(image.getWidth(), image.getHeight()));
    listPanel.addItem(gui, "Found Line Segments");
}
Also used : LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ImageLinePanel(boofcv.gui.feature.ImageLinePanel)

Example 15 with LineSegment2D_F32

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

the class LineImageOps method pruneSimilarLines.

/**
 * Prunes similar looking lines, but keeps the lines with the most intensity.
 *
 * @param lines
 * @param intensity
 * @param toleranceAngle
 * @return
 */
public static List<LineParametric2D_F32> pruneSimilarLines(List<LineParametric2D_F32> lines, float[] intensity, float toleranceAngle, float toleranceDist, int imgWidth, int imgHeight) {
    int[] indexSort = new int[intensity.length];
    QuickSort_F32 sort = new QuickSort_F32();
    sort.sort(intensity, 0, lines.size(), indexSort);
    float[] theta = new float[lines.size()];
    List<LineSegment2D_F32> segments = new ArrayList<>(lines.size());
    for (int i = 0; i < lines.size(); i++) {
        LineParametric2D_F32 l = lines.get(i);
        theta[i] = UtilAngle.atanSafe(l.getSlopeY(), l.getSlopeX());
        segments.add(convert(l, imgWidth, imgHeight));
    }
    for (int i = segments.size() - 1; i >= 0; i--) {
        LineSegment2D_F32 a = segments.get(indexSort[i]);
        if (a == null)
            continue;
        for (int j = i - 1; j >= 0; j--) {
            LineSegment2D_F32 b = segments.get(indexSort[j]);
            if (b == null)
                continue;
            if (UtilAngle.distHalf(theta[indexSort[i]], theta[indexSort[j]]) > toleranceAngle)
                continue;
            Point2D_F32 p = Intersection2D_F32.intersection(a, b, null);
            if (p != null && p.x >= 0 && p.y >= 0 && p.x < imgWidth && p.y < imgHeight) {
                segments.set(indexSort[j], null);
            } else {
                float distA = Distance2D_F32.distance(a, b.a);
                float distB = Distance2D_F32.distance(a, b.b);
                if (distA <= toleranceDist || distB < toleranceDist) {
                    segments.set(indexSort[j], null);
                }
            }
        }
    }
    List<LineParametric2D_F32> ret = new ArrayList<>();
    for (int i = 0; i < segments.size(); i++) {
        if (segments.get(i) != null) {
            ret.add(lines.get(i));
        }
    }
    return ret;
}
Also used : QuickSort_F32(org.ddogleg.sorting.QuickSort_F32) LineSegment2D_F32(georegression.struct.line.LineSegment2D_F32) ArrayList(java.util.ArrayList) Point2D_F32(georegression.struct.point.Point2D_F32) ClosestPoint2D_F32(georegression.metric.ClosestPoint2D_F32) LineParametric2D_F32(georegression.struct.line.LineParametric2D_F32)

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