Search in sources :

Example 11 with PixelTransform2_F32

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

the class TestFDistort method setRefs.

/**
 * Makes sure that setRefs doesn't cause it to blow up
 */
@Test
public void setRefs() {
    ImageMiscOps.fillUniform(input, rand, 0, 200);
    FDistort alg = new FDistort();
    alg.setRefs(input, output).interp(InterpolationType.BILINEAR).scaleExt().apply();
    ImageDistort distorter = alg.distorter;
    InterpolatePixel interp = alg.interp;
    ;
    PixelTransform2_F32 outputToInput = alg.outputToInput;
    // a new image shouldn't cause new memory to be declared bad stuff to happen
    GrayU8 found = new GrayU8(width / 2, height / 2);
    GrayU8 expected = new GrayU8(width / 2, height / 2);
    alg.setRefs(input, found).scale().apply();
    assertTrue(distorter == alg.distorter);
    assertTrue(interp == alg.interp);
    assertTrue(outputToInput == alg.outputToInput);
    new FDistort(input, expected).scaleExt().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 12 with PixelTransform2_F32

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

the class TestDetectPolygonFromContour 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;
    DetectPolygonFromContour alg = createDetector(imageType, numberOfSides, numberOfSides);
    alg.setLensDistortion(image.width, image.height, tranTo, tranFrom);
    alg.process(image, binary);
    FastQueue<DetectPolygonFromContour.Info> found = alg.getFound();
    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);
    }
}
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 13 with PixelTransform2_F32

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

the class TestDepthSparse3D method basicTest.

@Test
public void basicTest() {
    GrayU16 depth = new GrayU16(w, h);
    depth.set(5, 6, 1000);
    CameraPinholeRadial param = new CameraPinholeRadial(1, 1, 0, 5, 10, w, h).fsetRadial(0, 0);
    PixelTransform2_F32 v2d = new PixelTransform2_F32() {

        @Override
        public void compute(int x, int y) {
            distX = x + 1;
            distY = y + 2;
        }
    };
    DepthSparse3D<GrayU16> alg = new DepthSparse3D.I<>(2.1);
    alg.configure(LensDistortionOps.narrow(param), v2d);
    alg.setDepthImage(depth);
    assertTrue(alg.process(4, 4));
    Point3D_F64 found = alg.getWorldPt();
    Point2D_F64 norm = new Point2D_F64();
    PerspectiveOps.convertPixelToNorm(param, new Point2D_F64(4, 4), norm);
    double z = 1000 * 2.1;
    assertEquals(z, found.z, 1e-8);
    assertEquals(norm.x * z, found.x, 1e-8);
    assertEquals(norm.y * z, found.y, 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) GrayU16(boofcv.struct.image.GrayU16) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F64(georegression.struct.point.Point2D_F64) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) Test(org.junit.Test)

Example 14 with PixelTransform2_F32

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

the class StitchingFromMotion2D method setOriginToCurrent.

/**
 * Sets the current image to be the origin of the stitched coordinate system.  The background is filled
 * with a value of 0.
 * Must be called after {@link #process(boofcv.struct.image.ImageBase)}.
 */
public void setOriginToCurrent() {
    IT currToWorld = (IT) worldToCurr.invert(null);
    IT oldWorldToNewWorld = (IT) worldToInit.concat(currToWorld, null);
    PixelTransform2_F32 newToOld = converter.convertPixel(oldWorldToNewWorld, null);
    // fill in the background color
    GImageMiscOps.fill(workImage, 0);
    // render the transform
    distorter.setModel(newToOld);
    distorter.apply(stitchedImage, workImage);
    // swap the two images
    I s = workImage;
    workImage = stitchedImage;
    stitchedImage = s;
    // have motion estimates be relative to this frame
    motion.setToFirst();
    first = true;
    computeCurrToInit_PixelTran();
}
Also used : PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Example 15 with PixelTransform2_F32

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

the class UtilImageMotion method createPixelTransform.

/**
 * Given a motion model create a PixelTransform used to distort the image
 *
 * @param transform Motion transform
 * @return PixelTransform_F32 used to distort the image
 */
public static PixelTransform2_F32 createPixelTransform(InvertibleTransform transform) {
    PixelTransform2_F32 pixelTran;
    if (transform instanceof Homography2D_F64) {
        Homography2D_F32 t = ConvertFloatType.convert((Homography2D_F64) transform, null);
        pixelTran = new PixelTransformHomography_F32(t);
    } else if (transform instanceof Homography2D_F32) {
        pixelTran = new PixelTransformHomography_F32((Homography2D_F32) transform);
    } else if (transform instanceof Affine2D_F64) {
        Affine2D_F32 t = UtilAffine.convert((Affine2D_F64) transform, null);
        pixelTran = new PixelTransformAffine_F32(t);
    } else if (transform instanceof Affine2D_F32) {
        pixelTran = new PixelTransformAffine_F32((Affine2D_F32) transform);
    } else {
        throw new RuntimeException("Unknown model type");
    }
    return pixelTran;
}
Also used : Affine2D_F64(georegression.struct.affine.Affine2D_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformHomography_F32(boofcv.alg.distort.PixelTransformHomography_F32) Homography2D_F32(georegression.struct.homography.Homography2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Homography2D_F64(georegression.struct.homography.Homography2D_F64) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

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