Search in sources :

Example 11 with StereoParameters

use of boofcv.struct.calib.StereoParameters in project BoofCV by lessthanoptimal.

the class TestPnPStereoDistanceReprojectionSq method checkBehind.

public void checkBehind(double Tz, double Pz) {
    // Point location in world frame
    Point3D_F64 X = new Point3D_F64(0.1, -0.04, Pz);
    DMatrixRMaj K_left = PerspectiveOps.calibrationMatrix(param.left, (DMatrixRMaj) null);
    DMatrixRMaj K_right = PerspectiveOps.calibrationMatrix(param.right, (DMatrixRMaj) null);
    // create a noisy observed
    Point2D_F64 obsLeft = PerspectiveOps.renderPixel(worldToLeft, K_left, X);
    Point2D_F64 obsRight = PerspectiveOps.renderPixel(worldToRight, K_right, X);
    // convert to normalized image coordinates
    PerspectiveOps.convertPixelToNorm(K_left, obsLeft, obsLeft);
    PerspectiveOps.convertPixelToNorm(K_right, obsRight, obsRight);
    PnPStereoDistanceReprojectionSq alg = new PnPStereoDistanceReprojectionSq();
    StereoParameters param = new StereoParameters(this.param.left, this.param.right, new Se3_F64());
    param.rightToLeft.getT().set(0.1, 0, Tz);
    alg.setStereoParameters(param);
    alg.setModel(new Se3_F64());
    double found = alg.computeDistance(new Stereo2D3D(obsLeft, obsRight, X));
    assertTrue(Double.MAX_VALUE == found);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Stereo2D3D(boofcv.struct.sfm.Stereo2D3D) DMatrixRMaj(org.ejml.data.DMatrixRMaj) StereoParameters(boofcv.struct.calib.StereoParameters) Se3_F64(georegression.struct.se.Se3_F64)

Example 12 with StereoParameters

use of boofcv.struct.calib.StereoParameters in project BoofCV by lessthanoptimal.

the class TestStereoProcessingBase method createStereoParam.

public static StereoParameters createStereoParam(int width, int height) {
    StereoParameters ret = new StereoParameters();
    ret.setRightToLeft(new Se3_F64());
    ret.getRightToLeft().getT().set(-0.2, 0.001, -0.012);
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.001, -0.01, 0.0023, ret.getRightToLeft().getR());
    ret.left = new CameraPinholeRadial().fsetK(300, 320, 0, width / 2, height / 2, width, height).fsetRadial(0.1, 1e-4);
    ret.right = new CameraPinholeRadial().fsetK(290, 310, 0, width / 2 + 2, height / 2 - 6, width, height).fsetRadial(0.05, -2e-4);
    return ret;
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) StereoParameters(boofcv.struct.calib.StereoParameters) Se3_F64(georegression.struct.se.Se3_F64)

Example 13 with StereoParameters

use of boofcv.struct.calib.StereoParameters in project BoofCV by lessthanoptimal.

the class TestStereoProcessingBase method compute3D.

@Test
public void compute3D() {
    // point being viewed
    Point3D_F64 X = new Point3D_F64(-0.01, 0.1, 3);
    StereoParameters param = createStereoParam(width, height);
    DMatrixRMaj K = PerspectiveOps.calibrationMatrix(param.left, (DMatrixRMaj) null);
    // compute the view in pixels of the point in the left and right cameras
    Point2D_F64 lensLeft = new Point2D_F64();
    Point2D_F64 lensRight = new Point2D_F64();
    SfmTestHelper.renderPointPixel(param, X, lensLeft, lensRight);
    StereoProcessingBase<GrayU8> alg = new StereoProcessingBase<>(GrayU8.class);
    alg.setCalibration(param);
    // Rectify the points
    Point2Transform2_F64 rectLeft = RectifyImageOps.transformPixelToRect(param.left, alg.getRect1());
    Point2Transform2_F64 rectRight = RectifyImageOps.transformPixelToRect(param.right, alg.getRect2());
    Point2D_F64 l = new Point2D_F64();
    Point2D_F64 r = new Point2D_F64();
    rectLeft.compute(lensLeft.x, lensLeft.y, l);
    rectRight.compute(lensRight.x, lensRight.y, r);
    // make sure I rectified it correctly
    assertEquals(l.y, r.y, 1);
    // find point in homogeneous coordinates
    Point3D_F64 found = new Point3D_F64();
    alg.computeHomo3D(l.x, l.y, found);
    // disparity between the two images
    double disparity = l.x - r.x;
    found.x /= disparity;
    found.y /= disparity;
    found.z /= disparity;
    assertTrue(found.isIdentical(X, 0.01));
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) GrayU8(boofcv.struct.image.GrayU8) StereoParameters(boofcv.struct.calib.StereoParameters) Test(org.junit.Test)

