Search in sources :

Example 11 with AssociatedPair

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

the class ExampleStereoTwoViewsOneCamera method convertToNormalizedCoordinates.

/**
 * Convert a set of associated point features from pixel coordinates into normalized image coordinates.
 */
public static List<AssociatedPair> convertToNormalizedCoordinates(List<AssociatedPair> matchedFeatures, CameraPinholeRadial intrinsic) {
    Point2Transform2_F64 p_to_n = LensDistortionOps.narrow(intrinsic).undistort_F64(true, false);
    List<AssociatedPair> calibratedFeatures = new ArrayList<>();
    for (AssociatedPair p : matchedFeatures) {
        AssociatedPair c = new AssociatedPair();
        p_to_n.compute(p.p1.x, p.p1.y, c.p1);
        p_to_n.compute(p.p2.x, p.p2.y, c.p2);
        calibratedFeatures.add(c);
    }
    return calibratedFeatures;
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) ArrayList(java.util.ArrayList)

Example 12 with AssociatedPair

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

the class ExampleStereoTwoViewsOneCamera method estimateCameraMotion.

/**
 * Estimates the camera motion robustly using RANSAC and a set of associated points.
 *
 * @param intrinsic   Intrinsic camera parameters
 * @param matchedNorm set of matched point features in normalized image coordinates
 * @param inliers     OUTPUT: Set of inlier features from RANSAC
 * @return Found camera motion.  Note translation has an arbitrary scale
 */
public static Se3_F64 estimateCameraMotion(CameraPinholeRadial intrinsic, List<AssociatedPair> matchedNorm, List<AssociatedPair> inliers) {
    ModelMatcher<Se3_F64, AssociatedPair> epipolarMotion = FactoryMultiViewRobust.essentialRansac(new ConfigEssential(intrinsic), new ConfigRansac(200, 0.5));
    if (!epipolarMotion.process(matchedNorm))
        throw new RuntimeException("Motion estimation failed");
    // save inlier set for debugging purposes
    inliers.addAll(epipolarMotion.getMatchSet());
    return epipolarMotion.getModelParameters();
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) ConfigEssential(boofcv.factory.geo.ConfigEssential) ConfigRansac(boofcv.factory.geo.ConfigRansac) Se3_F64(georegression.struct.se.Se3_F64)

Example 13 with AssociatedPair

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

the class CommonMotionNPoint method generateScene.

protected void generateScene(int N, Se3_F64 motion, boolean planar) {
    this.motion = motion;
    // randomly generate points in space
    if (planar) {
        worldPts = CommonHomographyChecks.createRandomPlane(rand, 3, N);
    } else {
        worldPts = GeoTestingOps.randomPoints_F64(-1, 1, -1, 1, 2, 3, N, rand);
    }
    cameraPts = new ArrayList<>();
    // transform points into second camera's reference frame
    assocPairs = new ArrayList<>();
    pointPose = new ArrayList<>();
    for (Point3D_F64 p1 : worldPts) {
        Point3D_F64 p2 = SePointOps_F64.transform(motion, p1, null);
        AssociatedPair pair = new AssociatedPair();
        pair.p1.set(p1.x / p1.z, p1.y / p1.z);
        pair.p2.set(p2.x / p2.z, p2.y / p2.z);
        assocPairs.add(pair);
        pointPose.add(new Point2D3D(pair.p2, p1));
        cameraPts.add(p2);
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point3D_F64(georegression.struct.point.Point3D_F64) Point2D3D(boofcv.struct.geo.Point2D3D)

Example 14 with AssociatedPair

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

the class TestPnPLepetitEPnP method standardTest.

private void standardTest(final int numIterations) {
    ChecksMotionNPoint test = new ChecksMotionNPoint() {

        @Override
        public Se3_F64 compute(List<AssociatedPair> obs, List<Point3D_F64> locations) {
            PnPLepetitEPnP alg = new PnPLepetitEPnP();
            List<Point2D_F64> currObs = new ArrayList<>();
            for (AssociatedPair a : obs) {
                currObs.add(a.p2);
            }
            Se3_F64 solution = new Se3_F64();
            alg.setNumIterations(numIterations);
            alg.process(locations, currObs, solution);
            return solution;
        }
    };
    for (int i = 0; i < 20; i++) {
        // the minimal case is not tested here since its too unstable
        for (int N = 5; N < 10; N++) {
            test.testNoMotion(N);
            test.standardTest(N);
            test.planarTest(N - 1);
        }
    // System.out.println();
    }
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2D_F64(georegression.struct.point.Point2D_F64) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) Se3_F64(georegression.struct.se.Se3_F64)

Example 15 with AssociatedPair

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

the class TestGenerateHomographyLinear method createRandomPointFromModel.

@Override
public AssociatedPair createRandomPointFromModel(Homography2D_F64 transform) {
    AssociatedPair ret = new AssociatedPair();
    ret.p1.x = rand.nextDouble() * 10;
    ret.p1.y = rand.nextDouble() * 10;
    HomographyPointOps_F64.transform(transform, ret.p1, ret.p2);
    return ret;
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair)

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