Search in sources :

Example 6 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestRefineMetricWorkingGraph method assignKnown3DToUnassignedObs.

void assignKnown3DToUnassignedObs(boolean shouldReject) {
    var dbSimilar = new MockLookupSimilarImagesRealistic().pathLine(5, 0.3, 1.5, 2);
    var pairwise = dbSimilar.createPairwise();
    var graph = dbSimilar.createWorkingGraph(pairwise);
    var alg = new RefineMetricWorkingGraph() {

        // Override so that it can return an error for which all should be accepted or rejected
        @Override
        double computeReprojectionError(Se3_F64 world_to_view, Point2Transform2_F64 normToPixels, Point2D_F64 pixelObs, Point4D_F64 world3D) {
            // this is also a sanity check on the used error being squared
            double error = maxReprojectionErrorPixel * maxReprojectionErrorPixel;
            return error + (shouldReject ? 0.001 : -0.001);
        }
    };
    alg.maxReprojectionErrorPixel = 10;
    alg.initializeDataStructures(dbSimilar, graph);
    alg.metricSba.structure.points.resize(20);
    // create an inlier set composed of observations from 3 views
    var inliers = new SceneWorkingGraph.InlierInfo();
    for (int viewIdx : new int[] { 1, 2, 3 }) {
        inliers.views.add(pairwise.nodes.get(viewIdx));
        inliers.observations.grow().setTo(DogArray_I32.array(1, 2, 3, 5, 6));
    }
    // Specific which of the observations in the inlier set are currently unassigned
    var unassignedOrig = DogArray_I32.array(0, 2);
    alg.unassigned.setTo(unassignedOrig);
    // There is only one 3D feature they can be matched with
    alg.featureIdx3D.add(3);
    // this is the inlier set that's going to be inspected
    int inlierFeatIdx = 4;
    alg.initLookUpTablesForInlierSet(graph, inliers.views);
    alg.assignKnown3DToUnassignedObs(graph, inliers, inlierFeatIdx);
    // it keeps tracks of what was actually assigned by removing it
    assertEquals(shouldReject ? unassignedOrig.size : 0, alg.unassigned.size);
    BoofMiscOps.forIdx(graph.listViews, (i, v) -> {
        // See if the observation were added to the inliers and nothing changed for others
        boolean isInlier = inliers.views.contains(v.pview);
        int inlierViewIdx = inliers.views.indexOf(v.pview);
        boolean shouldBeAssigned = !shouldReject && isInlier && unassignedOrig.contains(inlierViewIdx);
        if (shouldBeAssigned) {
            // Make sure the point in the inlier set which is being inspected was assigned a value
            int pointID = inliers.observations.get(inlierViewIdx).get(inlierFeatIdx);
            DogArray_I32 point = alg.metricSba.observations.views.get(i).point;
            assertEquals(3, point.get(pointID));
            // Set it to -1 make the next test easier since everything should now be -1
            point.set(pointID, -1);
        }
        alg.metricSba.observations.views.get(i).point.forIdx((j, value) -> assertEquals(-1, value));
    });
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) Point4D_F64(georegression.struct.point.Point4D_F64) DogArray_I32(org.ddogleg.struct.DogArray_I32) Se3_F64(georegression.struct.se.Se3_F64)

Example 7 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestSelectNeighborsAroundView method createInliers.

private void createInliers(SceneWorkingGraph.View v, int idx0, int idx1, SceneWorkingGraph working) {
    // put ever view into this inlier set, except for 10. For that it will need to go outside
    for (int i = idx0; i <= idx1; i++) {
        PairwiseImageGraph.View pv = working.listViews.get(i).pview;
        SceneWorkingGraph.InlierInfo inlier = v.inliers.isEmpty() ? v.inliers.grow() : v.inliers.get(0);
        inlier.views.add(pv);
        DogArray_I32 obs = inlier.observations.grow();
        for (int j = 0; j < 5 + i; j++) {
            obs.add(j);
        }
    }
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32)

