Search in sources :

Example 31 with FMatrixRMaj

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

the class TestRectifyImageOps method allInsideLeft_uncalibrated.

@Test
public void allInsideLeft_uncalibrated() {
    // do nothing rectification
    FMatrixRMaj rect1 = CommonOps_FDRM.diag(2, 3, 1);
    FMatrixRMaj rect2 = CommonOps_FDRM.diag(0.5f, 2, 1);
    RectifyImageOps.allInsideLeft(300, 250, rect1, rect2);
    // check left image
    FMatrixRMaj inv = new FMatrixRMaj(3, 3);
    CommonOps_FDRM.invert(rect1, inv);
    PointTransformHomography_F32 tran = new PointTransformHomography_F32(inv);
    checkInside(tran);
// the right view is not checked since it is not part of the contract
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) PointTransformHomography_F32(boofcv.alg.distort.PointTransformHomography_F32) Test(org.junit.Test)

Example 32 with FMatrixRMaj

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

the class TestRemoveRadialPtoN_F32 method checkAgainstAdd.

public void checkAgainstAdd(float t1, float t2) {
    float fx = 600;
    float fy = 500;
    float skew = 2;
    float xc = 300;
    float yc = 350;
    /**/
    double[] radial = new /**/
    double[] { 0.12, -0.13 };
    Point2D_F32 point = new Point2D_F32();
    float undistX = 19.5f;
    float undistY = 200.1f;
    AddRadialPtoN_F32 p_to_n = new AddRadialPtoN_F32().setK(fx, fy, skew, xc, yc).setDistortion(radial, t1, t2);
    new Transform2ThenPixel_F32(p_to_n).set(fx, fy, skew, xc, yc).compute(undistX, undistY, point);
    float distX = point.x;
    float distY = point.y;
    RemoveRadialPtoN_F32 alg = new RemoveRadialPtoN_F32().setK(fx, fy, skew, xc, yc).setDistortion(radial, t1, t2);
    alg.compute(distX, distY, point);
    // / go from calibrated coordinates to pixel
    FMatrixRMaj K = PerspectiveOps.calibrationMatrix(fx, fy, skew, xc, yc);
    GeometryMath_F32.mult(K, point, point);
    assertEquals(undistX, point.x, GrlConstants.TEST_SQ_F32);
    assertEquals(undistY, point.y, GrlConstants.TEST_SQ_F32);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) Transform2ThenPixel_F32(boofcv.alg.distort.Transform2ThenPixel_F32) Point2D_F32(georegression.struct.point.Point2D_F32)

Example 33 with FMatrixRMaj

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

the class TestPerspectiveOps method matrixToPinhole_F.

@Test
void matrixToPinhole_F() {
    float fx = 1;
    float fy = 2;
    float skew = 3;
    float cx = 4;
    float cy = 5;
    FMatrixRMaj K = new FMatrixRMaj(3, 3, true, fx, skew, cx, 0, fy, cy, 0, 0, 1);
    CameraPinhole ret = PerspectiveOps.matrixToPinhole(K, 100, 200, null);
    assertEquals(ret.fx, fx);
    assertEquals(ret.fy, fy);
    assertEquals(ret.skew, skew);
    assertEquals(ret.cx, cx);
    assertEquals(ret.cy, cy);
    assertEquals(100, ret.width);
    assertEquals(200, ret.height);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Example 34 with FMatrixRMaj

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

the class TestPerspectiveOps method pinholeToMatrix_params_F.

@Test
void pinholeToMatrix_params_F() {
    FMatrixRMaj K = PerspectiveOps.pinholeToMatrix(1.0f, 2f, 3f, 4, 5);
    assertEquals(1, K.get(0, 0), UtilEjml.TEST_F32);
    assertEquals(2, K.get(1, 1), UtilEjml.TEST_F32);
    assertEquals(3, K.get(0, 1), UtilEjml.TEST_F32);
    assertEquals(4, K.get(0, 2), UtilEjml.TEST_F32);
    assertEquals(5, K.get(1, 2), UtilEjml.TEST_F32);
    assertEquals(1, K.get(2, 2), UtilEjml.TEST_F32);
}
Also used : FMatrixRMaj(org.ejml.data.FMatrixRMaj) Test(org.junit.jupiter.api.Test)

Example 35 with FMatrixRMaj

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

the class StereoProcessingBase method setCalibration.

/**
 * Specifies stereo parameters
 *
 * @param stereoParam stereo parameters
 */
public void setCalibration(StereoParameters stereoParam) {
    CameraPinholeBrown left = stereoParam.getLeft();
    CameraPinholeBrown 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.pinholeToMatrix(left, (DMatrixRMaj) null);
    DMatrixRMaj K2 = PerspectiveOps.pinholeToMatrix(right, (DMatrixRMaj) null);
    rectifyAlg.process(K1, new Se3_F64(), K2, leftToRight);
    // rectification matrix for each image
    rect1 = rectifyAlg.getUndistToRectPixels1();
    rect2 = rectifyAlg.getUndistToRectPixels2();
    // 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 = RectifyDistortImageOps.rectifyImage(stereoParam.left, rect1_F32, BorderType.SKIP, imageType);
    distortRightRect = RectifyDistortImageOps.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) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) RectifyCalibrated(boofcv.alg.geo.rectify.RectifyCalibrated) DMatrixRMaj(org.ejml.data.DMatrixRMaj) 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