Search in sources :

Example 1 with DistanceEpipolarConstraint

use of boofcv.alg.geo.f.DistanceEpipolarConstraint in project BoofCV by lessthanoptimal.

the class BenchmarkStabilityFundamental method evaluateMinimal.

public void evaluateMinimal(GeoModelEstimatorN<DMatrixRMaj, AssociatedPair> estimatorN) {
    DistanceEpipolarConstraint distance = new DistanceEpipolarConstraint();
    Estimate1ofEpipolar estimator = new EstimateNto1ofEpipolar(estimatorN, distance, 1);
    scores = new ArrayList<>();
    int failed = 0;
    int numSamples = estimator.getMinimumPoints();
    Random rand = new Random(234);
    DMatrixRMaj F = new DMatrixRMaj(3, 3);
    for (int i = 0; i < 50; i++) {
        List<AssociatedPair> pairs = new ArrayList<>();
        // create a unique set of pairs
        while (pairs.size() < numSamples) {
            AssociatedPair p = observations.get(rand.nextInt(observations.size()));
            if (!pairs.contains(p)) {
                pairs.add(p);
            }
        }
        if (!estimator.process(pairs, F)) {
            failed++;
            continue;
        }
        // normalize the scale of F
        CommonOps_DDRM.scale(1.0 / CommonOps_DDRM.elementMaxAbs(F), F);
        double totalScore = 0;
        // score against all observations
        for (AssociatedPair p : observations) {
            double score = Math.abs(GeometryMath_F64.innerProd(p.p2, F, p.p1));
            if (Double.isNaN(score))
                System.out.println("Score is NaN");
            scores.add(score);
            totalScore += score;
        }
    // System.out.println("  score["+i+"] = "+totalScore);
    }
    Collections.sort(scores);
    System.out.printf(" Failures %3d  Score:  50%% = %6.3e  95%% = %6.3e\n", failed, scores.get(scores.size() / 2), scores.get((int) (scores.size() * 0.95)));
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) DistanceEpipolarConstraint(boofcv.alg.geo.f.DistanceEpipolarConstraint) Random(java.util.Random) Estimate1ofEpipolar(boofcv.abst.geo.Estimate1ofEpipolar) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ArrayList(java.util.ArrayList) EstimateNto1ofEpipolar(boofcv.abst.geo.f.EstimateNto1ofEpipolar) DistanceEpipolarConstraint(boofcv.alg.geo.f.DistanceEpipolarConstraint)

Example 2 with DistanceEpipolarConstraint

use of boofcv.alg.geo.f.DistanceEpipolarConstraint in project BoofCV by lessthanoptimal.

the class FactoryMultiView method computeEssential_1.

public static Estimate1ofEpipolar computeEssential_1(EnumEssential which, int numRemoveAmbiguity) {
    switch(which) {
        case LINEAR_8:
            return new WrapFundamentalLinear8(false);
    }
    if (numRemoveAmbiguity <= 0)
        throw new IllegalArgumentException("numRemoveAmbiguity must be greater than zero");
    EstimateNofEpipolar alg = computeEssential_N(which);
    DistanceEpipolarConstraint distance = new DistanceEpipolarConstraint();
    return new EstimateNto1ofEpipolar(alg, distance, numRemoveAmbiguity);
}
Also used : DistanceEpipolarConstraint(boofcv.alg.geo.f.DistanceEpipolarConstraint)

Example 3 with DistanceEpipolarConstraint

use of boofcv.alg.geo.f.DistanceEpipolarConstraint in project BoofCV by lessthanoptimal.

the class FactoryMultiView method computeFundamental_1.

/**
 * <p>
 * Similar to {@link #computeFundamental_N}, but it returns only a single hypothesis.  If
 * the underlying algorithm generates multiple hypotheses they are resolved by considering additional
 * sample points. For example, if you are using the 7 point algorithm at least one additional sample point
 * is required to resolve that ambiguity.  So 8 or more sample points are now required.
 * </p>
 *
 * <p>
 * All estimated epipolar matrices will have the following constraint:<br>
 * x'*F*x = 0, where F is the epipolar matrix, x' = currLoc, and x = keyLoc.
 * </p>
 *
 * <p>
 * See {@link #computeFundamental_N} for a description of the algorithms and what 'minimumSamples'
 * and 'isFundamental' do.
 * </p>
 *
 * <p>
 * The 8-point algorithm already returns a single hypothesis and ignores the 'numRemoveAmbiguity' parameter.
 * All other algorithms require one or more points to remove ambiguity.  Understanding a bit of theory is required
 * to understand what a good number of points is.  If a single point is used then to select the correct answer that
 * point must be in the inlier set.  If more than one point, say 10, then not all of those points must be in the
 * inlier set,
 * </p>
 *
 * @see GeoModelEstimatorNto1
 *
 * @param which Specifies which algorithm is to be created
 * @param numRemoveAmbiguity Number of sample points used to prune hypotheses. Ignored if only a single solution.
 * @return Fundamental or essential estimation algorithm that returns a single hypothesis.
 */
public static Estimate1ofEpipolar computeFundamental_1(EnumFundamental which, int numRemoveAmbiguity) {
    switch(which) {
        case LINEAR_8:
            return new WrapFundamentalLinear8(true);
    }
    if (numRemoveAmbiguity <= 0)
        throw new IllegalArgumentException("numRemoveAmbiguity must be greater than zero");
    EstimateNofEpipolar alg = computeFundamental_N(which);
    DistanceEpipolarConstraint distance = new DistanceEpipolarConstraint();
    return new EstimateNto1ofEpipolar(alg, distance, numRemoveAmbiguity);
}
Also used : DistanceEpipolarConstraint(boofcv.alg.geo.f.DistanceEpipolarConstraint)

Aggregations

DistanceEpipolarConstraint (boofcv.alg.geo.f.DistanceEpipolarConstraint)3 Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)1 EstimateNto1ofEpipolar (boofcv.abst.geo.f.EstimateNto1ofEpipolar)1 AssociatedPair (boofcv.struct.geo.AssociatedPair)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1