Search in sources :

Example 41 with AssociatedPair

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

the class GenerateAffine2D method fitModel.

@Override
public boolean fitModel(List<AssociatedPair> dataSet, Affine2D_F64 initial, Affine2D_F64 found) {
    from.clear();
    to.clear();
    for (int i = 0; i < dataSet.size(); i++) {
        AssociatedPair p = dataSet.get(i);
        from.add(p.p1);
        to.add(p.p2);
    }
    if (!fitter.process(from, to))
        return false;
    found.set(fitter.getTransformSrcToDst());
    return true;
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair)

Example 42 with AssociatedPair

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

the class Se3FromEssentialGenerator method generate.

/**
 * Computes the camera motion from the set of observations.   The motion is from the first
 * into the second camera frame.
 *
 * @param dataSet Associated pairs in normalized camera coordinates.
 * @param model The best pose according to the positive depth constraint.
 */
@Override
public boolean generate(List<AssociatedPair> dataSet, Se3_F64 model) {
    if (!computeEssential.process(dataSet, E))
        return false;
    // extract the possible motions
    decomposeE.decompose(E);
    List<Se3_F64> candidates = decomposeE.getSolutions();
    // use positive depth constraint to select the best one
    Se3_F64 bestModel = null;
    int bestCount = -1;
    for (int i = 0; i < candidates.size(); i++) {
        Se3_F64 s = candidates.get(i);
        int count = 0;
        for (AssociatedPair p : dataSet) {
            if (depthCheck.checkConstraint(p.p1, p.p2, s)) {
                count++;
            }
        }
        if (count > bestCount) {
            bestCount = count;
            bestModel = s;
        }
    }
    model.set(bestModel);
    return true;
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Se3_F64(georegression.struct.se.Se3_F64)

Example 43 with AssociatedPair

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

the class FactoryMultiViewRobust method epipolarRansac.

private static Ransac<Se3_F64, AssociatedPair> epipolarRansac(Estimate1ofEpipolar epipolar, CameraPinholeRadial intrinsic, ConfigRansac ransac) {
    TriangulateTwoViewsCalibrated triangulate = FactoryMultiView.triangulateTwoGeometric();
    ModelManager<Se3_F64> manager = new ModelManagerSe3_F64();
    ModelGenerator<Se3_F64, AssociatedPair> generateEpipolarMotion = new Se3FromEssentialGenerator(epipolar, triangulate);
    DistanceFromModel<Se3_F64, AssociatedPair> distanceSe3 = new DistanceSe3SymmetricSq(triangulate, intrinsic.fx, intrinsic.fy, intrinsic.skew, intrinsic.fx, intrinsic.fy, intrinsic.skew);
    double ransacTOL = ransac.inlierThreshold * ransac.inlierThreshold * 2.0;
    return new Ransac<>(ransac.randSeed, manager, generateEpipolarMotion, distanceSe3, ransac.maxIterations, ransacTOL);
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) DistanceSe3SymmetricSq(boofcv.alg.geo.robust.DistanceSe3SymmetricSq) ModelManagerSe3_F64(georegression.fitting.se.ModelManagerSe3_F64) Se3FromEssentialGenerator(boofcv.alg.geo.robust.Se3FromEssentialGenerator) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) TriangulateTwoViewsCalibrated(boofcv.abst.geo.TriangulateTwoViewsCalibrated) Se3_F64(georegression.struct.se.Se3_F64) ModelManagerSe3_F64(georegression.fitting.se.ModelManagerSe3_F64)

Example 44 with AssociatedPair

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

the class FactoryMultiViewRobust method homographyLMedS.

/**
 * Robust solution for estimating {@link Homography2D_F64} with {@link LeastMedianOfSquares LMedS}.  Input
 * observations are in pixel coordinates.
 *
 * <ul>
 *     <li>Four point linear is used internally</p>
 *     <li>inlierThreshold is in pixels</p>
 * </ul>
 *
 * <p>See code for all the details.</p>
 *
 * @param homography Homography estimation parameters.  If null default is used.
 * @param configLMedS Parameters for LMedS.  Can't be null.
 * @return Homography estimator
 */
public static LeastMedianOfSquares<Homography2D_F64, AssociatedPair> homographyLMedS(ConfigHomography homography, ConfigLMedS configLMedS) {
    if (homography == null)
        homography = new ConfigHomography();
    ModelManager<Homography2D_F64> manager = new ModelManagerHomography2D_F64();
    GenerateHomographyLinear modelFitter = new GenerateHomographyLinear(homography.normalize);
    DistanceHomographySq distance = new DistanceHomographySq();
    LeastMedianOfSquares<Homography2D_F64, AssociatedPair> lmeds = new LeastMedianOfSquares<>(configLMedS.randSeed, configLMedS.totalCycles, manager, modelFitter, distance);
    lmeds.setErrorFraction(configLMedS.errorFraction);
    return lmeds;
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) DistanceHomographySq(boofcv.alg.geo.robust.DistanceHomographySq) ModelManagerHomography2D_F64(georegression.fitting.homography.ModelManagerHomography2D_F64) GenerateHomographyLinear(boofcv.alg.geo.robust.GenerateHomographyLinear) LeastMedianOfSquares(org.ddogleg.fitting.modelset.lmeds.LeastMedianOfSquares) Homography2D_F64(georegression.struct.homography.Homography2D_F64) ModelManagerHomography2D_F64(georegression.fitting.homography.ModelManagerHomography2D_F64)

Example 45 with AssociatedPair

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

the class HomographyDirectLinearTransform method createANormalized.

/**
 * Compute the 'A' matrix used to solve for H from normalized points.
 */
protected void createANormalized(List<AssociatedPair> points, DMatrixRMaj A) {
    A.reshape(points.size() * 2, 9, false);
    A.zero();
    Point2D_F64 f_norm = new Point2D_F64();
    Point2D_F64 s_norm = new Point2D_F64();
    final int size = points.size();
    for (int i = 0; i < size; i++) {
        AssociatedPair p = points.get(i);
        // the first image
        Point2D_F64 f = p.p1;
        // the second image
        Point2D_F64 s = p.p2;
        // normalize the points
        N1.apply(f, f_norm);
        N2.apply(s, s_norm);
        A.set(i * 2, 3, -f_norm.x);
        A.set(i * 2, 4, -f_norm.y);
        A.set(i * 2, 5, -1);
        A.set(i * 2, 6, s_norm.y * f_norm.x);
        A.set(i * 2, 7, s_norm.y * f_norm.y);
        A.set(i * 2, 8, s_norm.y);
        A.set(i * 2 + 1, 0, f_norm.x);
        A.set(i * 2 + 1, 1, f_norm.y);
        A.set(i * 2 + 1, 2, 1);
        A.set(i * 2 + 1, 6, -s_norm.x * f_norm.x);
        A.set(i * 2 + 1, 7, -s_norm.x * f_norm.y);
        A.set(i * 2 + 1, 8, -s_norm.x);
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2D_F64(georegression.struct.point.Point2D_F64)

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