Search in sources :

Example 76 with CameraPinholeBrown

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

the class ImplRectifyImageOps_F64 method allInsideLeft.

public static void allInsideLeft(CameraPinholeBrown paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK, ImageDimension rectifiedSize) {
    // need to take in account the order in which image distort will remove rectification later on
    paramLeft = new CameraPinholeBrown(paramLeft);
    Point2Transform2_F64 tranLeft = transformPixelToRect(paramLeft, rectifyLeft);
    Point2D_F64 work = new Point2D_F64();
    RectangleLength2D_F64 bound = LensDistortionOps_F64.boundBoxInside(paramLeft.width, paramLeft.height, new PointToPixelTransform_F64(tranLeft), work);
    LensDistortionOps_F64.roundInside(bound);
    // Select scale to maintain the same number of pixels
    double scale = Math.sqrt((paramLeft.width * paramLeft.height) / (bound.width * bound.height));
    rectifiedSize.width = (int) (scale * bound.width + 0.5);
    rectifiedSize.height = (int) (scale * bound.height + 0.5);
    adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Point2D_F64(georegression.struct.point.Point2D_F64) SequencePoint2Transform2_F64(boofcv.struct.distort.SequencePoint2Transform2_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) PointToPixelTransform_F64(boofcv.struct.distort.PointToPixelTransform_F64) RectangleLength2D_F64(georegression.struct.shapes.RectangleLength2D_F64)

Example 77 with CameraPinholeBrown

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

the class ImplRectifyImageOps_F64 method fullViewLeft.

public static void fullViewLeft(CameraPinholeBrown paramLeft, DMatrixRMaj rectifyLeft, DMatrixRMaj rectifyRight, DMatrixRMaj rectifyK, ImageDimension rectifiedSize) {
    // need to take in account the order in which image distort will remove rectification later on
    paramLeft = new CameraPinholeBrown(paramLeft);
    Point2Transform2_F64 tranLeft = transformPixelToRect(paramLeft, rectifyLeft);
    Point2D_F64 work = new Point2D_F64();
    RectangleLength2D_F64 bound = DistortImageOps.boundBox_F64(paramLeft.width, paramLeft.height, new PointToPixelTransform_F64(tranLeft), work);
    // Select scale to maintain the same number of pixels
    double scale = Math.sqrt((paramLeft.width * paramLeft.height) / (bound.width * bound.height));
    rectifiedSize.width = (int) (scale * bound.width + 0.5);
    rectifiedSize.height = (int) (scale * bound.height + 0.5);
    adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Point2D_F64(georegression.struct.point.Point2D_F64) SequencePoint2Transform2_F64(boofcv.struct.distort.SequencePoint2Transform2_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) PointToPixelTransform_F64(boofcv.struct.distort.PointToPixelTransform_F64) RectangleLength2D_F64(georegression.struct.shapes.RectangleLength2D_F64)

Example 78 with CameraPinholeBrown

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

the class TestDepthSparse3D method basicTest.

@Test
void basicTest() {
    GrayU16 depth = new GrayU16(w, h);
    depth.set(5, 6, 1000);
    CameraPinholeBrown param = new CameraPinholeBrown(1, 1, 0, 5, 10, w, h).fsetRadial(0, 0);
    PixelTransform<Point2D_F32> v2d = new PixelTransform<Point2D_F32>() {

        @Override
        public void compute(int x, int y, Point2D_F32 output) {
            output.x = x + 1;
            output.y = y + 2;
        }

        @Override
        public PixelTransform<Point2D_F32> copyConcurrent() {
            return null;
        }
    };
    DepthSparse3D<GrayU16> alg = new DepthSparse3D.I<>(2.1);
    alg.configure(LensDistortionFactory.narrow(param), v2d);
    alg.setDepthImage(depth);
    assertTrue(alg.process(4, 4));
    Point3D_F64 found = alg.getWorldPt();
    Point2D_F64 norm = new Point2D_F64();
    PerspectiveOps.convertPixelToNorm(param, new Point2D_F64(4, 4), norm);
    double z = 1000 * 2.1;
    assertEquals(z, found.z, 1e-8);
    assertEquals(norm.x * z, found.x, 1e-8);
    assertEquals(norm.y * z, found.y, 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) GrayU16(boofcv.struct.image.GrayU16) Point2D_F64(georegression.struct.point.Point2D_F64) Point2D_F32(georegression.struct.point.Point2D_F32) PixelTransform(boofcv.struct.distort.PixelTransform) Test(org.junit.jupiter.api.Test)

Example 79 with CameraPinholeBrown

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

the class TestPnPStereoResidualReprojection method compareToReprojection.

@Test
void compareToReprojection() {
    Se3_F64 worldToLeft = new Se3_F64();
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.1, 1, -0.2, worldToLeft.getR());
    worldToLeft.getT().setTo(-0.3, 0.4, 1);
    generateScene(10, worldToLeft, false);
    // make the input model incorrect
    worldToLeft.getR().set(2, 1, 2);
    // compute the error in normalized image coordinates per element
    PnPStereoResidualReprojection alg = new PnPStereoResidualReprojection();
    alg.setModel(new StereoPose(worldToLeft, leftToRight));
    // compute errors with perfect model
    double[] error = new double[alg.getN()];
    alg.computeResiduals(pointPose.get(0), error, 0);
    double found = 0;
    for (double e : error) {
        found += e * e;
    }
    PnPStereoDistanceReprojectionSq validation = new PnPStereoDistanceReprojectionSq();
    StereoParameters param = new StereoParameters();
    param.right_to_left = this.param.right_to_left;
    // intrinsic parameters are configured to be identical to normalized image coordinates
    param.left = new CameraPinholeBrown(1, 1, 0, 0, 0, 0, 0).fsetRadial(0, 0);
    param.right = new CameraPinholeBrown(1, 1, 0, 0, 0, 0, 0).fsetRadial(0, 0);
    validation.setStereoParameters(param);
    validation.setModel(worldToLeft);
    double expected = validation.distance(pointPose.get(0));
    assertEquals(expected, found, 1e-8);
}
Also used : StereoPose(boofcv.struct.sfm.StereoPose) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) StereoParameters(boofcv.struct.calib.StereoParameters) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 80 with CameraPinholeBrown

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

the class TestSelectTracksInFrameForBundleAdjustment method minimal_all.

/**
 * Basic test. Each track is visible in every frame at the same location.
 */
@Test
void minimal_all() {
    var scene = new VisOdomBundleAdjustment<>(BTrack::new);
    var alg = new SelectTracksInFrameForBundleAdjustment(0xBEEF);
    // makes the math easier
    alg.configUniform.regionScaleFactor = 1.0;
    alg.maxFeaturesPerFrame = 200;
    var selected = new ArrayList<BTrack>();
    scene.addCamera(new CameraPinholeBrown(0, 0, 0, 0, 0, width, height));
    for (int i = 0; i < 5; i++) {
        scene.addFrame(i);
    }
    for (int i = 0; i < 200; i++) {
        scene.tracks.grow().id = i;
    }
    for (int i = 0; i < scene.frames.size; i++) {
        BFrame frame = scene.frames.get(i);
        for (int j = 0; j < 200; j++) {
            BTrack track = scene.tracks.get(j);
            frame.tracks.add(track);
            // pixel coordinates
            int x = (i * 10) % width;
            int y = 10 * ((i * 10) / width);
            VisOdomBundleAdjustment.BObservation o = track.observations.grow();
            o.frame = frame;
            o.pixel.setTo(x, y);
        }
    }
    alg.selectTracks(scene, selected);
    assertEquals(200, selected.size());
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) BFrame(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BFrame) ArrayList(java.util.ArrayList) BTrack(boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack) Test(org.junit.jupiter.api.Test)

Aggregations

CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)99 Test (org.junit.jupiter.api.Test)62 Se3_F64 (georegression.struct.se.Se3_F64)39 GrayF32 (boofcv.struct.image.GrayF32)29 Point2D_F64 (georegression.struct.point.Point2D_F64)19 SimulatePlanarWorld (boofcv.simulation.SimulatePlanarWorld)16 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)14 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)14 BufferedImage (java.awt.image.BufferedImage)14 ArrayList (java.util.ArrayList)12 CameraPinhole (boofcv.struct.calib.CameraPinhole)11 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)10 DMatrixRMaj (org.ejml.data.DMatrixRMaj)10 File (java.io.File)9 StereoParameters (boofcv.struct.calib.StereoParameters)6 GrayU8 (boofcv.struct.image.GrayU8)6 Point3D_F64 (georegression.struct.point.Point3D_F64)6 ImageBase (boofcv.struct.image.ImageBase)5 ImageType (boofcv.struct.image.ImageType)5 DogArray (org.ddogleg.struct.DogArray)5