Search in sources :

Example 1 with SceneStructureProjective

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

the class TestBundleAdjustmentProjectiveSchurJacobian_DDRM method compareToNumerical_Homogenous.

@Test
void compareToNumerical_Homogenous() {
    SceneStructureProjective structure = createSceneH(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 2 with SceneStructureProjective

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

the class TestBundleAdjustmentProjectiveSchurJacobian_DSCC 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_DSCC alg = new BundleAdjustmentProjectiveSchurJacobian_DSCC();
    FunctionNtoMxN<DMatrixSparseCSC> jac = new SchurJacobian_to_NtoMxN.DSCC(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) DMatrixSparseCSC(org.ejml.data.DMatrixSparseCSC) Test(org.junit.jupiter.api.Test)

Example 3 with SceneStructureProjective

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

the class TestCodecSceneStructureProjective method encode_decode.

@Test
void encode_decode() {
    SceneStructureProjective original = createScene3D(rand);
    CodecSceneStructureProjective codec = new CodecSceneStructureProjective();
    int N = original.getUnknownViewCount() * 12 + original.points.size * 3 + original.getUnknownCameraParameterCount();
    double[] param = new double[N];
    codec.encode(original, param);
    SceneStructureProjective found = createScene3D(rand);
    codec.decode(param, found);
    for (int i = 0; i < original.points.size; i++) {
        assertTrue(original.points.data[i].distance(found.points.data[i]) < UtilEjml.TEST_F64);
    }
    for (int i = 0; i < original.cameras.size; i++) {
        SceneStructureCommon.Camera o = original.cameras.data[i];
        SceneStructureCommon.Camera f = found.cameras.data[i];
        double[] po = new double[o.model.getIntrinsicCount()];
        double[] pf = new double[f.model.getIntrinsicCount()];
        o.model.getIntrinsic(po, 0);
        f.model.getIntrinsic(pf, 0);
        assertArrayEquals(po, pf, UtilEjml.TEST_F64);
    }
    for (int i = 0; i < original.views.size; i++) {
        SceneStructureProjective.View o = original.views.data[i];
        SceneStructureProjective.View f = found.views.data[i];
        assertTrue(MatrixFeatures_DDRM.isIdentical(o.worldToView, f.worldToView, UtilEjml.TEST_F64));
    }
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) SceneStructureCommon(boofcv.abst.geo.bundle.SceneStructureCommon) Test(org.junit.jupiter.api.Test)

Example 4 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, MockLookupSimilarImages db, DogArray_I32 seedConnIdx, int numFeatures, double reprojectionTol) {
    final SceneStructureProjective structure = alg.getStructure();
    // Sanity check the number of each type of structure
    assertEquals(seedConnIdx.size + 1, structure.views.size);
    assertEquals(numFeatures, structure.points.size);
    alg.inlierIndexes.forEach(list -> assertEquals(numFeatures, list.size));
    int dbIndexSeed = db.viewIds.indexOf(alg.getPairwiseGraphViewByStructureIndex(0).id);
    // Check results for consistency. Can't do a direct comparison 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();
    for (int i = 0; i < numFeatures; i++) {
        int seedFeatureIdx = alg.inlierIndexes.get(0).get(i);
        int truthFeatIdx = db.viewToFeat.get(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 = db.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
            int viewFeatIdx = db.featToView.get(viewDbIdx)[truthFeatIdx];
            Point2D_F64 expected = db.viewObs.get(viewDbIdx).get(viewFeatIdx);
            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)

Example 5 with SceneStructureProjective

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

the class TestCodecSceneStructureProjective method createSceneH.

static SceneStructureProjective createSceneH(Random rand) {
    SceneStructureProjective out = new SceneStructureProjective(true);
    out.initialize(2, 4, 5);
    out.setCamera(0, true, new BundleCameraProjective());
    // out.setCamera(1,true,new BundleCameraProjective());
    out.setCamera(1, false, new CameraPinhole(100, 110, 0.0001, rand.nextGaussian() / 100, rand.nextGaussian() / 100, 1, 1));
    for (int i = 0; i < 5; i++) {
        double w = rand.nextDouble() * 0.1;
        out.setPoint(i, i + 1, i + 2 * rand.nextGaussian(), 2 * i - 3 * rand.nextGaussian(), 0.9 + w);
    }
    for (int i = 0; i < 4; i++) {
        boolean fixed = i % 2 == 0;
        DMatrixRMaj P = new DMatrixRMaj(3, 4);
        if (fixed) {
            for (int j = 0; j < 12; j++) {
                P.data[j] = 10.1 + j * 0.2;
            }
        } else
            RandomMatrices_DDRM.fillUniform(P, rand);
        out.setView(i, fixed, P, width, height);
        out.views.data[i].camera = i / 2;
    }
    // Assign first point to all views then the other points to just one view
    for (int i = 0; i < 4; i++) {
        out.points.data[0].views.add(i);
    }
    for (int i = 1; i < out.points.size; i++) {
        out.points.data[i].views.add(i - 1);
    }
    return out;
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) BundleCameraProjective(boofcv.alg.geo.bundle.cameras.BundleCameraProjective) DMatrixRMaj(org.ejml.data.DMatrixRMaj) CameraPinhole(boofcv.struct.calib.CameraPinhole)

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