Search in sources :

Example 6 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class TestBaseDetectFiducialSquare method render.

/**
 * Draws a distorted pattern onto the output
 */
public static void render(GrayU8 pattern, Quadrilateral_F64 where, GrayU8 output) {
    int w = pattern.width;
    int h = pattern.height;
    ArrayList<AssociatedPair> associatedPairs = new ArrayList<>();
    associatedPairs.add(new AssociatedPair(where.a, new Point2D_F64(0, 0)));
    associatedPairs.add(new AssociatedPair(where.b, new Point2D_F64(w, 0)));
    associatedPairs.add(new AssociatedPair(where.c, new Point2D_F64(w, h)));
    associatedPairs.add(new AssociatedPair(where.d, new Point2D_F64(0, h)));
    Estimate1ofEpipolar computeHomography = FactoryMultiView.computeHomographyDLT(true);
    DMatrixRMaj H = new DMatrixRMaj(3, 3);
    computeHomography.process(associatedPairs, H);
    // Create the transform for distorting the image
    FMatrixRMaj H32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(H, H32);
    PointTransformHomography_F32 homography = new PointTransformHomography_F32(H32);
    PixelTransform2_F32 pixelTransform = new PointToPixelTransform_F32(homography);
    // Apply distortion and show the results
    DistortImageOps.distortSingle(pattern, output, pixelTransform, InterpolationType.BILINEAR, BorderType.SKIP);
// ShowImages.showWindow(output, "Rendered");
// try {Thread.sleep(10000);} catch (InterruptedException e) {}
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) FMatrixRMaj(org.ejml.data.FMatrixRMaj) Point2D_F64(georegression.struct.point.Point2D_F64) Estimate1ofEpipolar(boofcv.abst.geo.Estimate1ofEpipolar) ArrayList(java.util.ArrayList) DMatrixRMaj(org.ejml.data.DMatrixRMaj) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 7 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class TestBinaryEllipseDetector method distortedImage.

/**
 * Input image is distorted
 */
@Test
public void distortedImage() {
    List<EllipseRotated_F64> original = new ArrayList<>();
    original.add(new EllipseRotated_F64(50, 65, 20, 10, 0.5));
    original.add(new EllipseRotated_F64(90, 100, 25, 25, 0));
    GrayU8 image = TestBinaryEllipseDetectorPixel.renderEllipses_F64(200, 210, original, 0);
    GrayU8 binary = image.createSameShape();
    ThresholdImageOps.threshold(image, binary, 30, true);
    BinaryEllipseDetector<GrayU8> alg = create();
    PixelTransform2_F32 distToUndist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, 5, 8));
    PixelTransform2_F32 undistToDist = new PixelTransformAffine_F32(new Affine2D_F32(1, 0, 0, 1, -5, -8));
    alg.setLensDistortion(distToUndist, undistToDist);
    alg.process(image, binary);
    // adjust the ellipses using the transform
    List<EllipseRotated_F64> expected = new ArrayList<>();
    for (EllipseRotated_F64 o : original) {
        EllipseRotated_F64 e = new EllipseRotated_F64(o);
        e.center.x += 5;
        e.center.y += 8;
        expected.add(e);
    }
    List<EllipseRotated_F64> found = alg.getFoundEllipses(null);
    TestBinaryEllipseDetectorPixel.checkEquals_F64(expected, found, 1.0, 0.1);
}
Also used : EllipseRotated_F64(georegression.struct.curve.EllipseRotated_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) ArrayList(java.util.ArrayList) GrayU8(boofcv.struct.image.GrayU8) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Example 8 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class TestDetectPolygonBinaryGrayRefine method checkDetected_LensDistortion.

private void checkDetected_LensDistortion(Class imageType, double tol) {
    renderDistortedRectangles(true, imageType);
    Affine2D_F32 a = new Affine2D_F32();
    UtilAffine.convert(transform, a);
    PixelTransform2_F32 tranFrom = new PixelTransformAffine_F32(a);
    PixelTransform2_F32 tranTo = new PixelTransformAffine_F32(a.invert(null));
    int numberOfSides = 4;
    DetectPolygonBinaryGrayRefine alg = createAlg(imageType, numberOfSides, numberOfSides);
    alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
    alg.process(image, binary);
    List<DetectPolygonFromContour.Info> found = alg.getPolygonInfo();
    assertEquals(rectangles.size(), found.size());
    for (int i = 0; i < found.size(); i++) {
        Polygon2D_F64 p = found.get(i).polygon;
        assertEquals(1, findMatchesOriginal(p, tol));
        assertEquals(black, found.get(i).edgeInside, 3);
        assertEquals(white, found.get(i).edgeOutside, white * 0.05);
    }
    // ----------- see if distortion is cleared properly
    alg.clearLensDistortion();
    alg.process(image, binary);
    found = alg.getPolygonInfo();
    assertEquals(rectangles.size(), found.size());
    // nothing should match now
    for (int i = 0; i < found.size(); i++) {
        Polygon2D_F64 p = found.get(i).polygon;
        assertEquals(0, findMatchesOriginal(p, tol));
    }
}
Also used : Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Polygon2D_F64(georegression.struct.shapes.Polygon2D_F64) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 9 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class TestFDistort method setBorderChange.

