Search in sources :

Example 31 with Point4D_F64

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

the class CommonThreeViewHomogenous method createScene.

public void createScene(int numFeatures, boolean planar) {
    // randomly generate points in space
    if (planar) {
        worldPts = CommonHomographyChecks.createRandomPlaneH(rand, 3, numFeatures);
    } else {
        worldPts = GeoTestingOps.randomPointsH_F64(-1, 1, -1, 1, 2, 4, numFeatures, rand);
    }
    Se3_F64 motion_0_to_0 = new Se3_F64();
    Se3_F64 motion_0_to_1 = SpecialEuclideanOps_F64.eulerXyz(0.01, 0.5, 0.2, 0.1, -0.02, 0.015, null);
    Se3_F64 motion_0_to_2 = SpecialEuclideanOps_F64.eulerXyz(0.05, 0.03, 0.53, 0.02, 0.1, -0.01, null);
    DMatrixRMaj P0 = PerspectiveOps.createCameraMatrix(motion_0_to_0.R, motion_0_to_0.T, K, null);
    DMatrixRMaj P1 = PerspectiveOps.createCameraMatrix(motion_0_to_1.R, motion_0_to_1.T, K, null);
    DMatrixRMaj P2 = PerspectiveOps.createCameraMatrix(motion_0_to_2.R, motion_0_to_2.T, K, null);
    cameras.clear();
    cameras.add(P0);
    cameras.add(P1);
    cameras.add(P2);
    fundamentals.clear();
    fundamentals.add(MultiViewOps.createFundamental(motion_0_to_1.R, motion_0_to_1.T, K, K, null));
    fundamentals.add(MultiViewOps.createFundamental(motion_0_to_2.R, motion_0_to_2.T, K, K, null));
    triples.clear();
    pixelsInView[0] = new ArrayList<>();
    pixelsInView[1] = new ArrayList<>();
    pixelsInView[2] = new ArrayList<>();
    Point2D_F64 x0 = new Point2D_F64();
    Point2D_F64 x1 = new Point2D_F64();
    Point2D_F64 x2 = new Point2D_F64();
    for (int i = 0; i < numFeatures; i++) {
        Point4D_F64 X = worldPts.get(i);
        PerspectiveOps.renderPixel(P0, X, x0);
        PerspectiveOps.renderPixel(P1, X, x1);
        PerspectiveOps.renderPixel(P2, X, x2);
        pixelsInView[0].add(x0.copy());
        pixelsInView[1].add(x1.copy());
        pixelsInView[2].add(x2.copy());
        AssociatedTriple t = new AssociatedTriple();
        t.setTo(x0, x1, x2);
        triples.add(t);
    }
}
Also used : AssociatedTriple(boofcv.struct.geo.AssociatedTriple) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Point4D_F64(georegression.struct.point.Point4D_F64) Se3_F64(georegression.struct.se.Se3_F64)

Example 32 with Point4D_F64

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

the class TestProjectiveReconstructionByFactorization method perfect_input.

/**
 * Perfect observations and perfect input, Output should be just perfect
 */
