Search in sources :

Example 56 with Point4D_F64

use of georegression.struct.point.Point4D_F64 in project BoofCV by lessthanoptimal.

the class VisOdomPixelDepthPnP_to_DepthVisualOdometry method getTrackWorld3D.

@Override
public boolean getTrackWorld3D(int index, Point3D_F64 world) {
    try {
        Point4D_F64 p = ((VisOdomBundleAdjustment.BTrack) active.get(index).getCookie()).worldLoc;
        world.setTo(p.x / p.w, p.y / p.w, p.z / p.w);
        return true;
    } catch (RuntimeException ignore) {
    /* not handled */
    }
    world.setTo(((Point2D3D) active.get(index).getCookie()).getLocation());
    return true;
}
Also used : Point4D_F64(georegression.struct.point.Point4D_F64)

Example 57 with Point4D_F64

use of georegression.struct.point.Point4D_F64 in project BoofCV by lessthanoptimal.

the class MetricSanityChecks method checkPhysicalConstraints.

/**
 * Checks physical constraints for one inlier set in a {@link SceneWorkingGraph}. Features are triangulated
 * directly from observations. Raw counts for each type of error can be found for this function.
 *
 * @param dbSimilar Use to get feature locations in the image
 * @param scene The scene
 * @param wview The view to check
 * @param setIdx Which inlier set in the view
 * @return true if nothing went wrong or false if a very nasty error was detected
 */