/**
 * Makes sure that border recycling doesn't mess things up
 */
@Test
public void setBorderChange() {
    ImageMiscOps.fillUniform(input, rand, 0, 200);
    GrayU8 found = new GrayU8(width / 2, height / 2);
    GrayU8 expected = new GrayU8(width / 2, height / 2);
    FDistort alg = new FDistort();
    alg.init(input, found).scaleExt().apply();
    ImageDistort distorter = alg.distorter;
    InterpolatePixel interp = alg.interp;
    ;
    PixelTransform2_F32 outputToInput = alg.outputToInput;
    // Set it to the default border, nothing should change
    expected.setTo(found);
    alg.border(BorderType.EXTENDED).apply();
    assertTrue(distorter == alg.distorter);
    assertTrue(interp == alg.interp);
    assertTrue(outputToInput == alg.outputToInput);
    BoofTesting.assertEquals(expected, found, 1e-4);
    // change border now a fixed value
    alg.border(10).apply();
    new FDistort(input, expected).scale().border(10).apply();
    BoofTesting.assertEquals(expected, found, 1e-4);
    // change value
    alg.border(1).apply();
    new FDistort(input, expected).scale().border(1).apply();
    BoofTesting.assertEquals(expected, found, 1e-4);
}
Also used : GrayU8(boofcv.struct.image.GrayU8) ImageDistort(boofcv.alg.distort.ImageDistort) InterpolatePixel(boofcv.alg.interpolate.InterpolatePixel) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Example 10 with PixelTransform2_F32

use of boofcv.struct.distort.PixelTransform2_F32 in project BoofCV by lessthanoptimal.

the class TestFDistort method affine.

@Test
public void affine() {
    ImageMiscOps.fillUniform(input, rand, 0, 200);
    Affine2D_F32 affine = new Affine2D_F32(2, 0.1f, -0.2f, 1.1f, 3, 4.5f);
    PixelTransform2_F32 transform = new PixelTransformAffine_F32(affine.invert(null));
    new FDistort(input, output).affine(2, 0.1f, -0.2f, 1.1f, 3, 4.5f).borderExt().apply();
    InterpolatePixelS<GrayU8> interp = FactoryInterpolation.bilinearPixelS(input, null);
    interp.setBorder(FactoryImageBorderAlgs.extend(input));
    interp.setImage(input);
    if (input.getDataType().isInteger()) {
        for (int y = 0; y < output.height; y++) {
            for (int x = 0; x < output.width; x++) {
                transform.compute(x, y);
                float val = interp.get(transform.distX, transform.distY);
                assertEquals((int) val, output.get(x, y), 1e-4);
            }
        }
    } else {
        for (int y = 0; y < output.height; y++) {
            for (int x = 0; x < output.width; x++) {
                transform.compute(x, y);
                float val = interp.get(transform.distX, transform.distY);
                assertEquals(val, output.get(x, y), 1e-4);
            }
        }
    }
}
Also used : Affine2D_F32(georegression.struct.affine.Affine2D_F32) GrayU8(boofcv.struct.image.GrayU8) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Aggregations

PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)17 Test (org.junit.Test)7 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)6 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)6 GrayU8 (boofcv.struct.image.GrayU8)4 ImageDistort (boofcv.alg.distort.ImageDistort)2 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)2 InterpolatePixel (boofcv.alg.interpolate.InterpolatePixel)2 GrayF32 (boofcv.struct.image.GrayF32)2 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)2 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 Polygon2D_F64 (georegression.struct.shapes.Polygon2D_F64)2 ArrayList (java.util.ArrayList)2 Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)1 PixelTransformHomography_F32 (boofcv.alg.distort.PixelTransformHomography_F32)1 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)1 CameraPinhole (boofcv.struct.calib.CameraPinhole)1 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)1 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)1