Search in sources :

Example 1 with ModelManagerSe2_F64

use of georegression.fitting.se.ModelManagerSe2_F64 in project BoofCV by lessthanoptimal.

the class FactoryMotion2D method createMotion2D.

/**
 * Estimates the 2D motion of an image using different models.
 *
 * @param ransacIterations Number of RANSAC iterations
 * @param inlierThreshold Threshold which defines an inlier.
 * @param outlierPrune If a feature is an outlier for this many turns in a row it is dropped. Try 2
 * @param absoluteMinimumTracks New features will be respawned if the number of inliers drop below this number.
 * @param respawnTrackFraction If the fraction of current inliers to the original number of inliers drops below
 * this fraction then new features are spawned. Try 0.3
 * @param respawnCoverageFraction If the area covered drops by this fraction then spawn more features. Try 0.8
 * @param refineEstimate Should it refine the model estimate using all inliers.
 * @param tracker Point feature tracker.
 * @param motionModel Instance of the model model used. Affine2D_F64 or Homography2D_F64
 * @param <I> Image input type.
 * @param <IT> Model model
 * @return ImageMotion2D
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static <I extends ImageBase<I>, IT extends InvertibleTransform<IT>> ImageMotion2D<I, IT> createMotion2D(int ransacIterations, double inlierThreshold, int outlierPrune, int absoluteMinimumTracks, double respawnTrackFraction, double respawnCoverageFraction, boolean refineEstimate, PointTracker<I> tracker, IT motionModel) {
    ModelManager<IT> manager;
    Factory<ModelGenerator<IT, AssociatedPair>> fitter;
    Factory<DistanceFromModel<IT, AssociatedPair>> distance;
    ModelFitter<IT, AssociatedPair> modelRefiner = null;
    if (motionModel instanceof Homography2D_F64) {
        manager = (ModelManager) new ModelManagerHomography2D_F64();
        if (refineEstimate)
            modelRefiner = (ModelFitter) new GenerateHomographyLinear(true);
        fitter = () -> (ModelGenerator) new GenerateHomographyLinear(true);
        distance = () -> (DistanceFromModel) new DistanceHomographySq();
    } else if (motionModel instanceof Affine2D_F64) {
        manager = (ModelManager) new ModelManagerAffine2D_F64();
        if (refineEstimate)
            modelRefiner = (ModelFitter) new GenerateAffine2D();
        fitter = () -> (ModelGenerator) new GenerateAffine2D();
        distance = () -> (DistanceFromModel) new DistanceAffine2DSq();
    } else if (motionModel instanceof Se2_F64) {
        manager = (ModelManager) new ModelManagerSe2_F64();
        fitter = () -> (ModelGenerator) new GenerateSe2_AssociatedPair(new MotionSe2PointSVD_F64());
        distance = () -> (DistanceFromModel) new DistanceSe2Sq();
    // no refine, already optimal
    } else {
        throw new RuntimeException("Unknown model type: " + motionModel.getClass().getSimpleName());
    }
    ModelMatcherPost<IT, AssociatedPair> modelMatcher = new Ransac<>(123123, ransacIterations, inlierThreshold, manager, AssociatedPair.class);
    modelMatcher.setModel(fitter, distance);
    ImageMotionPointTrackerKey<I, IT> lowlevel = new ImageMotionPointTrackerKey<>(tracker, modelMatcher, modelRefiner, motionModel, outlierPrune);
    ImageMotionPtkSmartRespawn<I, IT> smartRespawn = new ImageMotionPtkSmartRespawn<>(lowlevel, absoluteMinimumTracks, respawnTrackFraction, respawnCoverageFraction);
    return new WrapImageMotionPtkSmartRespawn<>(smartRespawn);
}
Also used : Homography2D_F64(georegression.struct.homography.Homography2D_F64) ModelManagerHomography2D_F64(georegression.fitting.homography.ModelManagerHomography2D_F64) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) MotionSe2PointSVD_F64(georegression.fitting.se.MotionSe2PointSVD_F64) ModelManagerAffine2D_F64(georegression.fitting.affine.ModelManagerAffine2D_F64) AssociatedPair(boofcv.struct.geo.AssociatedPair) ModelManagerHomography2D_F64(georegression.fitting.homography.ModelManagerHomography2D_F64) WrapImageMotionPtkSmartRespawn(boofcv.abst.sfm.d2.WrapImageMotionPtkSmartRespawn) ModelManagerSe2_F64(georegression.fitting.se.ModelManagerSe2_F64) Se2_F64(georegression.struct.se.Se2_F64) ModelManagerSe2_F64(georegression.fitting.se.ModelManagerSe2_F64) ModelManagerAffine2D_F64(georegression.fitting.affine.ModelManagerAffine2D_F64) Affine2D_F64(georegression.struct.affine.Affine2D_F64) WrapImageMotionPtkSmartRespawn(boofcv.abst.sfm.d2.WrapImageMotionPtkSmartRespawn)

Example 2 with ModelManagerSe2_F64

use of georegression.fitting.se.ModelManagerSe2_F64 in project BoofCV by lessthanoptimal.

the class FactoryVisualOdometry method monoPlaneInfinity.

/**
 * Monocular plane based visual odometry algorithm which uses both points on the plane and off plane for motion
 * estimation.
 *
 * @see VisOdomMonoPlaneInfinity
 *
 * @param thresholdAdd  New points are spawned when the number of on plane inliers drops below this value.
 * @param thresholdRetire Tracks are dropped when they are not contained in the inlier set for this many frames
 *                        in a row.  Try 2
 * @param inlierPixelTol Threshold used to determine inliers in pixels.  Try 1.5
 * @param ransacIterations Number of RANSAC iterations.  Try 200
 * @param tracker Image feature tracker
 * @param imageType Type of input image it processes
 * @param <T>
 * @return New instance of
 */
