Search in sources :

Example 31 with Point2Transform2_F32

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

the class CalibrationDetectorSquareGrid method setLensDistortion.

@Override
public void setLensDistortion(@Nullable LensDistortionNarrowFOV distortion, int width, int height) {
    if (distortion == null)
        detector.getDetectorSquare().setLensDistortion(width, height, null, null);
    else {
        Point2Transform2_F32 pointDistToUndist = distortion.undistort_F32(true, true);
        Point2Transform2_F32 pointUndistToDist = distortion.distort_F32(true, true);
        PixelTransform<Point2D_F32> distToUndist = new PointToPixelTransform_F32(pointDistToUndist);
        PixelTransform<Point2D_F32> undistToDist = new PointToPixelTransform_F32(pointUndistToDist);
        detector.getDetectorSquare().setLensDistortion(width, height, distToUndist, undistToDist);
    }
}
Also used : PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Example 32 with Point2Transform2_F32

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

the class RemoveLensDistortionApp method processImage.

@Override
public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {
    // strip away distortion parameters
    CameraPinhole desired = new CameraPinhole(param);
    // distorted image
    dist = (T) input.clone();
    // storage for undistorted image
    undist = (T) input.createSameShape();
    // show results and draw a horizontal line where the user clicks to see rectification easier
    SwingUtilities.invokeLater(() -> {
        gui.reset();
        gui.addItem(new ImagePanel(buffered), "Original");
    });
    // add different types of adjustments
    Point2Transform2_F32 add_p_to_p = LensDistortionOps_F32.transformChangeModel(AdjustmentType.NONE, param, desired, true, null);
    addUndistorted("No Adjustment", add_p_to_p);
    Point2Transform2_F32 expand = LensDistortionOps_F32.transformChangeModel(AdjustmentType.EXPAND, param, desired, true, null);
    addUndistorted("Expand", expand);
    Point2Transform2_F32 fullView = LensDistortionOps_F32.transformChangeModel(AdjustmentType.FULL_VIEW, param, desired, true, null);
    addUndistorted("Full View", fullView);
    Point2Transform2_F32 center = LensDistortionOps_F32.transformChangeModel(AdjustmentType.CENTER, param, desired, true, null);
    addUndistorted("Center", center);
}
Also used : Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) CameraPinhole(boofcv.struct.calib.CameraPinhole) ImagePanel(boofcv.gui.image.ImagePanel)

Example 33 with Point2Transform2_F32

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

the class GeneralLensDistortionNarrowFOVChecks method forwardsBackwards_F32.

@Test
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.jupiter.api.Test)

Example 34 with Point2Transform2_F32

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

the class RectifyDistortImageOps 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(CameraPinholeBrown 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 = RectifyImageOps.transformRectToPixel(param, rectify);
    ret.setModel(new PointToPixelTransform_F32(transform));
    return ret;
}
Also used : PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Example 35 with Point2Transform2_F32

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

the class LensDistortionOps method changeCameraModel.

/**
 * Creates a distortion for modifying the input image from one camera model into another camera model. If
 * requested the camera model can be further modified to ensure certain visibility requirements are meet
 * and the adjusted camera model will be returned.
 *
 * @param type How it should modify the image model to ensure visibility of pixels.
 * @param borderType How the image border is handled
 * @param original The original camera model
 * @param desired The desired camera model
 * @param modified (Optional) The desired camera model after being rescaled. Can be null.
 * @param imageType Type of image.
 * @return Image distortion from original camera model to the modified one.
 */
public static <T extends ImageBase<T>, O extends CameraPinhole, D extends CameraPinhole> ImageDistort<T, T> changeCameraModel(AdjustmentType type, BorderType borderType, O original, D desired, @Nullable D modified, ImageType<T> imageType) {
    Class bandType = imageType.getImageClass();
    boolean skip = borderType == BorderType.SKIP;
    // it has to process the border at some point, so if skip is requested just skip stuff truly outside the image
    if (skip)
        borderType = BorderType.EXTENDED;
    InterpolatePixelS interp = FactoryInterpolation.createPixelS(0, 255, InterpolationType.BILINEAR, borderType, bandType);
    Point2Transform2_F32 undistToDist = LensDistortionOps_F32.transformChangeModel(type, original, desired, true, modified);
    ImageDistort<T, T> distort = FactoryDistort.distort(true, interp, imageType);
    distort.setModel(new PointToPixelTransform_F32(undistToDist));
    distort.setRenderAll(!skip);
    return distort;
}
Also used : InterpolatePixelS(boofcv.alg.interpolate.InterpolatePixelS) PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Aggregations

Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)36 Point2D_F32 (georegression.struct.point.Point2D_F32)16 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)10 SequencePoint2Transform2_F32 (boofcv.struct.distort.SequencePoint2Transform2_F32)9 CameraPinhole (boofcv.struct.calib.CameraPinhole)8 PointToPixelTransform_F32 (boofcv.struct.distort.PointToPixelTransform_F32)8 Test (org.junit.Test)8 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 Test (org.junit.jupiter.api.Test)2 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)1 PinholePtoN_F32 (boofcv.alg.distort.pinhole.PinholePtoN_F32)1 ImagePanel (boofcv.gui.image.ImagePanel)1 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)1 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)1