Search in sources :

Example 6 with CameraPinholeBrown

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

the class GenericQrCodeDetectorChecks method rotation.

/**
 * See if a clear well defined qr code can be detected while rating
 */
@Test
void rotation() {
    QrCodeDetector<GrayF32> detector = createDetector();
    CameraPinholeBrown model = CalibrationIO.load(getClass().getResource("calib/pinhole_radial.yaml"));
    SimulatePlanarWorld simulator = new SimulatePlanarWorld();
    simulator.setCamera(model);
    simulator.resetScene();
    Se3_F64 markerToWorld = new Se3_F64();
    simulator.addSurface(markerToWorld, simulatedTargetWidth, generateMarker());
    markerToWorld.T.setTo(0, 0, 0.5);
    for (int i = 0; i < 30; i++) {
        double roll = 2 * Math.PI * i / 30.0;
        ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0, Math.PI, roll, markerToWorld.R);
        renderAndCheck(detector, simulator);
    }
}
Also used : SimulatePlanarWorld(boofcv.simulation.SimulatePlanarWorld) GrayF32(boofcv.struct.image.GrayF32) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 7 with CameraPinholeBrown

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

the class CommonEpipolarScore3DChecks method createAssociations.

private List<AssociatedPair> createAssociations(boolean oneCamera, int N, @Nullable PlaneNormal3D_F64 plane, Se3_F64 view0_to_view1) {
    List<Point3D_F64> feats3D;
    if (plane != null) {
        feats3D = UtilPoint3D_F64.random(plane, 0.5, N, rand);
    } else {
        feats3D = UtilPoint3D_F64.random(new Point3D_F64(0, 0, 1), -0.5, 0.5, N, rand);
    }
    var associated = new DogArray<>(AssociatedPair::new);
    // If generated from one camera use the first camera for both views
    CameraPinholeBrown intrinsic2 = oneCamera ? intrinsic1 : this.intrinsic2;
    double sigma = 0.5;
    for (int i = 0; i < feats3D.size(); i++) {
        Point3D_F64 X = feats3D.get(i).copy();
        AssociatedPair a = associated.grow();
        if (X.z <= 0)
            throw new RuntimeException("Point is behind camera! Pick a better scenario");
        PerspectiveOps.renderPixel(intrinsic1, X, a.p1);
        SePointOps_F64.transform(view0_to_view1, X, X);
        if (X.z <= 0)
            throw new RuntimeException("Point is behind camera! Pick a better scenario");
        PerspectiveOps.renderPixel(intrinsic2, X, a.p2);
        // add a little bit of noise so that it isn't perfect
        a.p1.x += rand.nextGaussian() * sigma;
        a.p1.y += rand.nextGaussian() * sigma;
        a.p2.x += rand.nextGaussian() * sigma;
        a.p2.y += rand.nextGaussian() * sigma;
    }
    return associated.toList();
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point3D_F64(georegression.struct.point.Point3D_F64) UtilPoint3D_F64(georegression.geometry.UtilPoint3D_F64) CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) DogArray(org.ddogleg.struct.DogArray)

Example 8 with CameraPinholeBrown

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

the class MonocularPlaneVisualOdometryScaleInput method setCalibration.

@Override
public void setCalibration(MonoPlaneParameters param) {
    scaleParameter.intrinsic = new CameraPinholeBrown(param.intrinsic);
    scaleParameter.planeToCamera = param.planeToCamera.copy();
    PerspectiveOps.scaleIntrinsic(scaleParameter.intrinsic, scaleFactor);
    scaled.reshape(scaleParameter.intrinsic.width, scaleParameter.intrinsic.height);
    alg.setCalibration(scaleParameter);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown)

Example 9 with CameraPinholeBrown

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

the class TestLookUpCameraInfo method addView_lookupVarious.

/**
 * adds a view then retrieves various information and makes sure everything is working correctly
 */
