Search in sources :

Example 1 with Motion

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

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

the class TestProjectiveInitializeAllCommon method scoreTripleView_Prefer3D.

/**
 * See if it scores a set of three views higher if they have stronger 3D information
 */
@Test
void scoreTripleView_Prefer3D() {
    var alg = new ProjectiveInitializeAllCommon();
    View seedA = new View();
    View viewB = new View();
    View viewC = new View();
    Motion motionAB = new Motion();
    motionAB.src = seedA;
    motionAB.dst = viewB;
    motionAB.score3D = 2.0;
    Motion motionAC = new Motion();
    motionAC.src = viewC;
    motionAC.dst = seedA;
    motionAC.score3D = 1000.0;
    Motion motionBC = new Motion();
    motionBC.src = viewC;
    motionBC.dst = viewB;
    motionBC.score3D = 20.0;
    seedA.connections.add(motionAB);
    viewB.connections.add(motionAB);
    seedA.connections.add(motionAC);
    viewC.connections.add(motionAC);
    viewB.connections.add(motionBC);
    viewC.connections.add(motionBC);
    double score0 = alg.scoreTripleView(seedA, viewB, viewC);
    // make it have a stronger 3D score and see if this is reflected
    motionAB.score3D *= 2.0;
    assertTrue(alg.scoreTripleView(seedA, viewB, viewC) > score0);
    // now a worse score
    motionAB.score3D *= 0.1;
    assertTrue(alg.scoreTripleView(seedA, viewB, viewC) < score0);
}
Also used : Motion(boofcv.alg.structure.PairwiseImageGraph.Motion) View(boofcv.alg.structure.PairwiseImageGraph.View) Test(org.junit.jupiter.api.Test)

Example 3 with Motion

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

the class ProjectiveInitializeAllCommon method initializeStructureForAllViews.

/**
 * Initializes the bundle adjustment structure for all views not just the initial set of 3. The seed view is
 * view index=0. The other views are in order of `seedConnIdx` after that.
 */
private void initializeStructureForAllViews(LookUpCameraInfo db, int numberOfFeatures, View seed, DogArray_I32 seedConnIdx) {
    utils.observations.initialize(1 + seedConnIdx.size);
    utils.structure.initialize(1 + seedConnIdx.size, numberOfFeatures);
    viewsByStructureIndex.resize(utils.structure.views.size, null);
    utils.triangulateFeatures();
    // Added the seed view
    db.lookupViewShape(seed.id, shape);
    utils.structure.setView(0, true, utils.P1, shape.width, shape.height);
    // Add the two views connected to it. Note that the index of these views is based on their index
    // in the seedConnIdx list
    int indexSbaViewB = 1 + seedConnIdx.indexOf(selectedTriple[0]);
    int indexSbaViewC = 1 + seedConnIdx.indexOf(selectedTriple[1]);
    checkTrue(indexSbaViewB > 0 && indexSbaViewC > 0, "indexOf() failed");
    for (int i = 0; i < 2; i++) {
        Motion motion = seed.connections.get(selectedTriple[i]);
        View view = motion.other(seed);
        db.lookupViewShape(view.id, shape);
        utils.structure.setView(i == 0 ? indexSbaViewB : indexSbaViewC, false, i == 0 ? utils.P2 : utils.P3, shape.width, shape.height);
    }
    // create lookup table
    viewsByStructureIndex.set(0, seed);
    viewsByStructureIndex.set(indexSbaViewB, utils.viewB);
    viewsByStructureIndex.set(indexSbaViewC, utils.viewC);
    // Observations for the initial three view
    SceneObservations.View view1 = utils.observations.getView(0);
    SceneObservations.View view2 = utils.observations.getView(indexSbaViewB);
    SceneObservations.View view3 = utils.observations.getView(indexSbaViewC);
    for (int i = 0; i < utils.inliersThreeView.size(); i++) {
        AssociatedTriple t = utils.inliersThreeView.get(i);
        view1.add(i, (float) t.p1.x, (float) t.p1.y);
        view2.add(i, (float) t.p2.x, (float) t.p2.y);
        view3.add(i, (float) t.p3.x, (float) t.p3.y);
    }
}
Also used : Motion(boofcv.alg.structure.PairwiseImageGraph.Motion) AssociatedTriple(boofcv.struct.geo.AssociatedTriple) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) View(boofcv.alg.structure.PairwiseImageGraph.View) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 4 with Motion

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

