Search in sources :

Example 1 with GenerateEpipolarMatrix

use of boofcv.abst.geo.fitting.GenerateEpipolarMatrix in project BoofCV by lessthanoptimal.

the class ExampleFundamentalMatrix method robustFundamental.

/**
 * Given a set of noisy observations, compute the Fundamental matrix while removing
 * the noise.
 *
 * @param matches List of associated features between the two images
 * @param inliers List of feature pairs that were determined to not be noise.
 * @return The found fundamental matrix.
 */
public static DMatrixRMaj robustFundamental(List<AssociatedPair> matches, List<AssociatedPair> inliers) {
    // used to create and copy new instances of the fit model
    ModelManager<DMatrixRMaj> managerF = new ModelManagerEpipolarMatrix();
    // Select which linear algorithm is to be used.  Try playing with the number of remove ambiguity points
    Estimate1ofEpipolar estimateF = FactoryMultiView.computeFundamental_1(EnumFundamental.LINEAR_7, 2);
    // Wrapper so that this estimator can be used by the robust estimator
    GenerateEpipolarMatrix generateF = new GenerateEpipolarMatrix(estimateF);
    // How the error is measured
    DistanceFromModelResidual<DMatrixRMaj, AssociatedPair> errorMetric = new DistanceFromModelResidual<>(new FundamentalResidualSampson());
    // Use RANSAC to estimate the Fundamental matrix
    ModelMatcher<DMatrixRMaj, AssociatedPair> robustF = new Ransac<>(123123, managerF, generateF, errorMetric, 6000, 0.1);
    // Estimate the fundamental matrix while removing outliers
    if (!robustF.process(matches))
        throw new IllegalArgumentException("Failed");
    // save the set of features that were used to compute the fundamental matrix
    inliers.addAll(robustF.getMatchSet());
    // Improve the estimate of the fundamental matrix using non-linear optimization
    DMatrixRMaj F = new DMatrixRMaj(3, 3);
    ModelFitter<DMatrixRMaj, AssociatedPair> refine = FactoryMultiView.refineFundamental(1e-8, 400, EpipolarError.SAMPSON);
    if (!refine.fitModel(inliers, robustF.getModelParameters(), F))
        throw new IllegalArgumentException("Failed");
    // Return the solution
    return F;
}
Also used : GenerateEpipolarMatrix(boofcv.abst.geo.fitting.GenerateEpipolarMatrix) AssociatedPair(boofcv.struct.geo.AssociatedPair) Estimate1ofEpipolar(boofcv.abst.geo.Estimate1ofEpipolar) DistanceFromModelResidual(boofcv.abst.geo.fitting.DistanceFromModelResidual) DMatrixRMaj(org.ejml.data.DMatrixRMaj) FundamentalResidualSampson(boofcv.alg.geo.f.FundamentalResidualSampson) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) ModelManagerEpipolarMatrix(boofcv.abst.geo.fitting.ModelManagerEpipolarMatrix)

Aggregations

Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)1 DistanceFromModelResidual (boofcv.abst.geo.fitting.DistanceFromModelResidual)1 GenerateEpipolarMatrix (boofcv.abst.geo.fitting.GenerateEpipolarMatrix)1 ModelManagerEpipolarMatrix (boofcv.abst.geo.fitting.ModelManagerEpipolarMatrix)1 FundamentalResidualSampson (boofcv.alg.geo.f.FundamentalResidualSampson)1 AssociatedPair (boofcv.struct.geo.AssociatedPair)1 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1