@Test
void perfect_input() {
    int numViews = 8;
    int numFeatures = 10;
    simulate(numViews, numFeatures, false);
    ProjectiveStructureByFactorization alg = new ProjectiveStructureByFactorization();
    alg.initialize(features3D.size(), projections.size());
    // Perfect depths. It should only need 1 iteration
    setPerfectDepths(numFeatures, alg);
    // noise free pixel observations too
    for (int viewIdx = 0; viewIdx < projections.size(); viewIdx++) {
        alg.setPixels(viewIdx, observations.get(viewIdx));
    }
    assertTrue(alg.process());
    DMatrixRMaj P = new DMatrixRMaj(3, 4);
    Point4D_F64 X = new Point4D_F64();
    for (int viewIdx = 0; viewIdx < numViews; viewIdx++) {
        alg.getCameraMatrix(viewIdx, P);
        for (int featureIdx = 0; featureIdx < numFeatures; featureIdx++) {
            alg.getFeature3D(featureIdx, X);
            Point2D_F64 expected = observations.get(viewIdx).get(featureIdx);
            Point3D_F64 xh = PerspectiveOps.renderPixel(P, X, (Point3D_F64) null);
            Point2D_F64 found = new Point2D_F64(xh.x / xh.z, xh.y / xh.z);
            assertTrue(expected.distance(found) < UtilEjml.TEST_F64);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Point4D_F64(georegression.struct.point.Point4D_F64) Test(org.junit.jupiter.api.Test)

Example 33 with Point4D_F64

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

the class TestTriangulateProjectiveLinearDLT method triangulate_metric_N.

/**
 * Create 3 perfect observations and solve for the position. Everything is in metric instead of an arbtirary
 * projective frame for ease of testing.
 */
@Test
void triangulate_metric_N() {
    createScene();
    TriangulateProjectiveLinearDLT alg = new TriangulateProjectiveLinearDLT();
    Point4D_F64 found = new Point4D_F64();
    alg.triangulate(obsPixels, cameraMatrices, found);
    found.x /= found.w;
    found.y /= found.w;
    found.z /= found.w;
    assertEquals(worldPoint.x, found.x, 1e-8);
    assertEquals(worldPoint.y, found.y, 1e-8);
    assertEquals(worldPoint.z, found.z, 1e-8);
}
Also used : Point4D_F64(georegression.struct.point.Point4D_F64) Test(org.junit.jupiter.api.Test)

Example 34 with Point4D_F64

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

the class TestTriangulateProjectiveLinearDLT method triangulate_projective.

/**
 * Test case with a true projective situation
 */
@Test
void triangulate_projective() {
    createScene();
    TriangulateProjectiveLinearDLT alg = new TriangulateProjectiveLinearDLT();
    Point4D_F64 foundX = new Point4D_F64();
    alg.triangulate(obsPixels, cameraMatrices, foundX);
    // project the found coordinate back on to each image
    Point2D_F64 foundPixel = new Point2D_F64();
    for (int i = 0; i < cameraMatrices.size(); i++) {
        DMatrixRMaj P = cameraMatrices.get(i);
        Point2D_F64 expected = obsPixels.get(i);
        GeometryMath_F64.mult(P, foundX, foundPixel);
        assertEquals(0, expected.distance(foundPixel), UtilEjml.TEST_F64);
    }
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Point4D_F64(georegression.struct.point.Point4D_F64) Test(org.junit.jupiter.api.Test)

Example 35 with Point4D_F64

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

the class TestTriangulateMetricLinearDLT method triangulate_N.

/**
 * Create 3 perfect observations and solve for the position
 */
@Test
void triangulate_N() {
    createScene();
    TriangulateMetricLinearDLT alg = new TriangulateMetricLinearDLT();
    Point4D_F64 found = new Point4D_F64();
    alg.triangulate(obsNorm, motionWorldToCamera, found);
    assertEquals(worldPoint.x, found.x / found.w, UtilEjml.TEST_F64);
    assertEquals(worldPoint.y, found.y / found.w, UtilEjml.TEST_F64);
    assertEquals(worldPoint.z, found.z / found.w, UtilEjml.TEST_F64);
}
Also used : Point4D_F64(georegression.struct.point.Point4D_F64) Test(org.junit.jupiter.api.Test)

Aggregations

Point4D_F64 (georegression.struct.point.Point4D_F64)57 Point2D_F64 (georegression.struct.point.Point2D_F64)25 Test (org.junit.jupiter.api.Test)25 DMatrixRMaj (org.ejml.data.DMatrixRMaj)19 Point3D_F64 (georegression.struct.point.Point3D_F64)12 Se3_F64 (georegression.struct.se.Se3_F64)11 ArrayList (java.util.ArrayList)9 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)5 SceneStructureProjective (boofcv.abst.geo.bundle.SceneStructureProjective)5 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)4 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)4 DogArray_I32 (org.ddogleg.struct.DogArray_I32)4 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 AssociatedPair (boofcv.struct.geo.AssociatedPair)3 UtilPoint4D_F64 (georegression.geometry.UtilPoint4D_F64)3 DogArray (org.ddogleg.struct.DogArray)3 TriangulateNViewsMetricH (boofcv.abst.geo.TriangulateNViewsMetricH)2 RemoveBrownPtoN_F64 (boofcv.alg.distort.brown.RemoveBrownPtoN_F64)2 BundlePinhole (boofcv.alg.geo.bundle.cameras.BundlePinhole)2