the class ProjectiveInitializeAllCommon method scoreTripleView.

/**
 * Evaluates how well this set of 3-views can be used to estimate the scene's 3D structure
 *
 * @return higher is better. zero means worthless
 */
double scoreTripleView(View seedA, View viewB, View viewC) {
    Motion motionAB = Objects.requireNonNull(seedA.findMotion(viewB));
    Motion motionAC = Objects.requireNonNull(seedA.findMotion(viewC));
    Motion motionBC = viewB.findMotion(viewC);
    if (motionBC == null)
        return 0.0;
    double score = 0.0;
    score += motionAB.score3D;
    score += motionAC.score3D;
    score += motionBC.score3D;
    return score;
}
Also used : Motion(boofcv.alg.structure.PairwiseImageGraph.Motion)

Example 5 with Motion

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

the class ProjectiveInitializeAllCommon method createObservationsForBundleAdjustment.

/**
 * Convert observations into a format which bundle adjustment will understand
 *
 * @param seedConnIdx Which edges in seed to use
 */
protected void createObservationsForBundleAdjustment(DogArray_I32 seedConnIdx) {
    DogArray_I32 inlierToSeed = inlierIndexes.get(0);
    // seed view + the motions
    utils.observations.initialize(inlierIndexes.size);
    // Observations for the seed view are a special case
    {
        SceneObservations.View obsView = utils.observations.getView(0);
        for (int i = 0; i < inlierToSeed.size; i++) {
            int id = inlierToSeed.data[i];
            // featsA is never modified after initially loaded
            Point2D_F64 o = utils.featsA.get(id);
            id = seedToStructure.data[id];
            obsView.add(id, (float) o.x, (float) o.y);
        }
    }
    // Now add observations for edges connected to the seed
    for (int motionIdx = 0; motionIdx < seedConnIdx.size(); motionIdx++) {
        SceneObservations.View obsView = utils.observations.getView(motionIdx + 1);
        Motion m = utils.seed.connections.get(seedConnIdx.get(motionIdx));
        View v = m.other(utils.seed);
        boolean seedIsSrc = m.src == utils.seed;
        utils.dbCams.lookupCalibration(utils.dbCams.viewToCamera(v.id), utils.priorCamB);
        utils.dbSimilar.lookupPixelFeats(v.id, utils.featsB);
        BoofMiscOps.offsetPixels(utils.featsB.toList(), -utils.priorCamB.cx, -utils.priorCamB.cy);
        // indicate which observation from this view contributed to which 3D feature
        DogArray_I32 connInlierIndexes = inlierIndexes.get(motionIdx + 1);
        connInlierIndexes.resize(inlierToSeed.size);
        for (int epipolarInlierIdx = 0; epipolarInlierIdx < m.inliers.size; epipolarInlierIdx++) {
            AssociatedIndex a = m.inliers.get(epipolarInlierIdx);
            // See if the feature is one of inliers computed from 3-view RANSAC
            int structId = seedToStructure.data[seedIsSrc ? a.src : a.dst];
            if (structId < 0)
                continue;
            // get the observation in this view to that feature[structId]
            connInlierIndexes.set(structId, seedIsSrc ? a.dst : a.src);
            Point2D_F64 o = utils.featsB.get(seedIsSrc ? a.dst : a.src);
            obsView.add(structId, (float) o.x, (float) o.y);
        }
    }
}
Also used : Motion(boofcv.alg.structure.PairwiseImageGraph.Motion) Point2D_F64(georegression.struct.point.Point2D_F64) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) DogArray_I32(org.ddogleg.struct.DogArray_I32) View(boofcv.alg.structure.PairwiseImageGraph.View) VerbosePrint(org.ddogleg.struct.VerbosePrint) AssociatedIndex(boofcv.struct.feature.AssociatedIndex)

Aggregations

Motion (boofcv.alg.structure.PairwiseImageGraph.Motion)10 View (boofcv.alg.structure.PairwiseImageGraph.View)8 Test (org.junit.jupiter.api.Test)5 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)3 VerbosePrint (org.ddogleg.struct.VerbosePrint)3 PairwiseImageGraph (boofcv.alg.structure.PairwiseImageGraph)2 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)2 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 ArrayList (java.util.ArrayList)2 DogArray_I32 (org.ddogleg.struct.DogArray_I32)2 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1