Search in sources :

Example 6 with LineGeneral2D_F64

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

the class TestFitLinesToContour method fitLine.

@Test
public void fitLine() {
    FitLinesToContour alg = new FitLinesToContour();
    // create the rectangle so that two sizes are less than max samples and the other two more
    int w = alg.maxSamples;
    alg.contour = createSquare(10, 12, 10 + w - 1, 12 + w + 4);
    GrowQueue_I32 corners = createSquareCorners(10, 12, 10 + w - 1, 12 + w + 4);
    LineGeneral2D_F64 line = new LineGeneral2D_F64();
    for (int i = 0, j = corners.size() - 1; i < corners.size(); j = i, i++) {
        alg.fitLine(corners.get(j), corners.get(i), line);
        // see if the line lies perfectly along the side
        int contour0 = corners.get(j);
        int contour1 = corners.get(i);
        int length = CircularIndex.distanceP(contour0, contour1, alg.contour.size());
        for (int k = 0; k < length; k++) {
            int contourIndex = CircularIndex.addOffset(contour0, k, alg.contour.size());
            Point2D_I32 p = alg.contour.get(contourIndex);
            double found = Distance2D_F64.distance(line, new Point2D_F64(p.x, p.y));
            assertEquals(0, found, 1e-8);
        }
    }
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Point2D_I32(georegression.struct.point.Point2D_I32) GrowQueue_I32(org.ddogleg.struct.GrowQueue_I32) Test(org.junit.Test)

Example 7 with LineGeneral2D_F64

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

the class TestSnapToLineEdge method localToGlobal.

@Test
public void localToGlobal() {
    LineSegment2D_F64 segment = new LineSegment2D_F64(10, 20, 50, -10);
    SnapToLineEdge alg = new SnapToLineEdge(10, 2, GrayU8.class);
    alg.center.set(20, 23);
    alg.localScale = 10;
    LineSegment2D_F64 local = segment.copy();
    toLocal(local.a, alg);
    toLocal(local.b, alg);
    LineGeneral2D_F64 expected = new LineGeneral2D_F64();
    LineGeneral2D_F64 found = new LineGeneral2D_F64();
    UtilLine2D_F64.convert(segment, expected);
    UtilLine2D_F64.convert(local, found);
    alg.localToGlobal(found);
    expected.normalize();
    found.normalize();
    assertEquals(expected.A, found.A, 1e-8);
    assertEquals(expected.B, found.B, 1e-8);
    assertEquals(expected.C, found.C, 1e-8);
}
Also used : LineSegment2D_F64(georegression.struct.line.LineSegment2D_F64) LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Test(org.junit.Test)

Example 8 with LineGeneral2D_F64

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

the class TestSnapToLineEdge method fit_noisy_affine.

public void fit_noisy_affine(Affine2D_F64 affine, Class imageType) {
    setup(affine, imageType);
    double tol = 0.5;
    SnapToLineEdge alg = new SnapToLineEdge(10, 2, imageType);
    Polygon2D_F64 input = new Polygon2D_F64(4);
    AffinePointOps_F64.transform(affine, new Point2D_F64(x0, y0), input.get(0));
    AffinePointOps_F64.transform(affine, new Point2D_F64(x0, y1), input.get(1));
    AffinePointOps_F64.transform(affine, new Point2D_F64(x1, y1), input.get(2));
    AffinePointOps_F64.transform(affine, new Point2D_F64(x1, y0), input.get(3));
    LineGeneral2D_F64[] found = new LineGeneral2D_F64[input.size()];
    for (int i = 0; i < found.length; i++) {
        found[i] = new LineGeneral2D_F64();
    }
    for (int i = 0; i < 10; i++) {
        // add some noise
        Polygon2D_F64 noisy = input.copy();
        addNoise(noisy, 2);
        alg.setImage(image);
        for (int j = 0; j < noisy.size(); j++) {
            LineSegment2D_F64 edge = noisy.getLine(j, null);
            double slopeX = edge.slopeX();
            double slopeY = edge.slopeY();
            double r = Math.sqrt(slopeX * slopeX + slopeY * slopeY);
            slopeX /= r;
            slopeY /= r;
            // shrink it slightly to avoid weirdness along the corner
            edge.a.x += 2 * slopeX;
            edge.a.y += 2 * slopeY;
            edge.b.x -= 2 * slopeX;
            edge.b.y -= 2 * slopeY;
            // optimize it a few times to get a good solution
            for (int k = 0; k < 5; k++) {
                assertTrue(alg.refine(edge.a, edge.b, found[j]));
                edge.a.set(ClosestPoint2D_F64.closestPoint(found[j], edge.a, null));
                edge.b.set(ClosestPoint2D_F64.closestPoint(found[j], edge.b, null));
            }
        }
        // compute the corners and see how it did
        for (int j = 0; j < input.size(); j++) {
            int k = (j + 1) % input.size();
            Point2D_F64 c = new Point2D_F64();
            Intersection2D_F64.intersection(found[j], found[k], c);
            double d = c.distance(input.get(k));
            assertTrue(d <= tol);
        }
    }
}
Also used : LineSegment2D_F64(georegression.struct.line.LineSegment2D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) ClosestPoint2D_F64(georegression.metric.ClosestPoint2D_F64) LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 9 with LineGeneral2D_F64

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

the class TestSnapToLineEdge method checkIdentical.

private void checkIdentical(LineSegment2D_F64 expectedLS, LineGeneral2D_F64 found) {
    LineGeneral2D_F64 expected = new LineGeneral2D_F64();
    UtilLine2D_F64.convert(expectedLS, expected);
    expected.normalize();
    found.normalize();
    if (Math.signum(expected.C) != Math.signum(found.C)) {
        expected.A *= -1;
        expected.B *= -1;
        expected.C *= -1;
    }
    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)

Example 10 with LineGeneral2D_F64

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

the class TestSnapToLineEdge method differentInitial.

private void differentInitial(SnapToLineEdge alg, LineSegment2D_F64 segment) {
    Vector2D_F64 v = new Vector2D_F64();
    v.x = -segment.slopeY();
    v.y = segment.slopeX();
    v.normalize();
    LineGeneral2D_F64 found = new LineGeneral2D_F64();
    // try
    for (int i = -1; i <= 1; i++) {
        LineSegment2D_F64 work = segment.copy();
        work.a.x += i * v.x;
        work.a.y += i * v.y;
        work.b.x += i * v.x;
        work.b.y += i * v.y;
        assertTrue(alg.refine(work.a, work.b, found));
        checkIdentical(segment, found);
        // do it in the other direction. shouldn't matter
        assertTrue(alg.refine(work.b, work.a, found));
        checkIdentical(segment, found);
    }
}
Also used : LineSegment2D_F64(georegression.struct.line.LineSegment2D_F64) LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Vector2D_F64(georegression.struct.point.Vector2D_F64)

Aggregations

LineGeneral2D_F64 (georegression.struct.line.LineGeneral2D_F64)12 Test (org.junit.Test)5 LineSegment2D_F64 (georegression.struct.line.LineSegment2D_F64)3 Point2D_I32 (georegression.struct.point.Point2D_I32)3 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 GrowQueue_I32 (org.ddogleg.struct.GrowQueue_I32)2 ClosestPoint2D_F64 (georegression.metric.ClosestPoint2D_F64)1 LineParametric2D_F64 (georegression.struct.line.LineParametric2D_F64)1 Vector2D_F64 (georegression.struct.point.Vector2D_F64)1 Quadrilateral_F64 (georegression.struct.shapes.Quadrilateral_F64)1 ArrayList (java.util.ArrayList)1