Search in sources :

Example 1 with PairwiseImageGraph

use of boofcv.alg.structure.PairwiseImageGraph 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 PairwiseImageGraph

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

the class TestExpandByOneView method createListOfValid.

@Test
void createListOfValid() {
    var working = new SceneWorkingGraph();
    var graph = new PairwiseImageGraph();
    SceneWorkingGraph.Camera camera = working.addCamera(2);
    View seed = graph.createNode("A");
    for (int i = 0; i < 10; i++) {
        View viewI = graph.createNode("" + i);
        Motion mA = graph.connect(seed, viewI);
        // is3D and being known are at different frequencies and will only intersect twice
        mA.is3D = i % 2 == 0;
        if (i % 3 == 0)
            working.addView(viewI, camera);
    }
    var alg = new ChildProjectiveExpandByOneView();
    alg.workGraph = working;
    List<Motion> valid = new ArrayList<>();
    alg.createListOfValid(seed, valid);
    assertEquals(2, valid.size());
}
Also used : Motion(boofcv.alg.structure.PairwiseImageGraph.Motion) SceneWorkingGraph(boofcv.alg.structure.SceneWorkingGraph) ArrayList(java.util.ArrayList) PairwiseImageGraph(boofcv.alg.structure.PairwiseImageGraph) View(boofcv.alg.structure.PairwiseImageGraph.View) Test(org.junit.jupiter.api.Test)

Example 3 with PairwiseImageGraph

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

the class TestMultiViewIO method checkIdentical.

private void checkIdentical(PairwiseImageGraph a, PairwiseImageGraph b) {
    assertEquals(a.edges.size, b.edges.size);
    assertEquals(a.nodes.size, b.nodes.size);
    assertEquals(a.mapNodes.size(), b.mapNodes.size());
    for (int viewIdx = 0; viewIdx < a.nodes.size; viewIdx++) {
        PairwiseImageGraph.View va = a.nodes.get(viewIdx);
        PairwiseImageGraph.View vb = b.nodes.get(viewIdx);
        assertSame(va, a.mapNodes.get(va.id));
        assertSame(vb, b.mapNodes.get(vb.id));
        assertEquals(va.index, vb.index);
        assertEquals(va.id, vb.id);
        assertEquals(va.totalObservations, vb.totalObservations);
        assertEquals(va.connections.size, vb.connections.size);
        for (int i = 0; i < va.connections.size; i++) {
            PairwiseImageGraph.Motion ma = va.connections.get(i);
            PairwiseImageGraph.Motion mb = vb.connections.get(i);
            // Make sure it didn't declare a new instance of the view
            assertSame(ma.src, a.mapNodes.get(ma.src.id));
            assertSame(mb.dst, b.mapNodes.get(mb.dst.id));
            // Make sure the same instance is in the edges list
            assertTrue(b.edges.contains(mb));
            assertEquals(ma.index, mb.index);
            assertEquals(ma.is3D, mb.is3D);
            assertEquals(ma.src.id, mb.src.id);
            assertEquals(ma.dst.id, mb.dst.id);
            assertEquals(ma.score3D, mb.score3D);
            assertEquals(ma.inliers.size, mb.inliers.size);
            for (int j = 0; j < ma.inliers.size; j++) {
                AssociatedIndex ia = ma.inliers.get(j);
                AssociatedIndex ib = mb.inliers.get(j);
                assertEquals(ia.src, ib.src);
                assertEquals(ia.dst, ib.dst);
            }
        }
    }
}
Also used : PairwiseImageGraph(boofcv.alg.structure.PairwiseImageGraph) AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Example 4 with PairwiseImageGraph

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

the class TestMultiViewIO method save_load_SceneWorkingGraph.

@Test
void save_load_SceneWorkingGraph() {
    for (int trial = 0; trial < 20; trial++) {
        PairwiseImageGraph pairwise = createPairwise();
        SceneWorkingGraph expected = createWorkingGraph(pairwise);
        var output = new ByteArrayOutputStream();
        MultiViewIO.save(expected, new OutputStreamWriter(output, UTF_8));
        var input = new ByteArrayInputStream(output.toByteArray());
        SceneWorkingGraph found = MultiViewIO.load(new InputStreamReader(input, UTF_8), pairwise, null);
        checkIdentical(expected, found);
    }
}
Also used : InputStreamReader(java.io.InputStreamReader) SceneWorkingGraph(boofcv.alg.structure.SceneWorkingGraph) ByteArrayInputStream(java.io.ByteArrayInputStream) OutputStreamWriter(java.io.OutputStreamWriter) PairwiseImageGraph(boofcv.alg.structure.PairwiseImageGraph) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.jupiter.api.Test)

Example 5 with PairwiseImageGraph

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

the class TestMultiViewIO method createPairwise.

private PairwiseImageGraph createPairwise() {
    var ret = new PairwiseImageGraph();
    ret.nodes.resize(rand.nextInt(10) + 1);
    for (int viewIdx = 0; viewIdx < ret.nodes.size; viewIdx++) {
        PairwiseImageGraph.View v = ret.nodes.get(viewIdx);
        v.index = viewIdx;
        v.id = rand.nextInt() + "";
        v.totalObservations = rand.nextInt(200);
        ret.mapNodes.put(v.id, v);
        // Randomly select connecting nodes from ones which higher indexes to ensure (src,dst) pairs are unique
        var candidates = DogArray_I32.range(viewIdx + 1, ret.nodes.size);
        PrimitiveArrays.shuffle(candidates.data, 0, candidates.size, rand);
        int numConnections = rand.nextInt() + 5;
        for (int i = 0; i < Math.min(numConnections, candidates.size); i++) {
            PairwiseImageGraph.Motion m = ret.edges.grow();
            m.is3D = rand.nextBoolean();
            m.score3D = rand.nextDouble();
            m.src = v;
            m.dst = ret.nodes.get(candidates.get(i));
            m.index = ret.edges.size - 1;
            m.inliers.resize(rand.nextInt(20));
            for (int j = 0; j < m.inliers.size; j++) {
                AssociatedIndex a = m.inliers.get(j);
                a.src = rand.nextInt();
                a.dst = rand.nextInt();
            }
            v.connections.add(m);
            m.dst.connections.add(m);
        }
    }
    return ret;
}
Also used : PairwiseImageGraph(boofcv.alg.structure.PairwiseImageGraph) AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Aggregations

PairwiseImageGraph (boofcv.alg.structure.PairwiseImageGraph)9 Test (org.junit.jupiter.api.Test)6 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)4 MockLookupSimilarImagesRealistic (boofcv.alg.structure.MockLookupSimilarImagesRealistic)2 PairwiseGraphUtils (boofcv.alg.structure.PairwiseGraphUtils)2 Motion (boofcv.alg.structure.PairwiseImageGraph.Motion)2 View (boofcv.alg.structure.PairwiseImageGraph.View)2 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)2 Se3_F64 (georegression.struct.se.Se3_F64)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 InputStreamReader (java.io.InputStreamReader)2 OutputStreamWriter (java.io.OutputStreamWriter)2 ArrayList (java.util.ArrayList)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)1 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)1 File (java.io.File)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1