Search in sources :

Example 6 with MetricCameras

use of boofcv.alg.geo.MetricCameras in project BoofCV by lessthanoptimal.

the class TestMetricSpawnSceneFromView method saveMetricSeed.

@Test
void saveMetricSeed() {
    var graph = new PairwiseImageGraph();
    List<String> viewIds = BoofMiscOps.asList("A", "B", "C");
    var listInliers = new DogArray<>(DogArray_I32::new, DogArray_I32::reset);
    // specify the seed view
    listInliers.grow().setTo(1, 3, 5, 7, 9);
    int numInliers = listInliers.get(0).size;
    // create distinctive sets of inlier indexes for each view
    for (int otherIdx = 0; otherIdx < viewIds.size() - 1; otherIdx++) {
        DogArray_I32 inliers = listInliers.grow();
        for (int i = 0; i < numInliers; i++) {
            inliers.add(listInliers.get(0).get(i) + 1 + otherIdx);
        }
    }
    // Create some arbitrary metric results that should be saved
    var results = new MetricCameras();
    for (int viewIdx = 0; viewIdx < viewIds.size(); viewIdx++) {
        // skip zero since it's implicit
        if (viewIdx > 0)
            results.motion_1_to_k.grow().T.setTo(1, viewIdx, 0);
        CameraPinhole pinhole = results.intrinsics.grow();
        pinhole.fx = pinhole.fy = 100 + viewIdx;
        graph.createNode(viewIds.get(viewIdx));
    }
    var alg = new MetricSpawnSceneFromView();
    alg.utils.dbCams = new MockLookUpCameraInfo(800, 800);
    var wgraph = new SceneWorkingGraph();
    alg.saveMetricSeed(graph, viewIds, listInliers, results, wgraph);
    // Check the cameras. There should only be one
    assertEquals(1, wgraph.cameras.size());
    assertEquals(0, wgraph.cameras.get(0).indexDB);
    assertEquals(100, wgraph.cameras.get(0).intrinsic.f);
    // See metric view info got saved correctly
    BoofMiscOps.forIdx(viewIds, (idx, viewId) -> {
        PairwiseImageGraph.View pview = graph.lookupNode(viewId);
        assertTrue(wgraph.isKnown(pview));
        SceneWorkingGraph.View wview = wgraph.lookupView(viewId);
        assertEquals(idx == 0 ? 0 : 1, wview.world_to_view.T.x, 1e-8);
        assertEquals(idx, wview.world_to_view.T.y, 1e-8);
    });
    // See if inliers got saved correctly
    BoofMiscOps.forIdx(viewIds, (idx, viewId) -> {
        SceneWorkingGraph.View wview = wgraph.lookupView(viewId);
        assertEquals(1, wview.inliers.size);
        SceneWorkingGraph.InlierInfo inlier = wview.inliers.get(0);
        assertEquals(0.0, inlier.scoreGeometric, "Score should be unassigned");
        assertEquals(viewIds.size(), inlier.views.size);
        assertEquals(viewIds.size(), inlier.observations.size);
        assertEquals(viewId, inlier.views.get(0).id);
        for (int inlierIdx = 0; inlierIdx < viewIds.size(); inlierIdx++) {
            int offset = (idx + inlierIdx) % viewIds.size();
            final int c = offset;
            DogArray_I32 obs = inlier.observations.get(inlierIdx);
            obs.forIdx((i, value) -> assertEquals(i * 2 + 1 + c, value));
        }
    });
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) CameraPinhole(boofcv.struct.calib.CameraPinhole) MetricCameras(boofcv.alg.geo.MetricCameras) Test(org.junit.jupiter.api.Test)

Aggregations

MetricCameras (boofcv.alg.geo.MetricCameras)6 ElevateViewInfo (boofcv.struct.calib.ElevateViewInfo)5 ArrayList (java.util.ArrayList)5 DMatrixRMaj (org.ejml.data.DMatrixRMaj)5 Test (org.junit.jupiter.api.Test)4 DogArray (org.ddogleg.struct.DogArray)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 Se3_F64 (georegression.struct.se.Se3_F64)2 ProjectiveToMetricCameras (boofcv.abst.geo.selfcalib.ProjectiveToMetricCameras)1 ResolveSignAmbiguityPositiveDepth (boofcv.alg.geo.selfcalib.ResolveSignAmbiguityPositiveDepth)1 TwoViewToCalibratingHomography (boofcv.alg.geo.selfcalib.TwoViewToCalibratingHomography)1 AssociatedTuple (boofcv.struct.geo.AssociatedTuple)1 AssociatedTupleN (boofcv.struct.geo.AssociatedTupleN)1 Rodrigues_F64 (georegression.struct.so.Rodrigues_F64)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1 VerbosePrint (org.ddogleg.struct.VerbosePrint)1