Search in sources :

Example 6 with RectifyCalibrated

use of boofcv.alg.geo.rectify.RectifyCalibrated in project narchy by automenta.

the class ExampleStereoTwoViewsOneCamera method rectifyImages.

/**
 * Remove lens distortion and rectify stereo images
 *
 * @param distortedLeft  Input distorted image from left camera.
 * @param distortedRight Input distorted image from right camera.
 * @param leftToRight    Camera motion from left to right
 * @param intrinsic      Intrinsic camera parameters
 * @param rectifiedLeft  Output rectified image for left camera.
 * @param rectifiedRight Output rectified image for right camera.
 * @param rectifiedK     Output camera calibration matrix for rectified camera
 */
public static void rectifyImages(GrayU8 distortedLeft, GrayU8 distortedRight, Se3_F64 leftToRight, CameraPinholeRadial intrinsic, GrayU8 rectifiedLeft, GrayU8 rectifiedRight, DMatrixRMaj rectifiedK) {
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    // RectifyFundamental rectifyAlg = RectifyImageOps.createUncalibrated();
    // original camera calibration matrices
    DMatrixRMaj K = PerspectiveOps.calibrationMatrix(intrinsic, (DMatrixRMaj) null);
    rectifyAlg.process(K, new Se3_F64(), K, leftToRight);
    // rectification matrix for each image
    DMatrixRMaj rect1 = rectifyAlg.getRect1();
    DMatrixRMaj rect2 = rectifyAlg.getRect2();
    // New calibration matrix,
    rectifiedK.set(rectifyAlg.getCalibrationMatrix());
    // Adjust the rectification to make the view area more useful
    RectifyImageOps.allInsideLeft(intrinsic, rect1, rect2, rectifiedK);
    // undistorted and rectify images
    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<GrayU8, GrayU8> distortLeft = RectifyImageOps.rectifyImage(intrinsic, rect1_F32, BorderType.SKIP, distortedLeft.getImageType());
    ImageDistort<GrayU8, GrayU8> distortRight = RectifyImageOps.rectifyImage(intrinsic, rect2_F32, BorderType.SKIP, distortedRight.getImageType());
    distortLeft.apply(distortedLeft, rectifiedLeft);
    distortRight.apply(distortedRight, rectifiedRight);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64)

Example 7 with RectifyCalibrated

use of boofcv.alg.geo.rectify.RectifyCalibrated in project BoofCV by lessthanoptimal.

the class ShowRectifyCalibratedApp method configure.

public void configure(final BufferedImage origLeft, final BufferedImage origRight, StereoParameters param) {
    this.param = param;
    // distorted images
    distLeft = ConvertBufferedImage.convertFromPlanar(origLeft, null, true, GrayF32.class);
    distRight = ConvertBufferedImage.convertFromPlanar(origRight, null, true, GrayF32.class);
    // storage for undistorted + rectified images
    rectLeft = new Planar<>(GrayF32.class, distLeft.getWidth(), distLeft.getHeight(), distLeft.getNumBands());
    rectRight = new Planar<>(GrayF32.class, distRight.getWidth(), distRight.getHeight(), distRight.getNumBands());
    // Compute rectification
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    Se3_F64 leftToRight = param.getRightToLeft().invert(null);
    // original camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.calibrationMatrix(param.getLeft(), (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.calibrationMatrix(param.getRight(), (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    DMatrixRMaj rect1 = rectifyAlg.getRect1();
    DMatrixRMaj rect2 = rectifyAlg.getRect2();
    DMatrixRMaj rectK = rectifyAlg.getCalibrationMatrix();
    // show results and draw a horizontal line where the user clicks to see rectification easier
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            gui.reset();
            gui.addItem(new RectifiedPairPanel(true, origLeft, origRight), "Original");
        }
    });
    // add different types of adjustments
    addRectified("No Adjustment", rect1, rect2);
    RectifyImageOps.allInsideLeft(param.left, rect1, rect2, rectK);
    addRectified("All Inside", rect1, rect2);
    RectifyImageOps.fullViewLeft(param.left, rect1, rect2, rectK);
    addRectified("Full View", rect1, rect2);
    hasProcessed = true;
}
Also used : GrayF32(boofcv.struct.image.GrayF32) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) RectifiedPairPanel(boofcv.gui.stereo.RectifiedPairPanel) Se3_F64(georegression.struct.se.Se3_F64)

