Search in sources :

Example 41 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestPnPLepetitEPnP method estimateCase1.

/**
 * Create two sets of points with a known scale difference.
 */
@Test
public void estimateCase1() {
    PnPLepetitEPnP alg = new PnPLepetitEPnP();
    // skip the adjust step
    alg.numControl = 4;
    alg.alphas = new DMatrixRMaj(0, 0);
    alg.nullPts[0] = GeoTestingOps.randomPoints_F64(5, 10, -1, 2, -5, 20, 4, rand);
    double beta = 10;
    for (int i = 0; i < alg.numControl; i++) {
        Point3D_F64 p = alg.nullPts[0].get(i);
        Point3D_F64 c = alg.controlWorldPts.grow();
        c.x = p.x * beta;
        c.y = p.y * beta;
        c.z = p.z * beta;
    }
    double[] betas = new double[] { 1, 2, 3, 4 };
    alg.estimateCase1(betas);
    assertEquals(beta, betas[0], 1e-8);
    assertEquals(0, betas[1], 1e-8);
    assertEquals(0, betas[2], 1e-8);
    assertEquals(0, betas[3], 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.Test)

Example 42 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestPnPLepetitEPnP method selectWorldControlPoints_planar.

@Test
public void selectWorldControlPoints_planar() {
    List<Point3D_F64> worldPts = CommonHomographyChecks.createRandomPlane(rand, 3, 30);
    FastQueue<Point3D_F64> controlPts = new FastQueue<>(4, Point3D_F64.class, true);
    PnPLepetitEPnP alg = new PnPLepetitEPnP();
    alg.selectWorldControlPoints(worldPts, controlPts);
    assertEquals(3, alg.numControl);
    // check that each row is unique
    for (int i = 0; i < 3; i++) {
        Point3D_F64 ci = controlPts.get(i);
        for (int j = i + 1; j < 3; j++) {
            Point3D_F64 cj = controlPts.get(j);
            double dx = ci.x - cj.x;
            double dy = ci.y - cj.y;
            double dz = ci.z - cj.z;
            double sum = Math.abs(dx) + Math.abs(dy) + Math.abs(dz);
            assertTrue(sum > 0.00001);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) FastQueue(org.ddogleg.struct.FastQueue) Test(org.junit.Test)

Example 43 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestPnPLepetitEPnP method extractNullPoints.

@Test
public void extractNullPoints() {
    // create a singular matrix
    SimpleMatrix M = SimpleMatrix.wrap(RandomMatrices_DDRM.singular(12, 40, rand, 12, 11, 10, 9, 8, 7, 6, 5, 4, 3, 2, 0));
    PnPLepetitEPnP alg = new PnPLepetitEPnP();
    alg.numControl = 4;
    alg.extractNullPoints(M.getDDRM());
    // see if the first set of null points is the null space pf M*M
    List<Point3D_F64> l = alg.nullPts[0];
    SimpleMatrix v = new SimpleMatrix(12, 1);
    for (int i = 0; i < 4; i++) {
        Point3D_F64 p = l.get(i);
        v.set(3 * i + 0, p.x);
        v.set(3 * i + 1, p.y);
        v.set(3 * i + 2, p.z);
    }
    SimpleMatrix MM = M.mult(M.transpose());
    SimpleMatrix x = MM.mult(v);
    double mag = x.normF();
    assertEquals(0, mag, 1e-8);
}
Also used : SimpleMatrix(org.ejml.simple.SimpleMatrix) Point3D_F64(georegression.struct.point.Point3D_F64) Test(org.junit.Test)

Example 44 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestPnPResidualReprojection method basicTest.

@Test
public void basicTest() {
    Se3_F64 motion = new Se3_F64();
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.1, 1, -0.2, motion.getR());
    motion.getT().set(-0.3, 0.4, 1);
    Point3D_F64 world = new Point3D_F64(0.5, -0.5, 3);
    Point2D_F64 obs = new Point2D_F64();
    Point3D_F64 temp = SePointOps_F64.transform(motion, world, null);
    obs.x = temp.x / temp.z;
    obs.y = temp.y / temp.z;
    PnPResidualReprojection alg = new PnPResidualReprojection();
    // compute errors with perfect model
    double[] error = new double[alg.getN()];
    alg.setModel(motion);
    int index = alg.computeResiduals(new Point2D3D(obs, world), error, 0);
    assertEquals(alg.getN(), index);
    assertEquals(0, error[0], 1e-8);
    assertEquals(0, error[1], 1e-8);
    // compute errors with an incorrect model
    motion.getR().set(2, 1, 2);
    alg.setModel(motion);
    index = alg.computeResiduals(new Point2D3D(obs, world), error, 0);
    assertEquals(alg.getN(), index);
    assertTrue(Math.abs(error[0]) > 1e-8);
    assertTrue(Math.abs(error[1]) > 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D3D(boofcv.struct.geo.Point2D3D) Point2D_F64(georegression.struct.point.Point2D_F64) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 45 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class CommonTriangulationChecks method createScene.

public void createScene() {
    worldPoint = new Point3D_F64(0.1, -0.2, 4);
    motionWorldToCamera = new ArrayList<>();
    obsPts = new ArrayList<>();
    essential = new ArrayList<>();
    Point3D_F64 cameraPoint = new Point3D_F64();
    for (int i = 0; i < N; i++) {
        // random motion from world to frame 'i'
        Se3_F64 tranWtoI = new Se3_F64();
        if (i > 0) {
            tranWtoI.getR().set(ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, rand.nextGaussian() * 0.01, rand.nextGaussian() * 0.05, rand.nextGaussian() * 0.1, null));
            tranWtoI.getT().set(0.2 + rand.nextGaussian() * 0.1, rand.nextGaussian() * 0.1, rand.nextGaussian() * 0.01);
        }
        DMatrixRMaj E = MultiViewOps.createEssential(tranWtoI.getR(), tranWtoI.getT());
        SePointOps_F64.transform(tranWtoI, worldPoint, cameraPoint);
        Point2D_F64 o = new Point2D_F64(cameraPoint.x / cameraPoint.z, cameraPoint.y / cameraPoint.z);
        obsPts.add(o);
        motionWorldToCamera.add(tranWtoI);
        essential.add(E);
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

Point3D_F64 (georegression.struct.point.Point3D_F64)174 Point2D_F64 (georegression.struct.point.Point2D_F64)85 Test (org.junit.Test)77 Se3_F64 (georegression.struct.se.Se3_F64)74 DMatrixRMaj (org.ejml.data.DMatrixRMaj)46 ArrayList (java.util.ArrayList)17 Vector3D_F64 (georegression.struct.point.Vector3D_F64)15 Point2D3D (boofcv.struct.geo.Point2D3D)13 AssociatedPair (boofcv.struct.geo.AssociatedPair)12 GrayU8 (boofcv.struct.image.GrayU8)9 FastQueue (org.ddogleg.struct.FastQueue)9 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)8 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)7 MotionTransformPoint (georegression.fitting.MotionTransformPoint)7 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)7 PointTrack (boofcv.abst.feature.tracker.PointTrack)5 StereoParameters (boofcv.struct.calib.StereoParameters)5 TrifocalTensor (boofcv.struct.geo.TrifocalTensor)5 GrayU16 (boofcv.struct.image.GrayU16)5 Stereo2D3D (boofcv.struct.sfm.Stereo2D3D)5