Search in sources :

Example 16 with View

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

the class TestProjectiveInitializeAllCommon method scoreTripleView_NotCircle.

/**
 * Give it a set of three views which are not mutually connected in a complete circle
 */
@Test
void scoreTripleView_NotCircle() {
    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;
    // give it an excellent 3D score
    motionAB.score3D = 1000;
    Motion motionAC = new Motion();
    motionAC.src = viewC;
    // src/dst shouldn't matter. bonus check
    motionAC.dst = seedA;
    // give it an excellent 3D score
    motionAC.score3D = 1000;
    seedA.connections.add(motionAB);
    viewB.connections.add(motionAB);
    seedA.connections.add(motionAC);
    viewC.connections.add(motionAC);
    // No connection B to C is made
    assertEquals(0.0, alg.scoreTripleView(seedA, viewB, viewC), UtilEjml.TEST_F64);
}
Also used : Motion(boofcv.alg.structure.PairwiseImageGraph.Motion) View(boofcv.alg.structure.PairwiseImageGraph.View) Test(org.junit.jupiter.api.Test)

Example 17 with View

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

the class ReconstructionFromPairwiseGraph method addOpenForView.

/**
 * Adds connections to the passed in view to the list of views to explore. Care is taken to not add the same
 * view more than once
 *
 * @param view (Input) Inspects connected views to add to found
 */
protected void addOpenForView(SceneWorkingGraph scene, View view) {
    int openSizeBefore = scene.open.size;
    for (int connIdx = 0; connIdx < view.connections.size; connIdx++) {
        PairwiseImageGraph.Motion c = view.connections.get(connIdx);
        // If there isn't 3D information skip it
        if (!c.is3D)
            continue;
        View o = c.other(view);
        // Make sure it hasn't been added or considered already
        if (scene.exploredViews.contains(o.id))
            continue;
        scene.open.add(o);
        scene.exploredViews.add(o.id);
    }
    if (verbose == null)
        return;
    verbose.print("_ scene[" + scene.index + "].view='" + view.id + "' adding: size=" + (scene.open.size - openSizeBefore) + " views={ ");
    for (int i = openSizeBefore; i < scene.open.size; i++) {
        verbose.print("'" + scene.open.get(i).id + "' ");
    }
    verbose.println("}");
}
Also used : View(boofcv.alg.structure.PairwiseImageGraph.View) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 18 with View

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

the class ReconstructionFromPairwiseGraph method scoreNodesAsSeeds.

/**
 * Considers every view in the graph as a potential seed and computes their scores
 */
protected Map<String, SeedInfo> scoreNodesAsSeeds(PairwiseImageGraph graph, int maxMotions) {
    seedScores.reset();
    Map<String, SeedInfo> mapScores = new HashMap<>();
    for (int idxView = 0; idxView < graph.nodes.size; idxView++) {
        View v = graph.nodes.get(idxView);
        SeedInfo info = seedScores.grow();
        scoreSeedAndSelectSet(v, maxMotions, info);
        mapScores.put(v.id, info);
    }
    return mapScores;
}
Also used : View(boofcv.alg.structure.PairwiseImageGraph.View) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 19 with View

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

the class ReconstructionFromPairwiseGraph method selectNextToProcess.

/**
 * Selects next View to process based on the score of it's known connections. Two connections which both
 * connect to each other is required.
 *
 * @param selection The results
 * @return true if a valid choice was found. Otherwise false.
 */
