Search in sources :

Example 21 with Point2Transform2_F32

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

the class RectifyImageOps method rectifyImage.

/**
 * Creates an {@link ImageDistort} for rectifying an image given its radial distortion and
 * rectification matrix.
 *
 * @param param Intrinsic parameters.
 * @param rectify Transform for rectifying the image.
 * @param imageType Type of single band image the transform is to be applied to.
 * @return ImageDistort for rectifying the image.
 */
public static <T extends ImageBase<T>> ImageDistort<T, T> rectifyImage(CameraPinholeRadial param, FMatrixRMaj rectify, BorderType borderType, ImageType<T> imageType) {
    boolean skip = borderType == BorderType.SKIP;
    if (skip) {
        borderType = BorderType.EXTENDED;
    }
    InterpolatePixel<T> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, borderType, imageType);
    // only compute the transform once
    ImageDistort<T, T> ret = FactoryDistort.distort(true, interp, imageType);
    ret.setRenderAll(!skip);
    Point2Transform2_F32 transform = transformRectToPixel(param, rectify);
    ret.setModel(new PointToPixelTransform_F32(transform));
    return ret;
}
Also used : PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Example 22 with Point2Transform2_F32

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

the class TestRectifyImageOps method transform_PixelToRect_and_RectToPixel_F32.

/**
 * Transforms and then performs the inverse transform to distorted rectified pixel
 */
@Test
public void transform_PixelToRect_and_RectToPixel_F32() {
    CameraPinholeRadial param = new CameraPinholeRadial().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 1e-4);
    FMatrixRMaj rect = new FMatrixRMaj(3, 3, true, 1.1f, 0, 0, 0, 2, 0, 0.1f, 0, 3);
    Point2Transform2_F32 forward = RectifyImageOps.transformPixelToRect(param, rect);
    Point2Transform2_F32 inverse = RectifyImageOps.transformRectToPixel(param, rect);
    float x = 20, y = 30;
    Point2D_F32 out = new Point2D_F32();
    forward.compute(x, y, out);
    // sanity check
    assertTrue(Math.abs(x - out.x) > 1e-4);
    assertTrue(Math.abs(y - out.y) > 1e-4);
    inverse.compute(out.x, out.y, out);
    assertEquals(x, out.x, 1e-4);
    assertEquals(y, out.y, 1e-4);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) Test(org.junit.Test)

Example 23 with Point2Transform2_F32

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

the class TestLensDistortionOps method transformChangeModel_F32_FULLVIEW_modified.

/**
 * Checks to see if the returned modified model is correct
 */
@Test
public void transformChangeModel_F32_FULLVIEW_modified() {
    // distorted pixel in original image
    float pixelX = 12.5f, pixelY = height - 3;
    CameraPinholeRadial orig = new CameraPinholeRadial().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 0.05);
    CameraPinhole desired = new CameraPinhole(orig);
    Point2Transform2_F32 distToNorm = LensDistortionOps.narrow(orig).undistort_F32(true, false);
    Point2D_F32 norm = new Point2D_F32();
    distToNorm.compute(pixelX, pixelY, norm);
    CameraPinholeRadial adjusted = new CameraPinholeRadial();
    Point2Transform2_F32 distToAdj = LensDistortionOps.transformChangeModel_F32(AdjustmentType.FULL_VIEW, orig, desired, false, adjusted);
    Point2D_F32 adjPixel = new Point2D_F32();
    Point2D_F32 normFound = new Point2D_F32();
    distToAdj.compute(pixelX, pixelY, adjPixel);
    PerspectiveOps.convertPixelToNorm(adjusted, adjPixel, normFound);
    // see if the normalized image coordinates are the same
    assertEquals(norm.x, normFound.x, 1e-3);
    assertEquals(norm.y, normFound.y, 1e-3);
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.Test)

Example 24 with Point2Transform2_F32

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

the class TestLensDistortionOps method transformChangeModel_F32_NONE_modified.

@Test
public void transformChangeModel_F32_NONE_modified() {
    // distorted pixel in original image
    float pixelX = 12.5f, pixelY = height - 3;
    CameraPinholeRadial orig = new CameraPinholeRadial().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 0.05);
    CameraPinhole desired = new CameraPinhole(orig);
    Point2Transform2_F32 distToNorm = LensDistortionOps.narrow(orig).undistort_F32(true, false);
    Point2D_F32 norm = new Point2D_F32();
    distToNorm.compute(pixelX, pixelY, norm);
    CameraPinhole adjusted = new CameraPinhole();
    Point2Transform2_F32 distToAdj = LensDistortionOps.transformChangeModel_F32(AdjustmentType.NONE, orig, desired, false, adjusted);
    Point2D_F32 adjPixel = new Point2D_F32();
    Point2D_F32 normFound = new Point2D_F32();
    distToAdj.compute(pixelX, pixelY, adjPixel);
    PerspectiveOps.convertPixelToNorm(adjusted, adjPixel, normFound);
    // see if the normalized image coordinates are the same
    assertEquals(norm.x, normFound.x, 1e-3);
    assertEquals(norm.y, normFound.y, 1e-3);
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.Test)

Example 25 with Point2Transform2_F32

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

the class GeneralLensDistortionNarrowFOVChecks method forwardsBackwards_F32.

@Test
public void forwardsBackwards_F32() {
    LensDistortionNarrowFOV alg = create();
    for (int i = 0; i < 4; i++) {
        boolean inputPixel = i % 2 == 0;
        boolean outputPixel = i / 2 == 0;
        Point2Transform2_F32 distort = alg.distort_F32(inputPixel, outputPixel);
        Point2Transform2_F32 undistort = alg.undistort_F32(outputPixel, inputPixel);
        float inputX, inputY, scale;
        if (inputPixel) {
            inputX = 21.3f;
            inputY = 45.1f;
            scale = 10.0f;
        } else {
            inputX = 0.05f;
            inputY = -0.1f;
            scale = 0.1f;
        }
        Point2D_F32 middle = new Point2D_F32();
        Point2D_F32 found = new Point2D_F32();
        distort.compute(inputX, inputY, middle);
        undistort.compute(middle.x, middle.y, found);
        assertEquals(inputX, found.x, scale * tol_F32);
        assertEquals(inputY, found.y, scale * tol_F32);
    }
}
Also used : Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) Test(org.junit.Test)

Aggregations

Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)26 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)10 SequencePoint2Transform2_F32 (boofcv.struct.distort.SequencePoint2Transform2_F32)9 Point2D_F32 (georegression.struct.point.Point2D_F32)9 Test (org.junit.Test)9 CameraPinhole (boofcv.struct.calib.CameraPinhole)7 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)5 FMatrixRMaj (org.ejml.data.FMatrixRMaj)5 PointTransformHomography_F32 (boofcv.alg.distort.PointTransformHomography_F32)4 RectangleLength2D_F32 (georegression.struct.shapes.RectangleLength2D_F32)4 LensDistortionRadialTangential (boofcv.alg.distort.radtan.LensDistortionRadialTangential)2 InterpolatePixelS (boofcv.alg.interpolate.InterpolatePixelS)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)1 PinholePtoN_F32 (boofcv.alg.distort.pinhole.PinholePtoN_F32)1 ImagePanel (boofcv.gui.image.ImagePanel)1 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)1 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)1 GrayU8 (boofcv.struct.image.GrayU8)1 Point3D_F32 (georegression.struct.point.Point3D_F32)1