Example 8 with RectifyCalibrated

use of boofcv.alg.geo.rectify.RectifyCalibrated in project BoofCV by lessthanoptimal.

the class StereoConsistencyCheck method setCalibration.

public void setCalibration(StereoParameters param) {
    CameraPinholeRadial left = param.getLeft();
    CameraPinholeRadial right = param.getRight();
    // compute rectification
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    Se3_F64 leftToRight = param.getRightToLeft().invert(null);
    // original camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.calibrationMatrix(left, (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.calibrationMatrix(right, (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    DMatrixRMaj rect1 = rectifyAlg.getRect1();
    DMatrixRMaj rect2 = rectifyAlg.getRect2();
    leftImageToRect = RectifyImageOps.transformPixelToRect(param.left, rect1);
    rightImageToRect = RectifyImageOps.transformPixelToRect(param.right, rect2);
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64)

Example 9 with RectifyCalibrated

use of boofcv.alg.geo.rectify.RectifyCalibrated in project BoofCV by lessthanoptimal.

the class StereoProcessingBase method setCalibration.

/**
 * Specifies stereo parameters
 *
 * @param stereoParam stereo parameters
 */
public void setCalibration(StereoParameters stereoParam) {
    CameraPinholeRadial left = stereoParam.getLeft();
    CameraPinholeRadial right = stereoParam.getRight();
    // adjust image size
    imageLeftRect.reshape(left.getWidth(), left.getHeight());
    imageRightRect.reshape(right.getWidth(), right.getHeight());
    // compute rectification
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    Se3_F64 leftToRight = stereoParam.getRightToLeft().invert(null);
    // original camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.calibrationMatrix(left, (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.calibrationMatrix(right, (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    rect1 = rectifyAlg.getRect1();
    rect2 = rectifyAlg.getRect2();
    // New calibration and rotation matrix, Both cameras are the same after rectification.
    rectK = rectifyAlg.getCalibrationMatrix();
    rectR = rectifyAlg.getRectifiedRotation();
    FMatrixRMaj rect1_F32 = new FMatrixRMaj(3, 3);
    FMatrixRMaj rect2_F32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect1, rect1_F32);
    ConvertMatrixData.convert(rect2, rect2_F32);
    ImageType<T> imageType = imageLeftRect.getImageType();
    distortLeftRect = RectifyImageOps.rectifyImage(stereoParam.left, rect1_F32, BorderType.SKIP, imageType);
    distortRightRect = RectifyImageOps.rectifyImage(stereoParam.right, rect2_F32, BorderType.SKIP, imageType);
    // Compute parameters that are needed when converting to 3D
    baseline = stereoParam.getBaseline();
    fx = rectK.get(0, 0);
    fy = rectK.get(1, 1);
    cx = rectK.get(0, 2);
    cy = rectK.get(1, 2);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

RectifyCalibrated (boofcv.alg.geo.rectify.RectifyCalibrated)9 DMatrixRMaj (org.ejml.data.DMatrixRMaj)9 Se3_F64 (georegression.struct.se.Se3_F64)8 FMatrixRMaj (org.ejml.data.FMatrixRMaj)5 GrayF32 (boofcv.struct.image.GrayF32)3 GrayU8 (boofcv.struct.image.GrayU8)3 RectifiedPairPanel (boofcv.gui.stereo.RectifiedPairPanel)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 StereoParameters (boofcv.struct.calib.StereoParameters)2 BufferedImage (java.awt.image.BufferedImage)2 File (java.io.File)2 FDistort (boofcv.abst.distort.FDistort)1 ImageDistort (boofcv.alg.distort.ImageDistort)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 PointCloudViewer (boofcv.gui.d3.PointCloudViewer)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1