Search in sources :

Example 1 with MockLookupSimilarImagesRealistic

use of boofcv.alg.structure.MockLookupSimilarImagesRealistic in project BoofCV by lessthanoptimal.

the class TestEstimateViewSelfCalibrate method computeCalibratingHomography.

/**
 * Check the calibrating homography computation by feeding it noise three data from 3 views
 */
@Test
void computeCalibratingHomography() {
    var db = new MockLookupSimilarImagesRealistic().setIntrinsic(new CameraPinhole(400, 400, 0, 0, 0, 800, 800)).pathLine(5, 0.3, 1.5, 2);
    PairwiseImageGraph pairwise = db.createPairwise();
    var alg = new EstimateViewSelfCalibrate();
    alg.workGraph = db.createWorkingGraph(pairwise);
    alg.pairwiseUtils = new PairwiseGraphUtils();
    alg.pairwiseUtils.seed = pairwise.nodes.get(0);
    alg.pairwiseUtils.viewB = pairwise.nodes.get(1);
    alg.pairwiseUtils.viewC = pairwise.nodes.get(2);
    int[] viewIdx = new int[] { 1, 0, 2 };
    // P1 might not be identity
    DMatrixRMaj P1 = db.views.get(viewIdx[0]).camera;
    alg.pairwiseUtils.P2.setTo(db.views.get(viewIdx[1]).camera);
    alg.pairwiseUtils.P3.setTo(db.views.get(viewIdx[2]).camera);
    // make sure P1 is identity, which is what it would be coming out of the trifocal tensor
    List<DMatrixRMaj> cameras = BoofMiscOps.asList(P1.copy(), alg.pairwiseUtils.P2, alg.pairwiseUtils.P3);
    MultiViewOps.projectiveMakeFirstIdentity(cameras, null);
    // Create the pixel observations
    db.createTripleObs(viewIdx, alg.pairwiseUtils.matchesTriple, new DogArray_I32());
    // Compute the homography
    assertTrue(alg.computeCalibratingHomography());
    // Test it by seeing it it returns the expected camera matrix
    DMatrixRMaj H = alg.projectiveHomography.getCalibrationHomography();
    DMatrixRMaj foundK = new DMatrixRMaj(3, 3);
    Se3_F64 view_0_to_2 = new Se3_F64();
    MultiViewOps.projectiveToMetric(alg.pairwiseUtils.P3, H, view_0_to_2, foundK);
    assertEquals(db.intrinsic.fx, foundK.get(0, 0), 1e-7);
    assertEquals(db.intrinsic.fy, foundK.get(1, 1), 1e-7);
    assertEquals(db.intrinsic.cx, foundK.get(0, 2), 1e-7);
    assertEquals(db.intrinsic.cy, foundK.get(1, 2), 1e-7);
    assertEquals(db.intrinsic.skew, foundK.get(0, 1), 1e-7);
}
Also used : MockLookupSimilarImagesRealistic(boofcv.alg.structure.MockLookupSimilarImagesRealistic) DMatrixRMaj(org.ejml.data.DMatrixRMaj) PairwiseGraphUtils(boofcv.alg.structure.PairwiseGraphUtils) PairwiseImageGraph(boofcv.alg.structure.PairwiseImageGraph) DogArray_I32(org.ddogleg.struct.DogArray_I32) CameraPinhole(boofcv.struct.calib.CameraPinhole) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 2 with MockLookupSimilarImagesRealistic

use of boofcv.alg.structure.MockLookupSimilarImagesRealistic in project BoofCV by lessthanoptimal.

the class TestEstimateViewKnownCalibration method simpleKnownScenario.

/**
 * Generate a known scene and pass in everything but the location of the 3rd view. Make sure
 * it's able to estimate it. A couple of outliers will be added and checked to make sure they are removed.
 */
