Search in sources :

Example 1 with SequencePoint2Transform2_F32

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

the class ImplRectifyImageOps_F32 method transformPixelToRectNorm.

public static Point2Transform2_F32 transformPixelToRectNorm(CameraPinholeRadial param, FMatrixRMaj rectify, FMatrixRMaj rectifyK) {
    if (rectifyK.get(0, 1) != 0)
        throw new IllegalArgumentException("Skew should be zero in rectified images");
    Point2Transform2_F32 remove_p_to_p = narrow(param).undistort_F32(true, true);
    PointTransformHomography_F32 rectifyDistort = new PointTransformHomography_F32(rectify);
    PinholePtoN_F32 pixelToNorm = new PinholePtoN_F32();
    pixelToNorm.set(rectifyK.get(0, 0), rectifyK.get(1, 1), rectifyK.get(0, 1), rectifyK.get(0, 2), rectifyK.get(1, 2));
    return new SequencePoint2Transform2_F32(remove_p_to_p, rectifyDistort, pixelToNorm);
}
Also used : PointTransformHomography_F32(boofcv.alg.distort.PointTransformHomography_F32) PinholePtoN_F32(boofcv.alg.distort.pinhole.PinholePtoN_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32)

Example 2 with SequencePoint2Transform2_F32

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

the class ImplRectifyImageOps_F32 method transformRectToPixel.

public static Point2Transform2_F32 transformRectToPixel(CameraPinholeRadial param, FMatrixRMaj rectify) {
    Point2Transform2_F32 add_p_to_p = narrow(param).distort_F32(true, true);
    FMatrixRMaj rectifyInv = new FMatrixRMaj(3, 3);
    CommonOps_FDRM.invert(rectify, rectifyInv);
    PointTransformHomography_F32 removeRect = new PointTransformHomography_F32(rectifyInv);
    return new SequencePoint2Transform2_F32(removeRect, add_p_to_p);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) PointTransformHomography_F32(boofcv.alg.distort.PointTransformHomography_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32)

Example 3 with SequencePoint2Transform2_F32

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

the class LensDistortionOps method transformChangeModel_F32.

/**
 * Creates a {@link Point2Transform2_F32} for converting pixels from original camera model into a new synthetic
 * model.  The scaling of the image can be adjusted to ensure certain visibility requirements.
 *
 * @param type The type of adjustment it will apply to the transform
 * @param paramOriginal Camera model for the current image
 * @param paramDesired Desired camera model for the distorted image
 * @param desiredToOriginal If true then the transform's input is assumed to be pixels in the desired
 *                       image and the output will be in original image, if false then the reverse transform
 *                       is returned.
 * @param paramMod The modified camera model to meet the requested visibility requirements.  Null if you don't want it.
 * @return The requested transform
 */
public static <O extends CameraPinhole, D extends CameraPinhole> Point2Transform2_F32 transformChangeModel_F32(AdjustmentType type, O paramOriginal, D paramDesired, boolean desiredToOriginal, D paramMod) {
    LensDistortionNarrowFOV original = LensDistortionOps.narrow(paramOriginal);
    LensDistortionNarrowFOV desired = LensDistortionOps.narrow(paramDesired);
    Point2Transform2_F32 ori_p_to_n = original.undistort_F32(true, false);
    Point2Transform2_F32 des_n_to_p = desired.distort_F32(false, true);
    Point2Transform2_F32 ori_to_des = new SequencePoint2Transform2_F32(ori_p_to_n, des_n_to_p);
    RectangleLength2D_F32 bound;
    if (type == AdjustmentType.FULL_VIEW) {
        bound = DistortImageOps.boundBox_F32(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F32(ori_to_des));
    } else if (type == AdjustmentType.EXPAND) {
        bound = LensDistortionOps.boundBoxInside(paramOriginal.width, paramOriginal.height, new PointToPixelTransform_F32(ori_to_des));
        // ensure there are no strips of black
        LensDistortionOps.roundInside(bound);
    } else if (type == AdjustmentType.NONE) {
        bound = new RectangleLength2D_F32(0, 0, paramDesired.width, paramDesired.height);
    } else {
        throw new IllegalArgumentException("Unsupported type " + type);
    }
    float scaleX = bound.width / paramDesired.width;
    float scaleY = bound.height / paramDesired.height;
    float scale;
    if (type == AdjustmentType.FULL_VIEW) {
        scale = Math.max(scaleX, scaleY);
    } else if (type == AdjustmentType.EXPAND) {
        scale = Math.min(scaleX, scaleY);
    } else {
        scale = 1.0f;
    }
    float deltaX = (float) (bound.x0 + (scaleX - scale) * paramDesired.width / 2.0);
    float deltaY = (float) (bound.y0 + (scaleY - scale) * paramDesired.height / 2.0);
    // adjustment matrix
    FMatrixRMaj A = new FMatrixRMaj(3, 3, true, scale, 0, deltaX, 0, scale, deltaY, 0, 0, 1);
    FMatrixRMaj A_inv = new FMatrixRMaj(3, 3);
    if (!CommonOps_FDRM.invert(A, A_inv)) {
        throw new RuntimeException("Failed to invert adjustment matrix.  Probably bad.");
    }
    if (paramMod != null) {
        PerspectiveOps.adjustIntrinsic(paramDesired, A_inv, paramMod);
    }
    if (desiredToOriginal) {
        Point2Transform2_F32 des_p_to_n = desired.undistort_F32(true, false);
        Point2Transform2_F32 ori_n_to_p = original.distort_F32(false, true);
        PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A);
        return new SequencePoint2Transform2_F32(adjust, des_p_to_n, ori_n_to_p);
    } else {
        PointTransformHomography_F32 adjust = new PointTransformHomography_F32(A_inv);
        return new SequencePoint2Transform2_F32(ori_to_des, adjust);
    }
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) RectangleLength2D_F32(georegression.struct.shapes.RectangleLength2D_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32)

