Search in sources :

Example 11 with Homography2D_F64

use of georegression.struct.homography.Homography2D_F64 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 12 with Homography2D_F64

use of georegression.struct.homography.Homography2D_F64 in project BoofCV by lessthanoptimal.

the class FactoryMultiViewRobust method homographyRansac.

/**
 * Robust solution for estimating {@link Homography2D_F64} with {@link Ransac}.  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 ransac Parameters for RANSAC.  Can't be null.
 * @return Homography estimator
 */
public static Ransac<Homography2D_F64, AssociatedPair> homographyRansac(ConfigHomography homography, ConfigRansac ransac) {
    if (homography == null)
        homography = new ConfigHomography();
    ModelManager<Homography2D_F64> manager = new ModelManagerHomography2D_F64();
    GenerateHomographyLinear modelFitter = new GenerateHomographyLinear(homography.normalize);
    DistanceHomographySq distance = new DistanceHomographySq();
    double ransacTol = ransac.inlierThreshold * ransac.inlierThreshold;
    return new Ransac<>(ransac.randSeed, manager, modelFitter, distance, ransac.maxIterations, ransacTol);
}
Also used : DistanceHomographySq(boofcv.alg.geo.robust.DistanceHomographySq) ModelManagerHomography2D_F64(georegression.fitting.homography.ModelManagerHomography2D_F64) GenerateHomographyLinear(boofcv.alg.geo.robust.GenerateHomographyLinear) Homography2D_F64(georegression.struct.homography.Homography2D_F64) ModelManagerHomography2D_F64(georegression.fitting.homography.ModelManagerHomography2D_F64) Ransac(org.ddogleg.fitting.modelset.ransac.Ransac)

Example 13 with Homography2D_F64

use of georegression.struct.homography.Homography2D_F64 in project BoofCV by lessthanoptimal.

the class TestDistanceHomographyPixelSq method distance.

@Override
public double distance(Homography2D_F64 h, AssociatedPair associatedPair) {
    Point2D_F64 result = new Point2D_F64();
    Point2D_F64 pixel1 = new Point2D_F64();
    Point2D_F64 pixel2 = new Point2D_F64();
    // convert points into pixel coordinates
    PerspectiveOps.convertNormToPixel(K, associatedPair.p1, pixel1);
    PerspectiveOps.convertNormToPixel(K, associatedPair.p2, pixel2);
    // compute error in pixels, which is what it should be in
    Homography2D_F64 h_pixel = new Homography2D_F64();
    UtilHomography_F64.convert(H_pixel, h_pixel);
    HomographyPointOps_F64.transform(h_pixel, pixel1, result);
    return result.distance2(pixel2);
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Homography2D_F64(georegression.struct.homography.Homography2D_F64)

Example 14 with Homography2D_F64

use of georegression.struct.homography.Homography2D_F64 in project BoofCV by lessthanoptimal.

the class TestDistanceHomographyPixelSq method createRandomModel.

@Override
public Homography2D_F64 createRandomModel() {
    double rotX = rand.nextGaussian();
    double rotY = rand.nextGaussian();
    double rotZ = rand.nextGaussian();
    DMatrixRMaj R = ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, rotX, rotY, rotZ, null);
    Vector3D_F64 T = new Vector3D_F64(0.2, -0.5, 3);
    Vector3D_F64 N = new Vector3D_F64(-0.5, 1, 3);
    // compute the Homography in normalized image coordinates and pixel coordinates
    H = MultiViewOps.createHomography(R, T, 1.0, N);
    H_pixel = MultiViewOps.createHomography(R, T, 1.0, N, K);
    Homography2D_F64 h = new Homography2D_F64();
    UtilHomography_F64.convert(H, h);
    return h;
}
Also used : Vector3D_F64(georegression.struct.point.Vector3D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Homography2D_F64(georegression.struct.homography.Homography2D_F64)

Example 15 with Homography2D_F64

use of georegression.struct.homography.Homography2D_F64 in project BoofCV by lessthanoptimal.

the class VideoStitchBaseApp method updateAlgGUI.

@Override
protected void updateAlgGUI(I frame, BufferedImage imageGUI, final double fps) {
    if (!hasProcessedImage)
        return;
    corners = alg.getImageCorners(frame.width, frame.height, null);
    ConvertBufferedImage.convertTo(alg.getStitchedImage(), stitchOut, true);
    if (checkLocation(corners)) {
        // the change will only be visible in the next update
        alg.setOriginToCurrent();
    }
    AccessPointTracks access = (AccessPointTracks) alg.getMotion();
    List<Point2D_F64> tracks = access.getAllTracks();
    List<Point2D_F64> inliers = new ArrayList<>();
    for (int i = 0; i < tracks.size(); i++) {
        if (access.isInlier(i))
            inliers.add(tracks.get(i));
    }
    final int numInliers = inliers.size();
    final int numFeatures = tracks.size();
    showImageView = infoPanel.getShowView();
    gui.setImages(imageGUI, stitchOut);
    gui.setShowImageView(infoPanel.getShowView());
    gui.setCorners(corners);
    // toggle on and off showing the active tracks
    if (infoPanel.getShowInliers())
        gui.setInliers(inliers);
    else
        gui.setInliers(null);
    if (infoPanel.getShowAll())
        gui.setAllTracks(tracks);
    else
        gui.setAllTracks(null);
    Homography2D_F64 H = alg.getWorldToCurr(null).invert(null);
    gui.setCurrToWorld(H);
    // update GUI
    SwingUtilities.invokeLater(new Runnable() {

        public void run() {
            // update GUI
            infoPanel.setFPS(fps);
            infoPanel.setNumInliers(numInliers);
            infoPanel.setNumTracks(numFeatures);
            infoPanel.setKeyFrames(totalResets);
            infoPanel.repaint();
            gui.repaint();
        }
    });
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) AccessPointTracks(boofcv.abst.sfm.AccessPointTracks) Homography2D_F64(georegression.struct.homography.Homography2D_F64)

Aggregations

Homography2D_F64 (georegression.struct.homography.Homography2D_F64)18 Point2D_F64 (georegression.struct.point.Point2D_F64)5 GrayF32 (boofcv.struct.image.GrayF32)4 BufferedImage (java.awt.image.BufferedImage)4 ConfigGeneralDetector (boofcv.abst.feature.detect.interest.ConfigGeneralDetector)3 ImageGridPanel (boofcv.gui.image.ImageGridPanel)3 MediaManager (boofcv.io.MediaManager)3 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 DefaultMediaManager (boofcv.io.wrapper.DefaultMediaManager)3 AssociatedPair (boofcv.struct.geo.AssociatedPair)3 Planar (boofcv.struct.image.Planar)3 ModelManagerHomography2D_F64 (georegression.fitting.homography.ModelManagerHomography2D_F64)3 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)3 PlToGrayMotion2D (boofcv.abst.sfm.d2.PlToGrayMotion2D)2 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)2 PixelTransformHomography_F32 (boofcv.alg.distort.PixelTransformHomography_F32)2 DistanceHomographySq (boofcv.alg.geo.robust.DistanceHomographySq)2 GenerateHomographyLinear (boofcv.alg.geo.robust.GenerateHomographyLinear)2 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)2 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)2