Search in sources :

Example 11 with SceneStructureProjective

use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.

the class TestBundleAdjustmentProjectiveSchurJacobian_DDRM method compareToNumerical_3D.

@Test
void compareToNumerical_3D() {
    SceneStructureProjective structure = createScene3D(rand);
    SceneObservations observations = createObservations(rand, structure);
    double[] param = new double[structure.getParameterCount()];
    new CodecSceneStructureProjective().encode(structure, param);
    BundleAdjustmentProjectiveSchurJacobian_DDRM alg = new BundleAdjustmentProjectiveSchurJacobian_DDRM();
    FunctionNtoMxN<DMatrixRMaj> jac = new SchurJacobian_to_NtoMxN.DDRM(alg);
    BundleAdjustmentProjectiveResidualFunction func = new BundleAdjustmentProjectiveResidualFunction();
    alg.configure(structure, observations);
    func.configure(structure, observations);
    // DerivativeChecker.jacobianPrint(func, jac, param, 0.1 );
    assertTrue(DerivativeChecker.jacobian(func, jac, param, 0.1));
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.jupiter.api.Test)

Example 12 with SceneStructureProjective

use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.

the class TestProjectiveInitializeAllCommon method checkReconstruction.

/**
 * Check reconstruction by seeing if it's consistent with the input observations
 */
private void checkReconstruction(ProjectiveInitializeAllCommon alg, MockLookupSimilarImagesRealistic db, DogArray_I32 seedConnIdx, double reprojectionTol) {
    final SceneStructureProjective structure = alg.getStructure();
    // Sanity check the number of each type of structure
    assertEquals(seedConnIdx.size + 1, structure.views.size);
    List<String> viewIds = BoofMiscOps.collectList(db.views, v -> v.id);
    int dbIndexSeed = viewIds.indexOf(alg.getPairwiseGraphViewByStructureIndex(0).id);
    // Check results for consistency. Can't do a direct comparision to ground truth since a different
    // but equivalent projective frame would have been estimated.
    Point4D_F64 X = new Point4D_F64();
    Point2D_F64 found = new Point2D_F64();
    DogArray_I32 inlierToSeed = alg.inlierIndexes.get(0);
    for (int i = 0; i < inlierToSeed.size; i++) {
        int seedFeatureIdx = inlierToSeed.get(i);
        int truthFeatIdx = db.observationToFeatureIdx(dbIndexSeed, seedFeatureIdx);
        int structureIdx = alg.seedToStructure.get(seedFeatureIdx);
        // only features that have structure should be in this list
        assertTrue(structureIdx >= 0);
        // Get the estimated point in 3D
        structure.points.get(structureIdx).get(X);
        // Project the point to the camera using found projection matrices
        for (int viewIdx = 0; viewIdx < structure.views.size; viewIdx++) {
            int viewDbIdx = viewIds.indexOf(alg.getPairwiseGraphViewByStructureIndex(viewIdx).id);
            // Project this feature to the camera
            DMatrixRMaj P = structure.views.get(viewIdx).worldToView;
            PerspectiveOps.renderPixel(P, X, found);
            // undo the offset
            found.x += db.intrinsic.cx;
            found.y += db.intrinsic.cy;
            // Lookup the expected pixel location
            // The seed feature ID and the ground truth feature ID are the same
            Point2D_F64 expected = db.featureToObservation(viewDbIdx, truthFeatIdx).pixel;
            assertEquals(0.0, expected.distance(found), reprojectionTol);
        }
    }
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Point4D_F64(georegression.struct.point.Point4D_F64) DogArray_I32(org.ddogleg.struct.DogArray_I32)

Aggregations

SceneStructureProjective (boofcv.abst.geo.bundle.SceneStructureProjective)12 DMatrixRMaj (org.ejml.data.DMatrixRMaj)7 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)6 Test (org.junit.jupiter.api.Test)5 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 Point4D_F64 (georegression.struct.point.Point4D_F64)3 BundleCameraProjective (boofcv.alg.geo.bundle.cameras.BundleCameraProjective)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 DMatrixSparseCSC (org.ejml.data.DMatrixSparseCSC)2 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)1 UtilPoint4D_F64 (georegression.geometry.UtilPoint4D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1