Search in sources :

Example 11 with FMatrixRMaj

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

the class ImplPerspectiveOps_F32 method createCameraMatrix.

public static FMatrixRMaj createCameraMatrix(FMatrixRMaj R, Vector3D_F32 T, FMatrixRMaj K, FMatrixRMaj ret) {
    if (ret == null)
        ret = new FMatrixRMaj(3, 4);
    CommonOps_FDRM.insert(R, ret, 0, 0);
    ret.data[3] = T.x;
    ret.data[7] = T.y;
    ret.data[11] = T.z;
    if (K == null)
        return ret;
    FMatrixRMaj temp = new FMatrixRMaj(3, 4);
    CommonOps_FDRM.mult(K, ret, temp);
    ret.set(temp);
    return ret;
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj)

Example 12 with FMatrixRMaj

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

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

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

the class ExampleFisheyeToEquirectangular method main.

public static void main(String[] args) {
    // Path to image data and calibration data
    String fisheyePath = UtilIO.pathExample("fisheye/theta");
    // load the fisheye camera parameters
    CameraUniversalOmni model0 = CalibrationIO.load(new File(fisheyePath, "front.yaml"));
    CameraUniversalOmni model1 = CalibrationIO.load(new File(fisheyePath, "back.yaml"));
    LensDistortionWideFOV distort0 = new LensDistortionUniversalOmni(model0);
    LensDistortionWideFOV distort1 = new LensDistortionUniversalOmni(model1);
    ImageType<Planar<GrayF32>> imageType = ImageType.pl(3, GrayF32.class);
    InterpolatePixel<Planar<GrayF32>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, imageType);
    ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distort = FactoryDistort.distort(false, interp, imageType);
    // This will create an equirectangular image with 800 x 400 pixels
    MultiCameraToEquirectangular<Planar<GrayF32>> alg = new MultiCameraToEquirectangular<>(distort, 800, 400, imageType);
    // this is an important parameter and is used to filter out falsely mirrored pixels
    alg.setMaskToleranceAngle(UtilAngle.radian(0.1f));
    // camera has a known FOV of 185 degrees
    GrayU8 mask0 = createMask(model0, distort0, UtilAngle.radian(182));
    // the edges are likely to be noisy,
    GrayU8 mask1 = createMask(model1, distort1, UtilAngle.radian(182));
    // so crop it a bit..
    // Rotate camera axis so that +x is forward and not +z and make it visually pleasing
    FMatrixRMaj adjR = ConvertRotation3D_F32.eulerToMatrix(EulerType.XYZ, GrlConstants.F_PI / 2, 0, 0, null);
    // Rotation from the front camera to the back facing camera.
    // This is only an approximation. Should be determined through calibration.
    FMatrixRMaj f2b = ConvertRotation3D_F32.eulerToMatrix(EulerType.ZYX, GrlConstants.F_PI, 0, 0, null);
    Se3_F32 frontToFront = new Se3_F32();
    frontToFront.setRotation(adjR);
    Se3_F32 frontToBack = new Se3_F32();
    CommonOps_FDRM.mult(f2b, adjR, frontToBack.R);
    // add the camera and specify which pixels are valid. These functions precompute the entire transform
    // and can be relatively slow, but generating the equirectangular image should be much faster
    alg.addCamera(frontToBack, distort0, mask0);
    alg.addCamera(frontToFront, distort1, mask1);
    // Load fisheye RGB image
    BufferedImage buffered0 = UtilImageIO.loadImage(fisheyePath, "front_table.jpg");
    Planar<GrayF32> fisheye0 = ConvertBufferedImage.convertFrom(buffered0, true, ImageType.pl(3, GrayF32.class));
    BufferedImage buffered1 = UtilImageIO.loadImage(fisheyePath, "back_table.jpg");
    Planar<GrayF32> fisheye1 = ConvertBufferedImage.convertFrom(buffered1, true, ImageType.pl(3, GrayF32.class));
    List<Planar<GrayF32>> images = new ArrayList<>();
    images.add(fisheye0);
    images.add(fisheye1);
    alg.render(images);
    BufferedImage equiOut = ConvertBufferedImage.convertTo(alg.getRenderedImage(), null, true);
    ShowImages.showWindow(equiOut, "Dual Fisheye to Equirectangular", true);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) LensDistortionWideFOV(boofcv.alg.distort.LensDistortionWideFOV) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) MultiCameraToEquirectangular(boofcv.alg.distort.MultiCameraToEquirectangular) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) LensDistortionUniversalOmni(boofcv.alg.distort.universal.LensDistortionUniversalOmni) File(java.io.File) Se3_F32(georegression.struct.se.Se3_F32)

Example 15 with FMatrixRMaj

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

the class ExampleStereoDisparity method rectify.

/**
 * Rectified the input images using known calibration.
 */
public static RectifyCalibrated rectify(GrayU8 origLeft, GrayU8 origRight, StereoParameters param, GrayU8 rectLeft, GrayU8 rectRight) {
    // Compute rectification
    RectifyCalibrated rectifyAlg = RectifyImageOps.createCalibrated();
    Se3_F64 leftToRight = param.getRightToLeft().invert(null);
    // original camera calibration matrices
    DMatrixRMaj K1 = PerspectiveOps.pinholeToMatrix(param.getLeft(), (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.pinholeToMatrix(param.getRight(), (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    DMatrixRMaj rect1 = rectifyAlg.getUndistToRectPixels1();
    DMatrixRMaj rect2 = rectifyAlg.getUndistToRectPixels2();
    // New calibration matrix,
    DMatrixRMaj rectK = rectifyAlg.getCalibrationMatrix();
    // Adjust the rectification to make the view area more useful
    RectifyImageOps.allInsideLeft(param.left, rect1, rect2, rectK, null);
    // undistorted and rectify images
    var rect1_F32 = new FMatrixRMaj(3, 3);
    var rect2_F32 = new FMatrixRMaj(3, 3);
    ConvertMatrixData.convert(rect1, rect1_F32);
    ConvertMatrixData.convert(rect2, rect2_F32);
    ImageDistort<GrayU8, GrayU8> imageDistortLeft = RectifyDistortImageOps.rectifyImage(param.getLeft(), rect1_F32, BorderType.SKIP, origLeft.getImageType());
    ImageDistort<GrayU8, GrayU8> imageDistortRight = RectifyDistortImageOps.rectifyImage(param.getRight(), rect2_F32, BorderType.SKIP, origRight.getImageType());
    imageDistortLeft.apply(origLeft, rectLeft);
    imageDistortRight.apply(origRight, rectRight);
    return rectifyAlg;
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) GrayU8(boofcv.struct.image.GrayU8) Se3_F64(georegression.struct.se.Se3_F64)

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