Search in sources :

Example 31 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestRefinePolygonToGrayLine method fitWithEdgeOnBorder.

/**
 * See if it handles lines along the image border correctly
 */
@Test
public void fitWithEdgeOnBorder() {
    x0 = 0;
    x1 = 100;
    y0 = 100;
    y1 = 200;
    rectangles.add(new Rectangle2D_I32(x0, y0, x1, y1));
    for (Class imageType : imageTypes) {
        renderDistortedRectangles(true, imageType);
        RefinePolygonToGrayLine alg = createAlg(4, imageType);
        Polygon2D_F64 input = createFromSquare(null);
        input.get(0).set(x0, y0 + 1.1);
        input.get(1).set(x0, y1 - 1.1);
        Polygon2D_F64 found = new Polygon2D_F64(4);
        alg.setImage(image);
        assertTrue(alg.refine(input, found));
        Polygon2D_F64 expected = createFromSquare(null);
        assertTrue(expected.isIdentical(found, 0.01));
    }
}
Also used : Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 32 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestRefinePolygonToGrayLine method fit_perfect_transform.

public void fit_perfect_transform(boolean black, Affine2D_F64 regToDist, Class imageType) {
    this.transform.set(regToDist);
    renderDistortedRectangles(black, imageType);
    RefinePolygonToGrayLine alg = createAlg(4, imageType);
    Polygon2D_F64 input = createFromSquare(null);
    Polygon2D_F64 expected = input.copy();
    Polygon2D_F64 found = new Polygon2D_F64(4);
    alg.setImage(image);
    // fail without the transform
    assertFalse(alg.refine(input, found));
    // work when the transform is applied
    PixelTransformAffine_F32 transform = new PixelTransformAffine_F32();
    Affine2D_F32 regToDist_F32 = new Affine2D_F32();
    ConvertFloatType.convert(regToDist, regToDist_F32);
    transform.set(regToDist_F32);
    alg.setTransform(transform);
    alg.setImage(image);
    assertTrue(alg.refine(input, found));
    // should be close to the expected
    assertTrue(expected.isIdentical(found, 0.3));
}
Also used : Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Example 33 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class TestUtilShapePolygon method convert.

@Test
public void convert() {
    Polygon2D_F64 orig = new Polygon2D_F64(10, 20, 30, 21, 19.5, -10, 8, -8);
    LineGeneral2D_F64[] lines = new LineGeneral2D_F64[4];
    lines[0] = UtilLine2D_F64.convert(orig.getLine(0, null), (LineGeneral2D_F64) null);
    lines[1] = UtilLine2D_F64.convert(orig.getLine(1, null), (LineGeneral2D_F64) null);
    lines[2] = UtilLine2D_F64.convert(orig.getLine(2, null), (LineGeneral2D_F64) null);
    lines[3] = UtilLine2D_F64.convert(orig.getLine(3, null), (LineGeneral2D_F64) null);
    Polygon2D_F64 found = new Polygon2D_F64(4);
    assertTrue(UtilShapePolygon.convert(lines, found));
    assertTrue(orig.isIdentical(found, 1e-8));
}
Also used : LineGeneral2D_F64(georegression.struct.line.LineGeneral2D_F64) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) Test(org.junit.Test)

Example 34 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_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 35 with Polygon2D_F64

use of georegression.struct.shapes.Polygon2D_F64 in project BoofCV by lessthanoptimal.

the class CommonFitPolygonChecks method findMatchesOriginal.

/**
 * Compare found rectangle against rectangles in the original undistorted image
 */
protected int findMatchesOriginal(Polygon2D_F64 found, double tol) {
    int match = 0;
    for (int i = 0; i < rectangles.size(); i++) {
        Rectangle2D_I32 ri = rectangles.get(i);
        Rectangle2D_F64 r = new Rectangle2D_F64(ri.x0, ri.y0, ri.x1, ri.y1);
        Polygon2D_F64 p = new Polygon2D_F64(4);
        UtilPolygons2D_F64.convert(r, p);
        if (p.isCCW())
            p.flip();
        if (UtilPolygons2D_F64.isEquivalent(found, p, tol))
            match++;
    }
    return match;
}
Also used : Rectangle2D_F64(georegression.struct.shapes.Rectangle2D_F64) Rectangle2D_I32(georegression.struct.shapes.Rectangle2D_I32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64)

Aggregations

Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)79 Test (org.junit.Test)40 Point2D_F64 (georegression.struct.point.Point2D_F64)13 ArrayList (java.util.ArrayList)9 GrayU8 (boofcv.struct.image.GrayU8)6 Rectangle2D_I32 (georegression.struct.shapes.Rectangle2D_I32)6 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)5 BufferedImage (java.awt.image.BufferedImage)5 GrowQueue_B (org.ddogleg.struct.GrowQueue_B)5 Point2D_I32 (georegression.struct.point.Point2D_I32)4 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)3 DetectPolygonFromContour (boofcv.alg.shapes.polygon.DetectPolygonFromContour)3 GrayF32 (boofcv.struct.image.GrayF32)3 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)3 Se3_F64 (georegression.struct.se.Se3_F64)3 Rectangle2D_F64 (georegression.struct.shapes.Rectangle2D_F64)3 File (java.io.File)3 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)2 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 SquareNode (boofcv.alg.fiducial.calib.squares.SquareNode)2