Search in sources :

Example 26 with SceneObservations

use of boofcv.abst.geo.bundle.SceneObservations 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 27 with SceneObservations

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

the class TestBundleAdjustmentMetricResidualFunction method chainedRelativeViews.

void chainedRelativeViews(boolean homogenous) {
    SceneStructureMetric structure = createScene(rand, homogenous, false, false);
    // Make each view be relative to the previous view
    structure.views.forIdx((i, v) -> v.parent = i > 0 ? structure.views.data[i - 1] : null);
    double[] param = new double[structure.getParameterCount()];
    new CodecSceneStructureMetric().encode(structure, param);
    // Create random observations
    SceneObservations obs = createObservations(rand, structure);
    BundleAdjustmentMetricResidualFunction alg = new BundleAdjustmentMetricResidualFunction();
    alg.configure(structure, obs);
    double[] original = new double[alg.getNumOfOutputsM()];
    double[] found = new double[alg.getNumOfOutputsM()];
    alg.process(param, original);
    // Now change view[1]. This should change residuals in 1,2,3 but not 0
    structure.getParentToView(1).T.x += 0.2;
    structure.getParentToView(1).T.y += 0.2;
    new CodecSceneStructureMetric().encode(structure, param);
    alg.process(param, found);
    // values should not be the same after this index
    int changeAfterIndex = obs.getView(0).size() * 2;
    for (int i = 0; i < found.length; i++) {
        if (i < changeAfterIndex) {
            assertEquals(original[i], found[i], UtilEjml.TEST_F64);
        } else {
            assertNotEquals(original[i], found[i], UtilEjml.TEST_F64);
        }
    }
}
Also used : SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) SceneObservations(boofcv.abst.geo.bundle.SceneObservations)

Example 28 with SceneObservations

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

the class TestBundleAdjustmentMetricResidualFunction method createObservations.

static SceneObservations createObservations(Random rand, SceneStructureMetric structure) {
    SceneObservations obs = new SceneObservations();
    obs.initialize(structure.views.size, structure.hasRigid());
    for (int j = 0; j < structure.points.size; j++) {
        SceneStructureCommon.Point p = structure.points.data[j];
        for (int i = 0; i < p.views.size; i++) {
            SceneObservations.View v = obs.getView(p.views.get(i));
            v.point.add(j);
            v.observations.add(rand.nextInt(300) + 20);
            v.observations.add(rand.nextInt(300) + 20);
        }
    }
    if (structure.hasRigid()) {
        for (int indexRigid = 0; indexRigid < structure.rigids.size; indexRigid++) {
            SceneStructureMetric.Rigid r = structure.rigids.data[indexRigid];
            for (int i = 0; i < r.points.length; i++) {
                SceneStructureCommon.Point p = r.points[i];
                int indexPoint = r.indexFirst + i;
                for (int j = 0; j < p.views.size; j++) {
                    SceneObservations.View v = obs.getViewRigid(p.views.get(j));
                    v.point.add(indexPoint);
                    v.observations.add(rand.nextInt(300) + 20);
                    v.observations.add(rand.nextInt(300) + 20);
                }
            }
        }
    }
    return obs;
}
Also used : SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) SceneStructureCommon(boofcv.abst.geo.bundle.SceneStructureCommon)

Example 29 with SceneObservations

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

the class TestBundleAdjustmentMetricResidualFunction method multipleCalls.

void multipleCalls(boolean homogenous, boolean hasRigid, boolean hasRelative) {
    SceneStructureMetric structure = createScene(rand, homogenous, hasRigid, hasRelative);
    SceneObservations obs = createObservations(rand, structure);
    double[] param = new double[structure.getParameterCount()];
    new CodecSceneStructureMetric().encode(structure, param);
    BundleAdjustmentMetricResidualFunction alg = new BundleAdjustmentMetricResidualFunction();
    alg.configure(structure, obs);
    double[] expected = new double[alg.getNumOfOutputsM()];
    double[] found = new double[alg.getNumOfOutputsM()];
    alg.process(param, expected);
    alg.process(param, found);
    assertArrayEquals(expected, found, UtilEjml.TEST_F64);
}
Also used : SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) SceneObservations(boofcv.abst.geo.bundle.SceneObservations)

