Search in sources :

Example 6 with BundlePinholeSimplified

use of boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified in project BoofCV by lessthanoptimal.

the class RefineMetricWorkingGraph method refineViews.

/**
 * Refines the scene and updates the graph.
 *
 * @param graph (Output) where the updated scene parameters are written to.
 * @return true is successful or false is SBA failed
 */
protected boolean refineViews(SceneWorkingGraph graph) {
    if (!metricSba.process())
        return false;
    final SceneStructureMetric structure = metricSba.structure;
    // save the results
    for (int cameraIdx = 0; cameraIdx < graph.listCameras.size(); cameraIdx++) {
        BundlePinholeSimplified found = (BundlePinholeSimplified) structure.cameras.get(cameraIdx).model;
        graph.listCameras.get(cameraIdx).intrinsic.setTo(found);
    }
    for (int viewIdx = 0; viewIdx < graph.listViews.size(); viewIdx++) {
        SceneWorkingGraph.View wview = graph.listViews.get(viewIdx);
        wview.world_to_view.setTo(structure.getParentToView(viewIdx));
        if (verbose != null && verboseViewInfo) {
            BundlePinholeSimplified intrinsics = graph.getViewCamera(wview).intrinsic;
            Se3_F64 m = metricSba.structure.getParentToView(viewIdx);
            double theta = ConvertRotation3D_F64.matrixToRodrigues(m.R, null).theta;
            verbose.printf("AFTER view='%s' T=(%.2f %.2f %.2f) R=%.4f, f=%.1f k1=%.1e k2=%.1e\n", wview.pview.id, m.T.x, m.T.y, m.T.z, theta, intrinsics.f, intrinsics.k1, intrinsics.k2);
        }
    }
    return true;
}
Also used : SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified) VerbosePrint(org.ddogleg.struct.VerbosePrint) Se3_F64(georegression.struct.se.Se3_F64)

Example 7 with BundlePinholeSimplified

use of boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified in project BoofCV by lessthanoptimal.

the class TestEstimateViewUtils method configureSbaStructure.

/**
 * Very simple test that just makes sure three views/cameras have been set as constant initially
 */
@Test
void configureSbaStructure() {
    DogArray<AssociatedTriple> inliers = new DogArray<>(AssociatedTriple::new);
    inliers.resize(95);
    var alg = new EstimateViewUtils();
    // configure internal data structures so that it won't blow up
    alg.camera1 = new BundlePinholeSimplified();
    alg.camera2 = new BundlePinholeSimplified();
    alg.camera3 = new BundlePinholeSimplified();
    alg.normalize1.setK(100, 100, 0, 100, 100).setDistortion(0.1, 0.1);
    alg.normalize2.setK(100, 100, 0, 100, 100).setDistortion(0.1, 0.1);
    alg.normalize3.setK(100, 100, 0, 100, 100).setDistortion(0.1, 0.1);
    alg.usedThreeViewInliers.resize(40);
    alg.configureSbaStructure(inliers.toList());
    // Check the results to make sure stuff is marked as known
    for (int i = 0; i < 3; i++) {
        assertTrue(alg.metricSba.structure.cameras.get(i).known);
        assertTrue(alg.metricSba.structure.motions.get(i).known);
    }
    assertEquals(40, alg.metricSba.structure.points.size);
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified) DogArray(org.ddogleg.struct.DogArray) Test(org.junit.jupiter.api.Test)

Example 8 with BundlePinholeSimplified

use of boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified in project BoofCV by lessthanoptimal.

the class EstimateViewSelfCalibrate method computeCalibratingHomography.

/**
 * Computes the transform needed to go from one projective space into another
 */