@Test
void simpleKnownScenario() {
    var db = new MockLookupSimilarImagesRealistic().pathLine(5, 0.3, 1.5, 2);
    PairwiseImageGraph pairwise = db.createPairwise();
    SceneWorkingGraph scene = db.createWorkingGraph(pairwise);
    var pairwiseUtils = new PairwiseGraphUtils();
    pairwiseUtils.dbSimilar = db;
    pairwiseUtils.dbCams = db.createLookUpCams();
    // Specify the 3-views it should use. viewC = target that's estimated
    pairwiseUtils.seed = pairwise.nodes.get(1);
    pairwiseUtils.viewB = pairwise.nodes.get(2);
    pairwiseUtils.viewC = pairwise.nodes.get(3);
    // Use truth for the priors
    pairwiseUtils.priorCamA.setTo(db.intrinsic);
    pairwiseUtils.priorCamB.setTo(db.intrinsic);
    pairwiseUtils.priorCamC.setTo(db.intrinsic);
    // Specifies the observations for the 3-views
    SceneWorkingGraph.View wviewA = scene.listViews.get(1);
    db.addInlierInfo(pairwise, wviewA, 2, 3);
    // Create the triplet of pixel observations using the "inlier" set created above
    SceneWorkingGraph.InlierInfo info = Objects.requireNonNull(wviewA.getBestInliers());
    int numInliers = info.getInlierCount();
    pairwiseUtils.inlierIdx.resize(numInliers, (idx) -> idx);
    assertTrue(numInliers > 20);
    for (int i = 0; i < numInliers; i++) {
        int obs1 = info.observations.get(0).get(i);
        int obs2 = info.observations.get(1).get(i);
        int obs3 = info.observations.get(2).get(i);
        AssociatedTriple a = new AssociatedTriple();
        a.p1.setTo(db.views.get(1).observations.get(obs1).pixel);
        a.p2.setTo(db.views.get(2).observations.get(obs2).pixel);
        a.p3.setTo(db.views.get(3).observations.get(obs3).pixel);
        pairwiseUtils.inliersThreeView.add(a);
    }
    // Pixels must be centered at (0,0)
    for (int i = 0; i < numInliers; i++) {
        AssociatedTriple a = pairwiseUtils.inliersThreeView.get(i);
        a.p1.x -= db.intrinsic.cx;
        a.p1.y -= db.intrinsic.cy;
        a.p2.x -= db.intrinsic.cx;
        a.p2.y -= db.intrinsic.cy;
        a.p3.x -= db.intrinsic.cx;
        a.p3.y -= db.intrinsic.cy;
    }
    var alg = new EstimateViewKnownCalibration();
    // alg.setVerbose(System.out, BoofMiscOps.hashSet(BoofVerbose.RECURSIVE));
    var solution = new MetricExpandByOneView.Solution();
    assertTrue(alg.process(pairwiseUtils, scene, solution));
    // See if the transforms are the same
    Se3_F64 expected = scene.listViews.get(3).world_to_view;
    assertEquals(0.0, expected.T.distance(solution.world_to_target.T), 1e-2);
// NOTE: The tolerance does seem a bit high for noise free observations. Could there be numeric issues?
}
Also used : MockLookupSimilarImagesRealistic(boofcv.alg.structure.MockLookupSimilarImagesRealistic) AssociatedTriple(boofcv.struct.geo.AssociatedTriple) SceneWorkingGraph(boofcv.alg.structure.SceneWorkingGraph) PairwiseGraphUtils(boofcv.alg.structure.PairwiseGraphUtils) PairwiseImageGraph(boofcv.alg.structure.PairwiseImageGraph) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Aggregations

MockLookupSimilarImagesRealistic (boofcv.alg.structure.MockLookupSimilarImagesRealistic)2 PairwiseGraphUtils (boofcv.alg.structure.PairwiseGraphUtils)2 PairwiseImageGraph (boofcv.alg.structure.PairwiseImageGraph)2 Se3_F64 (georegression.struct.se.Se3_F64)2 Test (org.junit.jupiter.api.Test)2 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)1 CameraPinhole (boofcv.struct.calib.CameraPinhole)1 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1