Example 4 with SequencePoint2Transform2_F32

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

the class ImplRectifyImageOps_F32 method transformPixelToRect.

public static Point2Transform2_F32 transformPixelToRect(CameraPinholeRadial param, FMatrixRMaj rectify) {
    Point2Transform2_F32 remove_p_to_p = narrow(param).undistort_F32(true, true);
    PointTransformHomography_F32 rectifyDistort = new PointTransformHomography_F32(rectify);
    return new SequencePoint2Transform2_F32(remove_p_to_p, rectifyDistort);
}
Also used : PointTransformHomography_F32(boofcv.alg.distort.PointTransformHomography_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32)

Example 5 with SequencePoint2Transform2_F32

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

the class PyramidDirectColorDepth_to_DepthVisualOdometry method setCalibration.

@Override
public void setCalibration(CameraPinholeRadial paramVisual, Point2Transform2_F32 visToDepth) {
    // the algorithms camera model assumes no lens distortion and that skew = 0
    CameraPinhole desired = new CameraPinhole(paramVisual);
    desired.skew = 0;
    adjustImage = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.ZERO, paramVisual, desired, paramAdjusted, algType);
    Point2Transform2_F32 desiredToOriginal = LensDistortionOps.transformChangeModel_F32(AdjustmentType.EXPAND, paramVisual, desired, false, null);
    // the adjusted undistorted image pixel to the depth image transform
    Point2Transform2_F32 adjustedToDepth = new SequencePoint2Transform2_F32(desiredToOriginal, visToDepth);
    // Create a lookup table to make the math much faster
    PixelTransform2_F32 pixelAdjToDepth = new PixelTransformCached_F32(paramAdjusted.width, paramAdjusted.height, adjustedToDepth);
    // adjusted pixels to normalized image coordinates in RGB frame
    sparse3D.configure(LensDistortionOps.narrow(paramAdjusted), pixelAdjToDepth);
    undistorted.reshape(paramAdjusted.width, paramAdjusted.height);
    if (convertInput != null) {
        inputConverted.reshape(paramAdjusted.width, paramAdjusted.height);
    }
    alg.setCameraParameters((float) paramAdjusted.fx, (float) paramAdjusted.fy, (float) paramAdjusted.cx, (float) paramAdjusted.cy, paramAdjusted.width, paramAdjusted.height);
}
Also used : SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32) CameraPinhole(boofcv.struct.calib.CameraPinhole) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) PixelTransformCached_F32(boofcv.alg.distort.PixelTransformCached_F32)

Aggregations

Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)6 SequencePoint2Transform2_F32 (boofcv.struct.distort.SequencePoint2Transform2_F32)6 PointTransformHomography_F32 (boofcv.alg.distort.PointTransformHomography_F32)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 FMatrixRMaj (org.ejml.data.FMatrixRMaj)2 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)1 PinholePtoN_F32 (boofcv.alg.distort.pinhole.PinholePtoN_F32)1 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)1 Point2D_F32 (georegression.struct.point.Point2D_F32)1 RectangleLength2D_F32 (georegression.struct.shapes.RectangleLength2D_F32)1