Example 8 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestEstimateViewSelfCalibrate method computeCalibratingHomography.

/**
 * Check the calibrating homography computation by feeding it noise three data from 3 views
 */
@Test
void computeCalibratingHomography() {
    var db = new MockLookupSimilarImagesRealistic().setIntrinsic(new CameraPinhole(400, 400, 0, 0, 0, 800, 800)).pathLine(5, 0.3, 1.5, 2);
    PairwiseImageGraph pairwise = db.createPairwise();
    var alg = new EstimateViewSelfCalibrate();
    alg.workGraph = db.createWorkingGraph(pairwise);
    alg.pairwiseUtils = new PairwiseGraphUtils();
    alg.pairwiseUtils.seed = pairwise.nodes.get(0);
    alg.pairwiseUtils.viewB = pairwise.nodes.get(1);
    alg.pairwiseUtils.viewC = pairwise.nodes.get(2);
    int[] viewIdx = new int[] { 1, 0, 2 };
    // P1 might not be identity
    DMatrixRMaj P1 = db.views.get(viewIdx[0]).camera;
    alg.pairwiseUtils.P2.setTo(db.views.get(viewIdx[1]).camera);
    alg.pairwiseUtils.P3.setTo(db.views.get(viewIdx[2]).camera);
    // make sure P1 is identity, which is what it would be coming out of the trifocal tensor
    List<DMatrixRMaj> cameras = BoofMiscOps.asList(P1.copy(), alg.pairwiseUtils.P2, alg.pairwiseUtils.P3);
    MultiViewOps.projectiveMakeFirstIdentity(cameras, null);
    // Create the pixel observations
    db.createTripleObs(viewIdx, alg.pairwiseUtils.matchesTriple, new DogArray_I32());
    // Compute the homography
    assertTrue(alg.computeCalibratingHomography());
    // Test it by seeing it it returns the expected camera matrix
    DMatrixRMaj H = alg.projectiveHomography.getCalibrationHomography();
    DMatrixRMaj foundK = new DMatrixRMaj(3, 3);
    Se3_F64 view_0_to_2 = new Se3_F64();
    MultiViewOps.projectiveToMetric(alg.pairwiseUtils.P3, H, view_0_to_2, foundK);
    assertEquals(db.intrinsic.fx, foundK.get(0, 0), 1e-7);
    assertEquals(db.intrinsic.fy, foundK.get(1, 1), 1e-7);
    assertEquals(db.intrinsic.cx, foundK.get(0, 2), 1e-7);
    assertEquals(db.intrinsic.cy, foundK.get(1, 2), 1e-7);
    assertEquals(db.intrinsic.skew, foundK.get(0, 1), 1e-7);
}
Also used : MockLookupSimilarImagesRealistic(boofcv.alg.structure.MockLookupSimilarImagesRealistic) DMatrixRMaj(org.ejml.data.DMatrixRMaj) PairwiseGraphUtils(boofcv.alg.structure.PairwiseGraphUtils) PairwiseImageGraph(boofcv.alg.structure.PairwiseImageGraph) DogArray_I32(org.ddogleg.struct.DogArray_I32) CameraPinhole(boofcv.struct.calib.CameraPinhole) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 9 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestProjectiveInitializeAllCommon method createStructureLookUpTables.

