Search in sources :

Example 1 with SceneWorkingGraph

use of boofcv.alg.structure.SceneWorkingGraph 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 2 with SceneWorkingGraph

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

the class TestMultiViewIO method checkIdentical.

private void checkIdentical(SceneWorkingGraph a, SceneWorkingGraph b) {
    assertEquals(a.listCameras.size(), b.listCameras.size());
    assertEquals(a.listViews.size(), b.listViews.size());
    assertEquals(a.views.size(), b.views.size());
    for (int cameraIdx = 0; cameraIdx < a.listCameras.size(); cameraIdx++) {
        SceneWorkingGraph.Camera ca = a.listCameras.get(cameraIdx);
        SceneWorkingGraph.Camera cb = b.listCameras.get(cameraIdx);
        assertEquals(ca.indexDB, cb.indexDB);
        assertEquals(ca.localIndex, cb.localIndex);
        assertEquals(ca.prior.fx, cb.prior.fx);
        assertEquals(ca.intrinsic.f, cb.intrinsic.f);
    }
    for (int viewIdx = 0; viewIdx < a.listViews.size(); viewIdx++) {
        SceneWorkingGraph.View va = a.listViews.get(viewIdx);
        SceneWorkingGraph.View vb = b.listViews.get(viewIdx);
        assertSame(va, a.views.get(va.pview.id));
        assertSame(vb, b.views.get(vb.pview.id));
        assertEquals(0.0, va.world_to_view.T.distance(vb.world_to_view.T), UtilEjml.EPS);
        assertTrue(MatrixFeatures_DDRM.isEquals(va.world_to_view.R, vb.world_to_view.R, UtilEjml.EPS));
        assertEquals(va.inliers.size, vb.inliers.size);
        for (int inlierInfo = 0; inlierInfo < va.inliers.size; inlierInfo++) {
            SceneWorkingGraph.InlierInfo infoa = va.inliers.get(inlierInfo);
            SceneWorkingGraph.InlierInfo infob = vb.inliers.get(inlierInfo);
            assertEquals(infoa.observations.size, infob.observations.size);
            final int numViews = infoa.views.size;
            for (int i = 0; i < numViews; i++) {
                assertEquals(infoa.views.get(i).id, infob.views.get(i).id);
                DogArray_I32 oa = infoa.observations.get(i);
                DogArray_I32 ob = infob.observations.get(i);
                assertEquals(oa.size, ob.size);
                oa.forIdx((idx, v) -> assertEquals(v, ob.get(idx)));
            }
        }
    }
}
Also used : SceneWorkingGraph(boofcv.alg.structure.SceneWorkingGraph) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 3 with SceneWorkingGraph

use of boofcv.alg.structure.SceneWorkingGraph 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 4 with SceneWorkingGraph

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

the class TestMultiViewIO method createWorkingGraph.

private SceneWorkingGraph createWorkingGraph(PairwiseImageGraph pairwise) {
    var ret = new SceneWorkingGraph();
    // Add a camera for each view
    for (int cameraIdx = 0; cameraIdx < pairwise.nodes.size; cameraIdx++) {
        SceneWorkingGraph.Camera c = ret.addCamera(cameraIdx);
        c.intrinsic.f = rand.nextDouble();
        c.intrinsic.k1 = rand.nextDouble();
        c.intrinsic.k2 = rand.nextDouble();
        c.prior.fx = rand.nextDouble();
    }
    pairwise.nodes.forIdx((i, v) -> ret.addView(v, ret.listCameras.get(i)));
    var candidates = DogArray_I32.range(0, pairwise.nodes.size);
    ret.listViews.forEach(v -> {
        SpecialEuclideanOps_F64.eulerXyz(rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), rand.nextDouble(), v.world_to_view);
        RandomMatrices_DDRM.fillUniform(v.projective, rand);
        PrimitiveArrays.shuffle(candidates.data, 0, candidates.size, rand);
        v.inliers.resetResize(2);
        for (int infoIdx = 0; infoIdx < v.inliers.size; infoIdx++) {
            SceneWorkingGraph.InlierInfo inlier = v.inliers.get(infoIdx);
            int numViews = rand.nextInt(Math.min(5, candidates.size));
            int numObs = rand.nextInt(20) + 1;
            inlier.views.resize(numViews);
            inlier.observations.resize(numViews);
            for (int i = 0; i < numViews; i++) {
                inlier.views.set(i, pairwise.nodes.get(candidates.get(i)));
                DogArray_I32 obs = inlier.observations.get(i);
                obs.resize(numObs);
                for (int j = 0; j < numObs; j++) {
                    obs.data[j] = rand.nextInt();
                }
            }
        }
    });
    return ret;
}
Also used : SceneWorkingGraph(boofcv.alg.structure.SceneWorkingGraph) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 5 with SceneWorkingGraph

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

the class TestExpandByOneView method selectTwoConnections.

/**
 * Creates a more complex scenario and sees if it selects the correct two views
 */
@Test
void selectTwoConnections() {
    var working = new SceneWorkingGraph();
    var graph = new PairwiseImageGraph();
    SceneWorkingGraph.Camera camera = working.addCamera(2);
    View seed = graph.createNode("A");
    for (int i = 0; i < 6; i++) {
        View viewI = graph.createNode("" + i);
        // make sure src/dst is handled correctly
        Motion mA = i % 2 == 0 ? graph.connect(seed, viewI) : graph.connect(viewI, seed);
        // All have the same score so that the connections between the other two is what decides the winner
        mA.score3D = 2.0;
        mA.is3D = true;
        working.addView(viewI, camera);
    }
    View viewB = seed.connection(1);
    View viewC = seed.connection(2);
    View viewD = seed.connection(3);
    Motion connBC = graph.connect(viewB, viewC);
    Motion connBD = graph.connect(viewD, viewB);
    connBD.is3D = connBC.is3D = true;
    connBC.score3D = 1.2;
    // this is the more desirable connection
    connBD.score3D = 1.3;
    var alg = new ChildProjectiveExpandByOneView();
    alg.workGraph = working;
    var found = new ArrayList<Motion>();
    assertTrue(alg.selectTwoConnections(seed, found));
    assertTrue(found.contains(seed.connections.get(1)));
    assertTrue(found.contains(seed.connections.get(3)));
}
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)

Aggregations

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