protected boolean selectNextToProcess(SceneWorkingGraph scene, Expansion selection) {
    selection.reset();
    selection.scene = scene;
    int bestIdx = -1;
    double bestScore = 0.0;
    int bestValidCount = 0;
    valid.clear();
    for (int openIdx = 0; openIdx < scene.open.size; openIdx++) {
        final View pview = scene.open.get(openIdx);
        // Create a list of valid views pview can connect too
        valid.clear();
        for (int connIdx = 0; connIdx < pview.connections.size; connIdx++) {
            PairwiseImageGraph.Motion m = pview.connections.get(connIdx);
            View dst = m.other(pview);
            if (!m.is3D || !scene.isKnown(dst))
                continue;
            valid.add(dst);
        }
        double bestLocalScore = 0.0;
        for (int idx0 = 0; idx0 < valid.size(); idx0++) {
            View viewB = valid.get(idx0);
            PairwiseImageGraph.Motion m0 = Objects.requireNonNull(pview.findMotion(viewB));
            for (int idx1 = idx0 + 1; idx1 < valid.size(); idx1++) {
                View viewC = valid.get(idx1);
                PairwiseImageGraph.Motion m2 = viewB.findMotion(viewC);
                if (m2 == null || !m2.is3D)
                    continue;
                PairwiseImageGraph.Motion m1 = Objects.requireNonNull(pview.findMotion(viewC));
                double s = BoofMiscOps.min(m0.score3D, m1.score3D, m2.score3D);
                bestLocalScore = Math.max(s, bestLocalScore);
            }
        }
        // so this test serves as a reminder
        if (Math.min(3, valid.size()) >= bestValidCount && bestLocalScore > bestScore) {
            bestValidCount = Math.min(3, valid.size());
            bestScore = bestLocalScore;
            bestIdx = openIdx;
        }
    }
    if (bestIdx < 0) {
        if (verbose != null) {
            verbose.println("_ Failed to find a valid view to connect. open.size=" + scene.open.size);
            for (int i = 0; i < scene.open.size; i++) {
                View v = scene.open.get(i);
                verbose.print("___ id='" + v.id + "' conn={ ");
                for (int j = 0; j < v.connections.size; j++) {
                    verbose.print("'" + v.connections.get(j).other(v).id + "' ");
                }
                verbose.println("}");
            }
        }
        return false;
    }
    if (verbose != null)
        verbose.printf("_ scene[%d].open.size=%d score=%.2f conn=%d\n", scene.index, scene.open.size, bestScore, bestValidCount);
    selection.score = bestScore;
    selection.openIdx = bestIdx;
    return true;
}
Also used : View(boofcv.alg.structure.PairwiseImageGraph.View) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Example 20 with View

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

the class ReconstructionFromPairwiseGraph method scoreSeedAndSelectSet.

/**
 * Scores how the target as a seed and selects the initial set of views it should spawn from.
 */
protected SeedInfo scoreSeedAndSelectSet(View target, int maxMotions, SeedInfo output) {
    output.seed = target;
    scoresMotions.reset();
    // score all edges
    for (int i = 0; i < target.connections.size; i++) {
        PairwiseImageGraph.Motion m = target.connections.get(i);
        if (!m.is3D)
            continue;
        scoresMotions.grow().set(m.score3D, i);
    }
    // selected ones. This avoids selecting two nearly identical views
    while (output.motions.size < maxMotions && !scoresMotions.isEmpty()) {
        double bestScore = 0;
        int bestMotion = -1;
        for (int i = 0; i < scoresMotions.size; i++) {
            // set the score initially to the score with the target
            double score = scoresMotions.get(i).score;
            PairwiseImageGraph.View va = target.connections.get(scoresMotions.get(i).index).other(target);
            // Go through all already selected motions. Reduce the score is similar to another view.
            // Disqualify if so similar it doesn't have a 3D connection
            boolean foundValid = true;
            for (int outIdx = 0; outIdx < output.motions.size; outIdx++) {
                int connIdx = output.motions.get(outIdx);
                PairwiseImageGraph.View vb = target.connections.get(connIdx).other(target);
                PairwiseImageGraph.Motion m = va.findMotion(vb);
                // All seed views must be connected with each other with a 3D relationship
                if (m == null || !m.is3D) {
                    foundValid = false;
                    break;
                }
                score = Math.min(score, m.score3D);
            }
            if (!foundValid || score <= bestScore)
                continue;
            bestScore = score;
            bestMotion = i;
        }
        // stop if it can't find another valid view
        if (bestScore == 0.0)
            break;
        output.motions.add(scoresMotions.removeSwap(bestMotion).index);
        output.score += bestScore;
    }
    return output;
}
Also used : View(boofcv.alg.structure.PairwiseImageGraph.View) VerbosePrint(org.ddogleg.struct.VerbosePrint)

Aggregations

View (boofcv.alg.structure.PairwiseImageGraph.View)20 Test (org.junit.jupiter.api.Test)9 Motion (boofcv.alg.structure.PairwiseImageGraph.Motion)8 VerbosePrint (org.ddogleg.struct.VerbosePrint)8 DogArray_I32 (org.ddogleg.struct.DogArray_I32)6 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)4 ArrayList (java.util.ArrayList)4 Point2D_F64 (georegression.struct.point.Point2D_F64)3 DMatrixRMaj (org.ejml.data.DMatrixRMaj)3 PairwiseImageGraph (boofcv.alg.structure.PairwiseImageGraph)2 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)2 CompatibleProjectiveHomography (boofcv.alg.geo.pose.CompatibleProjectiveHomography)1 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)1 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)1 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)1 Point3D_F64 (georegression.struct.point.Point3D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 Rodrigues_F64 (georegression.struct.so.Rodrigues_F64)1