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;
}
Aggregations