Search in sources :

Example 6 with LinePolar2D_F32

use of georegression.struct.line.LinePolar2D_F32 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
 * @param regionSize
 */
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();
    GridLineModelDistance distance = new GridLineModelDistance(0.9f);
    GridLineModelFitter fitter = new GridLineModelFitter(0.9f);
    ModelMatcher<LinePolar2D_F32, Edgel> matcher = new Ransac<>(123123, manager, fitter, distance, 25, 1);
    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);
        assertTrue(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)

Example 7 with LinePolar2D_F32

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

the class TestGridLineModelDistance method computeDistance_list.

@Test
public void computeDistance_list() {
    float theta = (float) (Math.PI / 4.0);
    LinePolar2D_F32 l = new LinePolar2D_F32((float) (Math.sqrt(2 * 5 * 5)), theta);
    GridLineModelDistance alg = new GridLineModelDistance(0.2f);
    alg.setModel(l);
    double[] distance = new double[2];
    List<Edgel> points = new ArrayList<>();
    points.add(new Edgel(5, 5, theta));
    points.add(new Edgel(0, 0, theta));
    alg.computeDistance(points, distance);
    assertEquals(0, distance[0], 1e-4);
    assertEquals(7.0711, distance[1], 1e-4);
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 8 with LinePolar2D_F32

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

the class TestGridLineModelDistance method distance.

/**
 * Assuming two points have an angle less than the max, check the distance
 */
@Test
public void distance() {
    float theta = (float) (Math.PI / 4.0);
    LinePolar2D_F32 l = new LinePolar2D_F32((float) (Math.sqrt(2 * 5 * 5)), theta);
    GridLineModelDistance alg = new GridLineModelDistance(0.2f);
    alg.setModel(l);
    assertEquals(0, alg.computeDistance(new Edgel(5, 5, theta)), 1e-4);
    assertEquals(7.0711, alg.computeDistance(new Edgel(0, 0, theta)), 0.1);
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) Test(org.junit.Test)

Example 9 with LinePolar2D_F32

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

the class TestGridLineModelFitter method checkFailInCompatible.

/**
 * If only two points are passed in, they should fail if their orientations
 * are more than the specified tolerance apart
 */
@Test
public void checkFailInCompatible() {
    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(0, 0, (float) Math.PI / 2f));
    l.add(new Edgel(1, 0, (float) -Math.PI / 2f));
    LinePolar2D_F32 model = new LinePolar2D_F32();
    assertTrue(alg.generate(l, model));
    // this one should fail
    l.clear();
    l.add(new Edgel(0, 0, (float) Math.PI / 2f));
    l.add(new Edgel(1, 0, (float) Math.PI / 2f - 0.5f));
    assertFalse(alg.generate(l, model));
}
Also used : LinePolar2D_F32(georegression.struct.line.LinePolar2D_F32) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

LinePolar2D_F32 (georegression.struct.line.LinePolar2D_F32)9 Test (org.junit.Test)5 ModelManagerLinePolar2D_F32 (georegression.fitting.line.ModelManagerLinePolar2D_F32)3 ArrayList (java.util.ArrayList)3 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)3 ConnectLinesGrid (boofcv.alg.feature.detect.line.ConnectLinesGrid)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 GrayU8 (boofcv.struct.image.GrayU8)2 LineSegment2D_F32 (georegression.struct.line.LineSegment2D_F32)2 DetectLineSegmentsGridRansac (boofcv.abst.feature.detect.line.DetectLineSegmentsGridRansac)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 GrayS16 (boofcv.struct.image.GrayS16)1 GrayS8 (boofcv.struct.image.GrayS8)1 BufferedImage (java.awt.image.BufferedImage)1