Search in sources :

Example 41 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestFitLinesToContour method linesIntoCorners.

@Test
void linesIntoCorners() {
    FitLinesToContour alg = new FitLinesToContour();
    alg.contour = createSquare(10, 12, 30, 40);
    DogArray_I32 corners = createSquareCorners(10, 12, 30, 40);
    // first generate the lines it will fit
    alg.lines.resize(3);
    alg.anchor0 = 1;
    alg.fitLinesUsingCorners(3, corners);
    // now extract the corners
    DogArray_I32 found = new DogArray_I32(corners.size);
    found.resize(corners.size());
    alg.anchor0 = 1;
    alg.linesIntoCorners(3, found);
    // only corners 2 and 3 should be updated with no change
    for (int i = 2; i < found.size(); i++) {
        assertEquals(corners.get(i), found.get(i));
    }
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Example 42 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestFitLinesToContour method fitLinesUsingCorners.

@Test
void fitLinesUsingCorners() {
    FitLinesToContour alg = new FitLinesToContour();
    alg.contour = createSquare(10, 12, 30, 40);
    DogArray_I32 corners = createSquareCorners(10, 12, 30, 40);
    alg.lines.resize(3);
    alg.anchor0 = 1;
    alg.fitLinesUsingCorners(3, corners);
    LineGeneral2D_F64 expected = new LineGeneral2D_F64();
    for (int i = 0; i < 3; i++) {
        alg.fitLine(corners.get((i + 1) % 4), corners.get((i + 2) % 4), expected);
        LineGeneral2D_F64 found = alg.lines.get(i);
        assertEquals(expected.A, found.A, 1e-8);
        assertEquals(expected.B, found.B, 1e-8);
        assertEquals(expected.C, found.C, 1e-8);
    }
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Example 43 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestRefinePolyLineCorner method fit_six_sides.

/**
 * Fit six sided shape
 */
@Test
void fit_six_sides() {
    List<Point2D_I32> points = new ArrayList<>();
    addPoints(0, 0, 20, 0, points);
    addPoints(20, 0, 20, 20, points);
    addPoints(20, 20, 40, 20, points);
    addPoints(40, 20, 40, 40, points);
    addPoints(40, 40, 0, 40, points);
    addPoints(0, 40, 0, 0, points);
    DogArray_I32 corners = new DogArray_I32();
    corners.add(0);
    corners.add(20);
    corners.add(40);
    corners.add(60);
    corners.add(80);
    corners.add(120);
    RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
    for (int i = 0; i < 10; i++) {
        // noise up the inputs
        for (int j = 0; j < corners.size(); j++) {
            corners.data[j] = CircularIndex.addOffset(corners.data[j], rand.nextInt(10) - 5, points.size());
        }
        assertTrue(alg.fit(points, corners));
        assertEquals(0, corners.get(0));
        assertEquals(20, corners.get(1));
        assertEquals(40, corners.get(2));
        assertEquals(60, corners.get(3));
        assertEquals(80, corners.get(4));
        assertEquals(120, corners.get(5));
    }
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Example 44 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestRefinePolyLineCorner method fit_quad_segment.

/**
 * Fit to a square, but only a disconnected polyline on 3 sides
 */
@Test
void fit_quad_segment() {
    int x0 = 10, y0 = 15;
    int x1 = 60, y1 = 99;
    List<Point2D_I32> points = new ArrayList<>();
    addPoints(x0, y0, x1, y0, points);
    addPoints(x1, y0, x1, y1, points);
    addPoints(x1, y1, x0, y1, points);
    RefinePolyLineCorner alg = new RefinePolyLineCorner(false);
    for (int i = 0; i < 10; i++) {
        DogArray_I32 corners = new DogArray_I32();
        corners.add(0);
        corners.add(50 + rand.nextInt(6) - 3);
        corners.add(50 + 84 + rand.nextInt(6) - 3);
        corners.add(points.size() - 1);
        assertTrue(alg.fit(points, corners));
        assertEquals(0, corners.get(0));
        assertEquals(50, corners.get(1));
        assertEquals(134, corners.get(2));
        assertEquals(points.size() - 1, corners.get(3));
    }
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Example 45 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestRefinePolyLineCorner method fit_quad.

/**
 * Fit to a square
 */
@Test
void fit_quad() {
    int x0 = 10, y0 = 15;
    int x1 = 60, y1 = 99;
    List<Point2D_I32> points = new ArrayList<>();
    addPoints(x0, y0, x1, y0, points);
    addPoints(x1, y0, x1, y1, points);
    addPoints(x1, y1, x0, y1, points);
    addPoints(x0, y1, x0, y0, points);
    RefinePolyLineCorner alg = new RefinePolyLineCorner(true);
    DogArray_I32 corners = new DogArray_I32();
    corners.add(0);
    corners.add(50);
    corners.add(50 + 84);
    corners.add(50 + 84 + 50);
    assertTrue(alg.fit(points, corners));
    assertEquals(0, corners.get(0));
    assertEquals(50, corners.get(1));
    assertEquals(134, corners.get(2));
    assertEquals(184, corners.get(3));
}
Also used : ArrayList(java.util.ArrayList) Point2D_I32(georegression.struct.point.Point2D_I32) DogArray_I32(org.ddogleg.struct.DogArray_I32) Test(org.junit.jupiter.api.Test)

Aggregations

DogArray_I32 (org.ddogleg.struct.DogArray_I32)192 Test (org.junit.jupiter.api.Test)73 Point2D_I32 (georegression.struct.point.Point2D_I32)24 ArrayList (java.util.ArrayList)21 Point2D_F64 (georegression.struct.point.Point2D_F64)17 DogArray (org.ddogleg.struct.DogArray)17 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)15 GrayS32 (boofcv.struct.image.GrayS32)10 VerbosePrint (org.ddogleg.struct.VerbosePrint)7 View (boofcv.alg.structure.PairwiseImageGraph.View)6 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)6 GrayI (boofcv.struct.image.GrayI)5 Point3D_F64 (georegression.struct.point.Point3D_F64)5 GrowArray (pabeles.concurrency.GrowArray)5 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)4 BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)4 AssociatedTripleIndex (boofcv.struct.feature.AssociatedTripleIndex)4 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)3 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)3 ConfigAssociateGreedy (boofcv.factory.feature.associate.ConfigAssociateGreedy)3