@Test
void addView_lookupVarious() {
    var alg = new LookUpCameraInfo();
    alg.addCameraCanonical(1001, 200, 45);
    alg.addCameraCanonical(1002, 200, 45);
    alg.addCameraCanonical(1003, 200, 45);
    alg.addView("foo", 1);
    assertEquals(1, alg.viewToCamera("foo"));
    ImageDimension shape = new ImageDimension();
    alg.lookupViewShape("foo", shape);
    assertEquals(1002, shape.width);
    CameraPinholeBrown foundCamera = new CameraPinholeBrown();
    alg.lookupCalibration("foo", foundCamera);
    assertEquals(1002, foundCamera.width);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) ImageDimension(boofcv.struct.image.ImageDimension) Test(org.junit.jupiter.api.Test)

Example 10 with CameraPinholeBrown

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

the class MetricSanityChecks method checkPhysicalConstraints.

public boolean checkPhysicalConstraints(SceneStructureMetric structure, SceneObservations observations, List<CameraPinholeBrown> listPriors) {
    BoofMiscOps.checkEq(listPriors.size(), structure.views.size);
    for (int i = 0; i < structure.cameras.size; i++) {
        BundlePinholeSimplified pinhole = (BundlePinholeSimplified) structure.cameras.get(i).model;
        if (pinhole.f < 0.0f) {
            if (verbose != null)
                verbose.println("Bad focal length. f=" + pinhole.f);
            return false;
        }
    }
    badFeatures.resetResize(structure.points.size, false);
    var worldP = new Point4D_F64(0, 0, 0, 1);
    var viewP = new Point4D_F64();
    var observedPixel = new Point2D_F64();
    var predictdPixel = new Point2D_F64();
    for (int viewIdx = 0; viewIdx < observations.views.size; viewIdx++) {
        int cameraIdx = structure.views.get(viewIdx).camera;
        BundlePinholeSimplified pinhole = (BundlePinholeSimplified) Objects.requireNonNull(structure.cameras.get(cameraIdx).model);
        CameraPinholeBrown priorCamera = listPriors.get(viewIdx);
        int width = priorCamera.width;
        int height = priorCamera.height;
        // Used to compensates for the lens model having its origin at the image center
        float cx = (float) priorCamera.cx;
        float cy = (float) priorCamera.cy;
        // Number of times each test failed in this particular view
        int failedBehind = 0;
        int failedImageBounds = 0;
        int failedReprojection = 0;
        Se3_F64 world_to_view = structure.getParentToView(viewIdx);
        SceneObservations.View oview = observations.views.get(viewIdx);
        for (int i = 0; i < oview.size(); i++) {
            // If true then this feature failed one of the constraints test in tis value
            boolean badObservation = false;
            oview.getPixel(i, observedPixel);
            SceneStructureCommon.Point p = structure.points.get(oview.getPointId(i));
            worldP.x = p.getX();
            worldP.y = p.getY();
            worldP.z = p.getZ();
            if (structure.isHomogenous()) {
                worldP.w = p.getW();
            }
            // worldP.w = 1 was already set for 3D points
            SePointOps_F64.transform(world_to_view, worldP, viewP);
            if (PerspectiveOps.isBehindCamera(viewP)) {
                badObservation = true;
                failedBehind++;
            }
            pinhole.project(viewP.x, viewP.y, viewP.z, predictdPixel);
            double reprojectionError = predictdPixel.distance2(observedPixel);
            if (reprojectionError > maxReprojectionErrorSq) {
                badObservation = true;
                failedReprojection++;
            }
            if (!BoofMiscOps.isInside(width, height, predictdPixel.x + cx, predictdPixel.y + cy)) {
                badObservation = true;
                failedImageBounds++;
            }
            if (badObservation) {
                badFeatures.set(oview.getPointId(i), true);
            }
        }
        if (verbose != null)
            verbose.printf("view[%d] errors: behind=%d bounds=%d reprojection=%d, obs=%d\n", viewIdx, failedBehind, failedImageBounds, failedReprojection, oview.size());
    }
    return true;
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified) SceneStructureCommon(boofcv.abst.geo.bundle.SceneStructureCommon) VerbosePrint(org.ddogleg.struct.VerbosePrint) Point2D_F64(georegression.struct.point.Point2D_F64) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) Point4D_F64(georegression.struct.point.Point4D_F64) Se3_F64(georegression.struct.se.Se3_F64)

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