public static <T extends ImageGray<T>> MonocularPlaneVisualOdometry<T> monoPlaneInfinity(int thresholdAdd, int thresholdRetire, double inlierPixelTol, int ransacIterations, PointTracker<T> tracker, ImageType<T> imageType) {
    // squared pixel error
    double ransacTOL = inlierPixelTol * inlierPixelTol;
    ModelManagerSe2_F64 manager = new ModelManagerSe2_F64();
    DistancePlane2DToPixelSq distance = new DistancePlane2DToPixelSq();
    GenerateSe2_PlanePtPixel generator = new GenerateSe2_PlanePtPixel();
    ModelMatcher<Se2_F64, PlanePtPixel> motion = new Ransac<>(2323, manager, generator, distance, ransacIterations, ransacTOL);
    VisOdomMonoPlaneInfinity<T> alg = new VisOdomMonoPlaneInfinity<>(thresholdAdd, thresholdRetire, inlierPixelTol, motion, tracker);
    return new MonoPlaneInfinity_to_MonocularPlaneVisualOdometry<>(alg, distance, generator, imageType);
}
Also used : GenerateSe2_PlanePtPixel(boofcv.alg.sfm.robust.GenerateSe2_PlanePtPixel) GenerateSe2_PlanePtPixel(boofcv.alg.sfm.robust.GenerateSe2_PlanePtPixel) PlanePtPixel(boofcv.struct.sfm.PlanePtPixel) DistancePlane2DToPixelSq(boofcv.alg.sfm.robust.DistancePlane2DToPixelSq) ModelManagerSe2_F64(georegression.fitting.se.ModelManagerSe2_F64) Se2_F64(georegression.struct.se.Se2_F64) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac) ModelManagerSe2_F64(georegression.fitting.se.ModelManagerSe2_F64)

Aggregations

ModelManagerSe2_F64 (georegression.fitting.se.ModelManagerSe2_F64)2 Se2_F64 (georegression.struct.se.Se2_F64)2 Ransac (org.ddogleg.fitting.modelset.ransac.Ransac)2 WrapImageMotionPtkSmartRespawn (boofcv.abst.sfm.d2.WrapImageMotionPtkSmartRespawn)1 DistancePlane2DToPixelSq (boofcv.alg.sfm.robust.DistancePlane2DToPixelSq)1 GenerateSe2_PlanePtPixel (boofcv.alg.sfm.robust.GenerateSe2_PlanePtPixel)1 AssociatedPair (boofcv.struct.geo.AssociatedPair)1 PlanePtPixel (boofcv.struct.sfm.PlanePtPixel)1 ModelManagerAffine2D_F64 (georegression.fitting.affine.ModelManagerAffine2D_F64)1 ModelManagerHomography2D_F64 (georegression.fitting.homography.ModelManagerHomography2D_F64)1 MotionSe2PointSVD_F64 (georegression.fitting.se.MotionSe2PointSVD_F64)1 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)1 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)1