Search in sources :

Example 6 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class BenchmarkStabilityFundamental method evaluateAll.

public void evaluateAll(GeoModelEstimator1<DMatrixRMaj, AssociatedPair> estimator) {
    scores = new ArrayList<>();
    int failed = 0;
    DMatrixRMaj F = new DMatrixRMaj(3, 3);
    for (int i = 0; i < 50; i++) {
        if (!estimator.process(observations, F)) {
            failed++;
            continue;
        }
        // normalize the scale of F
        CommonOps_DDRM.scale(1.0 / CommonOps_DDRM.elementMaxAbs(F), F);
        // 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);
        }
    }
    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) DMatrixRMaj(org.ejml.data.DMatrixRMaj) DistanceEpipolarConstraint(boofcv.alg.geo.f.DistanceEpipolarConstraint)

Example 7 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class EssentialNister5 method computeSpan.

/**
 * From the epipolar constraint p2^T*E*p1 = 0 construct a linear system
 * and find its null space.
 */
private void computeSpan(List<AssociatedPair> points) {
    Q.reshape(points.size(), 9);
    int index = 0;
    for (int i = 0; i < points.size(); i++) {
        AssociatedPair p = points.get(i);
        Point2D_F64 a = p.p2;
        Point2D_F64 b = p.p1;
        // The points are assumed to be in homogeneous coordinates.  This means z = 1
        Q.data[index++] = a.x * b.x;
        Q.data[index++] = a.x * b.y;
        Q.data[index++] = a.x;
        Q.data[index++] = a.y * b.x;
        Q.data[index++] = a.y * b.y;
        Q.data[index++] = a.y;
        Q.data[index++] = b.x;
        Q.data[index++] = b.y;
        Q.data[index++] = 1;
    }
    if (!solverNull.process(Q, 4, nullspace))
        throw new RuntimeException("Nullspace solver should never fail, probably bad input");
    // extract the span of solutions for E from the null space
    for (int i = 0; i < 9; i++) {
        X[i] = nullspace.unsafe_get(i, 0);
        Y[i] = nullspace.unsafe_get(i, 1);
        Z[i] = nullspace.unsafe_get(i, 2);
        W[i] = nullspace.unsafe_get(i, 3);
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2D_F64(georegression.struct.point.Point2D_F64)

Example 8 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class LowLevelMultiViewOps method applyNormalization.

public static void applyNormalization(List<AssociatedPair> points, NormalizationPoint2D N1, NormalizationPoint2D N2, DMatrix1Row X1, DMatrixRMaj X2) {
    final int size = points.size();
    X1.reshape(size, 2);
    X2.reshape(size, 2);
    for (int i = 0, index = 0; i < size; i++, index += 2) {
        AssociatedPair pair = points.get(i);
        X1.data[index] = (pair.p1.x - N1.meanX) / N1.stdX;
        X1.data[index + 1] = (pair.p1.y - N1.meanY) / N1.stdY;
        X2.data[index] = (pair.p2.x - N2.meanX) / N2.stdX;
        X2.data[index + 1] = (pair.p2.y - N2.meanY) / N2.stdY;
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair)

Example 9 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair 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)

Example 10 with AssociatedPair

use of boofcv.struct.geo.AssociatedPair in project BoofCV by lessthanoptimal.

the class ExampleFundamentalMatrix method main.

public static void main(String[] args) {
    String dir = UtilIO.pathExample("structure/");
    BufferedImage imageA = UtilImageIO.loadImage(dir, "undist_cyto_01.jpg");
    BufferedImage imageB = UtilImageIO.loadImage(dir, "undist_cyto_02.jpg");
    List<AssociatedPair> matches = computeMatches(imageA, imageB);
    // Where the fundamental matrix is stored
    DMatrixRMaj F;
    // List of matches that matched the model
    List<AssociatedPair> inliers = new ArrayList<>();
    // estimate and print the results using a robust and simple estimator
    // The results should be difference since there are many false associations in the simple model
    // Also note that the fundamental matrix is only defined up to a scale factor.
    F = robustFundamental(matches, inliers);
    System.out.println("Robust");
    F.print();
    F = simpleFundamental(matches);
    System.out.println("Simple");
    F.print();
    // display the inlier matches found using the robust estimator
    AssociationPanel panel = new AssociationPanel(20);
    panel.setAssociation(inliers);
    panel.setImages(imageA, imageB);
    ShowImages.showWindow(panel, "Inlier Pairs");
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ArrayList(java.util.ArrayList) AssociationPanel(boofcv.gui.feature.AssociationPanel) BufferedImage(java.awt.image.BufferedImage)

Aggregations

AssociatedPair (boofcv.struct.geo.AssociatedPair)110 Test (org.junit.Test)32 Point2D_F64 (georegression.struct.point.Point2D_F64)28 ArrayList (java.util.ArrayList)27 DMatrixRMaj (org.ejml.data.DMatrixRMaj)22 Se3_F64 (georegression.struct.se.Se3_F64)17 Point3D_F64 (georegression.struct.point.Point3D_F64)12 ScaleTranslate2D (boofcv.struct.sfm.ScaleTranslate2D)7 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)6 Estimate1ofEpipolar (boofcv.abst.geo.Estimate1ofEpipolar)5 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)4 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)4 ScaleTranslateRotate2D (boofcv.struct.sfm.ScaleTranslateRotate2D)4 ClosestPoint3D_F64 (georegression.metric.ClosestPoint3D_F64)4 ConfigFastHessian (boofcv.abst.feature.detect.interest.ConfigFastHessian)3 TriangulateTwoViewsCalibrated (boofcv.abst.geo.TriangulateTwoViewsCalibrated)3 AssociationPanel (boofcv.gui.feature.AssociationPanel)3 BrightFeature (boofcv.struct.feature.BrightFeature)3 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)3 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)3