Example 30 with SceneObservations

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

the class TestProjectiveInitializeAllCommon method createObservationsForBundleAdjustment.

@Test
void createObservationsForBundleAdjustment() {
    var dbSimilar = new MockLookupSimilarImages(5, 0xDEADBEEF);
    var dbCams = new MockLookUpCameraInfo(dbSimilar.intrinsic);
    PairwiseImageGraph graph = dbSimilar.graph;
    View seed = graph.nodes.get(0);
    // which edges in the first view should be considered
    DogArray_I32 motionIndexes = DogArray_I32.array(0, 2, 3);
    var alg = new ProjectiveInitializeAllCommon();
    alg.utils.dbSimilar = dbSimilar;
    alg.utils.dbCams = dbCams;
    alg.utils.seed = seed;
    // ------------------------------ Initialize internal data structures
    // make every other feature an inlier
    alg.seedToStructure.resize(dbSimilar.feats3D.size());
    alg.seedToStructure.fill(-1);
    DogArray_I32 inlierToSeed = alg.inlierIndexes.grow();
    for (int i = 0; i < dbSimilar.feats3D.size(); i += 2) {
        alg.seedToStructure.data[i] = inlierToSeed.size;
        inlierToSeed.add(i);
    }
    dbSimilar.lookupPixelFeats(seed.id, alg.utils.featsA);
    // Call the function being tested
    // allocate for rest of the views
    alg.inlierIndexes.resize(motionIndexes.size + 1);
    alg.createObservationsForBundleAdjustment(motionIndexes);
    SceneObservations found = alg.utils.observations;
    found.checkOneObservationPerView();
    // Check to see if there's the expected number of views
    assertFalse(found.hasRigid());
    // seed + 3 connected views
    assertEquals(4, found.views.size);
    for (int i = 0; i < 4; i++) {
        SceneObservations.View view = found.views.get(i);
        assertEquals(inlierToSeed.size, view.size());
        for (int j = 0; j < view.size(); j++) {
            // crude sanity check on the index
            assertTrue(view.getPointId(j) < inlierToSeed.size);
        }
    }
// Not doing a detailed check of the values since that will be very complex
}
Also used : SceneObservations(boofcv.abst.geo.bundle.SceneObservations) DogArray_I32(org.ddogleg.struct.DogArray_I32) View(boofcv.alg.structure.PairwiseImageGraph.View) Test(org.junit.jupiter.api.Test)

Aggregations

SceneObservations (boofcv.abst.geo.bundle.SceneObservations)32 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)21 VerbosePrint (org.ddogleg.struct.VerbosePrint)10 SceneStructureProjective (boofcv.abst.geo.bundle.SceneStructureProjective)7 Se3_F64 (georegression.struct.se.Se3_F64)6 Test (org.junit.jupiter.api.Test)6 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)5 Point2D_F64 (georegression.struct.point.Point2D_F64)4 Point3D_F64 (georegression.struct.point.Point3D_F64)4 Point4D_F64 (georegression.struct.point.Point4D_F64)4 DMatrixRMaj (org.ejml.data.DMatrixRMaj)4 CodecSceneStructureMetric (boofcv.alg.geo.bundle.CodecSceneStructureMetric)3 BundlePinholeSimplified (boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)2 TriangulateNViewsMetricH (boofcv.abst.geo.TriangulateNViewsMetricH)2 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)2 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)2 PointIndex2D_F64 (boofcv.struct.geo.PointIndex2D_F64)2 ArrayList (java.util.ArrayList)2