Search in sources :

Example 21 with FMatrixRMaj

use of org.ejml.data.FMatrixRMaj in project BoofCV by lessthanoptimal.

the class ShowRectifyCalibratedApp method addRectified.

private void addRectified(final String name, final DMatrixRMaj rect1, final DMatrixRMaj rect2) {
    // TODO simplify code some how
    FMatrixRMaj rect1_F32 = new FMatrixRMaj(3, 3);
    FMatrixRMaj rect2_F32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect1, rect1_F32);
    ConvertMatrixData.convert(rect2, rect2_F32);
    // Will rectify the image
    ImageType<Planar<GrayF32>> imageType = ImageType.pl(3, GrayF32.class);
    ImageDistort<Planar<GrayF32>, Planar<GrayF32>> imageDistortLeft = RectifyDistortImageOps.rectifyImage(param.getLeft(), rect1_F32, BorderType.ZERO, imageType);
    // ImageDistort<Planar<GrayF32>, Planar<GrayF32>> imageDistortRight =
    // RectifyDistortImageOps.rectifyImage(param.getRight(), rect2_F32, BorderType.ZERO, imageType);
    // Fill the image with all black
    GImageMiscOps.fill(rectLeft, 0);
    GImageMiscOps.fill(rectRight, 0);
    // Render the rectified image
    imageDistortLeft.apply(distLeft, rectLeft);
    imageDistortLeft.apply(distRight, rectRight);
    // convert for output
    final BufferedImage outLeft = ConvertBufferedImage.convertTo(rectLeft, null, true);
    final BufferedImage outRight = ConvertBufferedImage.convertTo(rectRight, null, true);
    // Add this rectified image
    SwingUtilities.invokeLater(() -> gui.addItem(new RectifiedPairPanel(true, outLeft, outRight), name));
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) Planar(boofcv.struct.image.Planar) RectifiedPairPanel(boofcv.gui.stereo.RectifiedPairPanel) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 22 with FMatrixRMaj

use of org.ejml.data.FMatrixRMaj in project BoofCV by lessthanoptimal.

the class VisualizeStereoDisparity method rectifyInputImages.

/**
 * Removes distortion and rectifies images.
 */
private void rectifyInputImages() {
    // Check to see if the input images have already been recitified
    rectifiedImages = calib.isRectified(1e-3);
    // get intrinsic camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.pinholeToMatrix(calib.left, (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.pinholeToMatrix(calib.right, (DMatrixRMaj) null);
    // and could add a little bit of noise
    if (rectifiedImages) {
        rectLeft.setTo(inputLeft);
        rectRight.setTo(inputRight);
        leftRectToPixel = new DoNothing2Transform2_F64();
        rectK = K1;
        rectR = CommonOps_DDRM.identity(3);
        return;
    }
    // compute rectification matrices
    rectifyAlg.process(K1, new Se3_F64(), K2, calib.getRightToLeft().invert(null));
    DMatrixRMaj rect1 = rectifyAlg.getUndistToRectPixels1();
    DMatrixRMaj rect2 = rectifyAlg.getUndistToRectPixels2();
    rectK = rectifyAlg.getCalibrationMatrix();
    rectR = rectifyAlg.getRectifiedRotation();
    // adjust view to maximize viewing area while not including black regions
    RectifyImageOps.allInsideLeft(calib.left, rect1, rect2, rectK, null);
    // compute transforms to apply rectify the images
    leftRectToPixel = transformRectToPixel(calib.left, rect1);
    ImageType<T> imageType = activeAlg.getInputType();
    // TODO simplify code some how
    FMatrixRMaj rect1_F32 = new FMatrixRMaj(3, 3);
    FMatrixRMaj rect2_F32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect1, rect1_F32);
    ConvertMatrixData.convert(rect2, rect2_F32);
    ImageDistort<T, T> distortRect1 = RectifyDistortImageOps.rectifyImage(calib.left, rect1_F32, BorderType.EXTENDED, imageType);
    ImageDistort<T, T> distortRect2 = RectifyDistortImageOps.rectifyImage(calib.right, rect2_F32, BorderType.EXTENDED, imageType);
    // rectify and undo distortion
    distortRect1.apply(inputLeft, rectLeft);
    distortRect2.apply(inputRight, rectRight);
    rectifiedImages = true;
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) DMatrixRMaj(org.ejml.data.DMatrixRMaj) DoNothing2Transform2_F64(boofcv.struct.distort.DoNothing2Transform2_F64) Se3_F64(georegression.struct.se.Se3_F64)

Example 23 with FMatrixRMaj

use of org.ejml.data.FMatrixRMaj in project BoofCV by lessthanoptimal.

the class DisplayPinholeCalibrationPanel method setCalibration.

public void setCalibration(CameraPinholeBrown param, DMatrixRMaj rect) {
    FMatrixRMaj rect_f32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect, rect_f32);
    this.undoRadial = RectifyDistortImageOps.rectifyImage(param, rect_f32, BorderType.ZERO, ImageType.single(GrayF32.class));
    this.remove_p_to_p = RectifyImageOps.transformPixelToRect(param, rect_f32);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj)

Example 24 with FMatrixRMaj

use of org.ejml.data.FMatrixRMaj 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 25 with FMatrixRMaj

use of org.ejml.data.FMatrixRMaj in project BoofCV by lessthanoptimal.

the class DisplayPinholeCalibrationPanel method setCalibration.

public void setCalibration(CameraPinholeRadial param, DMatrixRMaj rect) {
    FMatrixRMaj rect_f32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect, rect_f32);
    this.undoRadial = RectifyImageOps.rectifyImage(param, rect_f32, BorderType.ZERO, ImageType.single(GrayF32.class));
    this.remove_p_to_p = RectifyImageOps.transformPixelToRect(param, rect_f32);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj)

Aggregations

FMatrixRMaj (org.ejml.data.FMatrixRMaj)36 DMatrixRMaj (org.ejml.data.DMatrixRMaj)10 Test (org.junit.Test)8 Point2D_F32 (georegression.struct.point.Point2D_F32)7 Se3_F64 (georegression.struct.se.Se3_F64)7 RectifyCalibrated (boofcv.alg.geo.rectify.RectifyCalibrated)6 PointTransformHomography_F32 (boofcv.alg.distort.PointTransformHomography_F32)5 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)5 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)4 BufferedImage (java.awt.image.BufferedImage)4 RectifiedPairPanel (boofcv.gui.stereo.RectifiedPairPanel)3 GrayF32 (boofcv.struct.image.GrayF32)3 GrayU8 (boofcv.struct.image.GrayU8)3 Planar (boofcv.struct.image.Planar)3 ArrayList (java.util.ArrayList)3 Test (org.junit.jupiter.api.Test)3 Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 PointToPixelTransform_F32 (boofcv.struct.distort.PointToPixelTransform_F32)2