@Test
void createStructureLookUpTables() {
    int offset = 5;
    var db = new MockLookupSimilarImages(4, 0xDEADBEEF);
    var alg = new ProjectiveInitializeAllCommon();
    alg.utils.ransac = new MockRansac(offset, db.feats3D.size() - offset);
    alg.utils.dbSimilar = db;
    alg.utils.P1.setTo(db.listCameraMatrices.get(0));
    alg.utils.P2.setTo(db.listCameraMatrices.get(1));
    alg.utils.P3.setTo(db.listCameraMatrices.get(3));
    alg.utils.commonIdx.setTo(DogArray_I32.range(0, db.feats3D.size()));
    // order shouldn't mattter
    PrimitiveArrays.shuffle(alg.utils.commonIdx.data, 0, alg.utils.commonIdx.size, rand);
    View seed = db.graph.nodes.get(0);
    alg.inlierIndexes.resize(3);
    alg.createStructureLookUpTables(seed);
    // Check to see if inlier indexes are correct
    int numInliers = db.feats3D.size() - offset;
    DogArray_I32 inlierToSeed = alg.inlierIndexes.get(0);
    assertEquals(numInliers, inlierToSeed.size);
    for (int i = 0; i < numInliers; i++) {
        assertEquals(alg.utils.commonIdx.get(i + offset), inlierToSeed.get(i));
    }
    // mapping from seed features to structure features
    for (int i = 0; i < db.feats3D.size(); i++) {
        assertEquals(i < offset ? -1 : i - offset, alg.seedToStructure.get(alg.utils.commonIdx.get(i)));
    }
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32) View(boofcv.alg.structure.PairwiseImageGraph.View) Test(org.junit.jupiter.api.Test)

Example 10 with DogArray_I32

use of org.ddogleg.struct.DogArray_I32 in project BoofCV by lessthanoptimal.

the class TestProjectiveInitializeAllCommon method checkConfiguration.

private void checkConfiguration(ProjectiveInitializeAllCommon alg, MockLookupSimilarImages dbSimilar, MockLookUpCameraInfo dbCams, boolean threeViews, boolean sba, boolean scale, double reprojectionTol) {
    alg.utils.configConvergeSBA.maxIterations = sba ? 50 : -1;
    alg.utils.configScaleSBA = scale;
    View seed = dbSimilar.graph.nodes.get(0);
    var seedFeatsIdx = new DogArray_I32();
    var seedConnIdx = threeViews ? DogArray_I32.array(0, 2) : DogArray_I32.array(1, 2, 3);
    // Give a subset as a test to see if the size is being properly pass down the chain
    int offset = 0;
    int numFeatures = dbSimilar.feats3D.size() - offset;
    for (int i = offset; i < numFeatures; i++) {
        seedFeatsIdx.add(i);
    }
    // order should not matter
    PrimitiveArrays.shuffle(seedFeatsIdx.data, 0, seedFeatsIdx.size, rand);
    // Reconstruct the projective scene
    assertTrue(alg.projectiveSceneN(dbSimilar, dbCams, seed, seedFeatsIdx, seedConnIdx));
    // test results
    checkReconstruction(alg, dbSimilar, seedConnIdx, numFeatures, reprojectionTol);
}
Also used : DogArray_I32(org.ddogleg.struct.DogArray_I32) View(boofcv.alg.structure.PairwiseImageGraph.View)

Aggregations

DogArray_I32 (org.ddogleg.struct.DogArray_I32)192 Test (org.junit.jupiter.api.Test)73 Point2D_I32 (georegression.struct.point.Point2D_I32)24 ArrayList (java.util.ArrayList)21 Point2D_F64 (georegression.struct.point.Point2D_F64)17 DogArray (org.ddogleg.struct.DogArray)17 TupleDesc_F64 (boofcv.struct.feature.TupleDesc_F64)15 GrayS32 (boofcv.struct.image.GrayS32)10 VerbosePrint (org.ddogleg.struct.VerbosePrint)7 View (boofcv.alg.structure.PairwiseImageGraph.View)6 AssociatedIndex (boofcv.struct.feature.AssociatedIndex)6 GrayI (boofcv.struct.image.GrayI)5 Point3D_F64 (georegression.struct.point.Point3D_F64)5 GrowArray (pabeles.concurrency.GrowArray)5 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)4 BTrack (boofcv.alg.sfm.d3.structure.VisOdomBundleAdjustment.BTrack)4 AssociatedTripleIndex (boofcv.struct.feature.AssociatedTripleIndex)4 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)3 SceneWorkingGraph (boofcv.alg.structure.SceneWorkingGraph)3 ConfigAssociateGreedy (boofcv.factory.feature.associate.ConfigAssociateGreedy)3