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);
}
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;
}
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);
}
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);
}
Aggregations