boolean computeCalibratingHomography() {
    // convert everything in to the correct data format
    MultiViewOps.projectiveToFundamental(pairwiseUtils.P2, F21);
    projectiveHomography.initialize(F21, pairwiseUtils.P2);
    BundlePinholeSimplified camera1 = workGraph.getViewCamera(workGraph.lookupView(pairwiseUtils.seed.id)).intrinsic;
    BundlePinholeSimplified camera2 = workGraph.getViewCamera(workGraph.lookupView(pairwiseUtils.viewB.id)).intrinsic;
    BundleAdjustmentOps.convert(camera1, K1);
    BundleAdjustmentOps.convert(camera2, K2);
    DogArray<AssociatedTriple> triples = pairwiseUtils.matchesTriple;
    pairs.resize(triples.size());
    for (int idx = 0; idx < triples.size(); idx++) {
        AssociatedTriple a = triples.get(idx);
        pairs.get(idx).setTo(a.p1, a.p2);
    }
    return projectiveHomography.process(K1, K2, pairs.toList());
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 9 with BundlePinholeSimplified

use of boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified in project BoofCV by lessthanoptimal.

the class TestThreeViewEstimateMetricScene method perfectData.

@Test
void perfectData() {
    ThreeViewEstimateMetricScene alg = new ThreeViewEstimateMetricScene();
    assertTrue(alg.process(views, 900, 900));
    // See if the reconstructed seen matches the original to within a high level of precision
    SceneStructureMetric structure = alg.getStructure();
    for (int i = 0; i < 3; i++) {
        BundlePinholeSimplified c = structure.getCameras().get(i).getModel();
        assertEquals(intrinsic.fx, c.f, 1e-4);
        assertEquals(0, c.k1, 1e-5);
        assertEquals(0, c.k2, 1e-5);
    }
    Se3_F64 found1 = structure.getParentToView(1);
    Se3_F64 found2 = structure.getParentToView(2);
    view0_to_view1.T.normalize();
    found1.T.normalize();
    assertEquals(0, found1.T.distance(view0_to_view1.T), 1e-4);
    view0_to_view2.T.normalize();
    found2.T.normalize();
    assertEquals(0, found2.T.distance(view0_to_view2.T), 1e-4);
    double[] found_xyz = ConvertRotation3D_F64.matrixToEuler(found1.R, EulerType.XYZ, null);
    double[] expec_xyz = ConvertRotation3D_F64.matrixToEuler(view0_to_view1.R, EulerType.XYZ, null);
    for (int i = 0; i < 3; i++) {
        assertEquals(expec_xyz[i], found_xyz[i], 1e-4);
    }
    found_xyz = ConvertRotation3D_F64.matrixToEuler(found2.R, EulerType.XYZ, null);
    expec_xyz = ConvertRotation3D_F64.matrixToEuler(view0_to_view2.R, EulerType.XYZ, null);
    for (int i = 0; i < 3; i++) {
        assertEquals(expec_xyz[i], found_xyz[i], 1e-4);
    }
}
Also used : SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 10 with BundlePinholeSimplified

use of boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified in project BoofCV by lessthanoptimal.

the class TestMetricExpandByOneView method checkPerfect.

private void checkPerfect(MockLookupSimilarImagesRealistic dbSimilar, LookUpCameraInfo dbCams, MetricExpandByOneView alg, boolean cameraKnown, int targetViewIdx) {
    PairwiseImageGraph pairwise = dbSimilar.createPairwise();
    SceneWorkingGraph workGraph = dbSimilar.createWorkingGraph(pairwise);
    if (!cameraKnown) {
        // The target view will now reference camera 0, the default is camera 2
        dbCams.viewToCamera.set(targetViewIdx, 0);
        // Change 0 will now have correct prior information
        dbCams.listCalibration.get(0).setTo(dbSimilar.intrinsic);
    }
    // Decide which view will be estimated
    PairwiseImageGraph.View target = pairwise.nodes.get(targetViewIdx);
    // remove the view from the work graph
    workGraph.listViews.remove(workGraph.views.remove(target.id));
    // add the target view
    assertTrue(alg.process(dbSimilar, dbCams, workGraph, target));
    BundlePinholeSimplified foundCamera = workGraph.listCameras.get(cameraKnown ? 0 : 1).intrinsic;
    if (cameraKnown) {
        // If known the camera should never be modified
        assertEquals(dbSimilar.intrinsic.fx, foundCamera.f, 0.0);
    } else {
        // If unknown, then the camera should be close to but not exactly truth
        assertEquals(dbSimilar.intrinsic.fx, foundCamera.f, 1e-4);
        assertNotEquals(dbSimilar.intrinsic.fx, foundCamera.f, 0.0);
    }
    // Check pose
    SceneWorkingGraph.View found = workGraph.views.get(target.id);
    BoofTesting.assertEquals(dbSimilar.views.get(targetViewIdx).world_to_view, found.world_to_view, 0.01, 0.01);
}
Also used : BundlePinholeSimplified(boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified)

Aggregations

BundlePinholeSimplified (boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified)18 Se3_F64 (georegression.struct.se.Se3_F64)10 VerbosePrint (org.ddogleg.struct.VerbosePrint)9 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)6 ArrayList (java.util.ArrayList)5 DogArray (org.ddogleg.struct.DogArray)5 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)4 Test (org.junit.jupiter.api.Test)4 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)3 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)3 Point4D_F64 (georegression.struct.point.Point4D_F64)3 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)2 RemoveBrownPtoN_F64 (boofcv.alg.distort.brown.RemoveBrownPtoN_F64)2 ConfigBundleAdjustment (boofcv.factory.geo.ConfigBundleAdjustment)2 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)2 BoofMiscOps (boofcv.misc.BoofMiscOps)2 GrayU8 (boofcv.struct.image.GrayU8)2 Vector3D_F64 (georegression.struct.point.Vector3D_F64)2 BufferedImage (java.awt.image.BufferedImage)2 Objects (java.util.Objects)2