public boolean checkPhysicalConstraints(LookUpSimilarImages dbSimilar, SceneWorkingGraph scene, SceneWorkingGraph.View wview, int setIdx) {
    failedTriangulate = 0;
    failedBehind = 0;
    failedImageBounds = 0;
    failedReprojection = 0;
    SceneWorkingGraph.InlierInfo inliers = wview.inliers.get(setIdx);
    int numFeatures = inliers.getInlierCount();
    badFeatures.resetResize(numFeatures, false);
    List<SceneWorkingGraph.View> listViews = new ArrayList<>();
    List<RemoveBrownPtoN_F64> listNormalize = new ArrayList<>();
    List<Se3_F64> listMotion = new ArrayList<>();
    List<DogArray<Point2D_F64>> listFeatures = new ArrayList<>();
    List<Point2D_F64> listViewPixels = new ArrayList<>();
    Se3_F64 view1_to_world = wview.world_to_view.invert(null);
    for (int i = 0; i < inliers.views.size; i++) {
        SceneWorkingGraph.View w = scene.lookupView(inliers.views.get(i).id);
        SceneWorkingGraph.Camera c = scene.getViewCamera(w);
        if (c.intrinsic.f <= 0.0) {
            if (verbose != null)
                verbose.println("Negative focal length. view='" + w.pview.id + "'");
            return false;
        }
        listViews.add(w);
        // TODO switch to known camera if available
        var normalize = new RemoveBrownPtoN_F64();
        normalize.setK(c.intrinsic.f, c.intrinsic.f, 0, 0, 0).setDistortion(c.intrinsic.k1, c.intrinsic.k2);
        listNormalize.add(normalize);
        listMotion.add(view1_to_world.concat(w.world_to_view, null));
        SceneWorkingGraph.Camera wcamera = scene.getViewCamera(w);
        var features = new DogArray<>(Point2D_F64::new);
        dbSimilar.lookupPixelFeats(w.pview.id, features);
        double cx = wcamera.prior.cx;
        double cy = wcamera.prior.cy;
        features.forEach(p -> p.setTo(p.x - cx, p.y - cy));
        listFeatures.add(features);
    }
    List<Point2D_F64> pixelNorms = BoofMiscOps.createListFilled(inliers.views.size, Point2D_F64::new);
    Point4D_F64 foundX = new Point4D_F64();
    Point4D_F64 viewX = new Point4D_F64();
    Point2D_F64 predictdPixel = new Point2D_F64();
    SceneWorkingGraph.Camera wviewCamera = scene.getViewCamera(wview);
    for (int inlierIdx = 0; inlierIdx < numFeatures; inlierIdx++) {
        listViewPixels.clear();
        for (int viewIdx = 0; viewIdx < listViews.size(); viewIdx++) {
            Point2D_F64 p = listFeatures.get(viewIdx).get(inliers.observations.get(viewIdx).get(inlierIdx));
            listViewPixels.add(p);
            listNormalize.get(viewIdx).compute(p.x, p.y, pixelNorms.get(viewIdx));
        }
        if (!triangulator.triangulate(pixelNorms, listMotion, foundX)) {
            failedTriangulate++;
            badFeatures.set(inlierIdx, true);
            continue;
        }
        boolean badObservation = false;
        for (int viewIdx = 0; viewIdx < listViews.size(); viewIdx++) {
            Se3_F64 view1_to_view = listMotion.get(viewIdx);
            SceneWorkingGraph.View w = listViews.get(viewIdx);
            SePointOps_F64.transform(view1_to_view, foundX, viewX);
            if (PerspectiveOps.isBehindCamera(viewX)) {
                badObservation = true;
                failedBehind++;
            }
            wviewCamera.intrinsic.project(viewX.x, viewX.y, viewX.z, predictdPixel);
            double reprojectionError = predictdPixel.distance2(listViewPixels.get(viewIdx));
            if (reprojectionError > maxReprojectionErrorSq) {
                badObservation = true;
                failedReprojection++;
            }
            SceneWorkingGraph.Camera wcamera = scene.getViewCamera(w);
            int width = wcamera.prior.width;
            int height = wcamera.prior.height;
            double cx = wcamera.prior.cx;
            double cy = wcamera.prior.cy;
            if (!BoofMiscOps.isInside(width, height, predictdPixel.x + cx, predictdPixel.y + cy)) {
                badObservation = true;
                failedImageBounds++;
            }
        }
        badFeatures.set(inlierIdx, badObservation);
    }
    if (verbose != null)
        verbose.printf("view.id='%s' inlierIdx=%d, errors: behind=%d bounds=%d reprojection=%d tri=%d, obs=%d\n", wview.pview.id, setIdx, failedBehind, failedImageBounds, failedReprojection, failedTriangulate, numFeatures);
    return true;
}
Also used : ArrayList(java.util.ArrayList) FactoryMultiView(boofcv.factory.geo.FactoryMultiView) DogArray(org.ddogleg.struct.DogArray) VerbosePrint(org.ddogleg.struct.VerbosePrint) Point2D_F64(georegression.struct.point.Point2D_F64) RemoveBrownPtoN_F64(boofcv.alg.distort.brown.RemoveBrownPtoN_F64) Point4D_F64(georegression.struct.point.Point4D_F64) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

Point4D_F64 (georegression.struct.point.Point4D_F64)57 Point2D_F64 (georegression.struct.point.Point2D_F64)25 Test (org.junit.jupiter.api.Test)25 DMatrixRMaj (org.ejml.data.DMatrixRMaj)19 Point3D_F64 (georegression.struct.point.Point3D_F64)12 Se3_F64 (georegression.struct.se.Se3_F64)11 ArrayList (java.util.ArrayList)9 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)5 SceneStructureProjective (boofcv.abst.geo.bundle.SceneStructureProjective)5 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)4 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)4 DogArray_I32 (org.ddogleg.struct.DogArray_I32)4 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 AssociatedPair (boofcv.struct.geo.AssociatedPair)3 UtilPoint4D_F64 (georegression.geometry.UtilPoint4D_F64)3 DogArray (org.ddogleg.struct.DogArray)3 TriangulateNViewsMetricH (boofcv.abst.geo.TriangulateNViewsMetricH)2 RemoveBrownPtoN_F64 (boofcv.alg.distort.brown.RemoveBrownPtoN_F64)2 BundlePinhole (boofcv.alg.geo.bundle.cameras.BundlePinhole)2