Example 14 with StereoParameters

use of boofcv.struct.calib.StereoParameters in project BoofCV by lessthanoptimal.

the class TestStereoProcessingBase method checkRectification.

/**
 * Center a point in the left and right images.  Search for the point and see if after rectification
 * the point can be found on the same row in both images.
 */
@Test
public void checkRectification() {
    // point being viewed
    Point3D_F64 X = new Point3D_F64(-0.01, 0.1, 3);
    StereoParameters param = createStereoParam(width, height);
    // create input images by rendering the point in both
    GrayU8 left = new GrayU8(width, height);
    GrayU8 right = new GrayU8(width, height);
    // compute the view in pixels of the point in the left and right cameras
    Point2D_F64 lensLeft = new Point2D_F64();
    Point2D_F64 lensRight = new Point2D_F64();
    SfmTestHelper.renderPointPixel(param, X, lensLeft, lensRight);
    // render the pixel in the image
    left.set((int) lensLeft.x, (int) lensLeft.y, 200);
    right.set((int) lensRight.x, (int) lensRight.y, 200);
    // test the algorithm
    StereoProcessingBase<GrayU8> alg = new StereoProcessingBase<>(GrayU8.class);
    alg.setCalibration(param);
    alg.setImages(left, right);
    alg.initialize();
    // Test tolerances are set to one pixel due to discretization errors in the image
    // sanity check test
    assertFalse(Math.abs(lensLeft.y - lensRight.y) <= 1);
    // check properties of a rectified image and stereo pairs
    Point2D_F64 foundLeft = centroid(alg.getImageLeftRect());
    Point2D_F64 foundRight = centroid(alg.getImageRightRect());
    assertTrue(Math.abs(foundLeft.y - foundRight.y) <= 1);
    assertTrue(foundRight.x < foundLeft.x);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) GrayU8(boofcv.struct.image.GrayU8) StereoParameters(boofcv.struct.calib.StereoParameters) Test(org.junit.Test)

Example 15 with StereoParameters

use of boofcv.struct.calib.StereoParameters in project BoofCV by lessthanoptimal.

the class CheckVisualOdometryStereoSim method createStereoParam.

public StereoParameters createStereoParam() {
    StereoParameters ret = new StereoParameters();
    ret.setRightToLeft(new Se3_F64());
    ret.getRightToLeft().getT().set(-0.2, 0.001, -0.012);
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.001, -0.01, 0.0023, ret.getRightToLeft().getR());
    ret.left = new CameraPinholeRadial(200, 201, 0, width / 2, height / 2, width, height).fsetRadial(0, 0);
    ret.right = new CameraPinholeRadial(199, 200, 0, width / 2 + 2, height / 2 - 6, width, height).fsetRadial(0, 0);
    return ret;
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) StereoParameters(boofcv.struct.calib.StereoParameters) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

StereoParameters (boofcv.struct.calib.StereoParameters)25 Se3_F64 (georegression.struct.se.Se3_F64)12 Test (org.junit.Test)9 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)8 BufferedImage (java.awt.image.BufferedImage)8 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)7 GrayF32 (boofcv.struct.image.GrayF32)7 GrayU8 (boofcv.struct.image.GrayU8)6 Point3D_F64 (georegression.struct.point.Point3D_F64)5 Point2D_F64 (georegression.struct.point.Point2D_F64)4 DMatrixRMaj (org.ejml.data.DMatrixRMaj)4 File (java.io.File)3 CalibrationObservation (boofcv.alg.geo.calibration.CalibrationObservation)2 RectifyCalibrated (boofcv.alg.geo.rectify.RectifyCalibrated)2 ListDisplayPanel (boofcv.gui.ListDisplayPanel)2 FDistort (boofcv.abst.distort.FDistort)1 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)1 CalibrateStereoPlanar (boofcv.abst.geo.calibration.CalibrateStereoPlanar)1 ImageDistort (boofcv.alg.distort.ImageDistort)1 CreateSyntheticOverheadViewPL (boofcv.alg.sfm.overhead.CreateSyntheticOverheadViewPL)1