Search in sources :

Example 1 with ElevateViewInfo

use of boofcv.struct.calib.ElevateViewInfo in project BoofCV by lessthanoptimal.

the class CommonGenerateMetricCameraTripleChecks method checkScene.

private void checkScene() {
    ModelGeneratorViews<MetricCameraTriple, AssociatedTriple, ElevateViewInfo> alg = createGenerator();
    assertEquals(3, alg.getNumberOfViews());
    for (int i = 0; i < 3; i++) {
        alg.setView(i, new ElevateViewInfo(800, 600, i));
    }
    assertTrue(alg.getMinimumPoints() > 0);
    var found = new MetricCameraTriple();
    List<AssociatedTriple> selected = new ArrayList<>();
    DogArray_I32 indexes = DogArray_I32.range(0, numFeatures);
    int countSuccess = 0;
    for (int trial = 0; trial < totalTrials; trial++) {
        // Randomly select different points each trial
        PrimitiveArrays.shuffle(indexes.data, 0, numFeatures, rand);
        selected.clear();
        for (int i = 0; i < alg.getMinimumPoints() + extraObservations; i++) {
            selected.add(observations3.get(indexes.get(i)));
        }
        // Compute the model
        if (!alg.generate(selected, found)) {
            continue;
        }
        countSuccess++;
        // System.out.println("Trial = "+trial);
        // Check results
        checkEquals(cameraA, found.view1);
        checkEquals(cameraB, found.view2);
        checkEquals(cameraC, found.view3);
        BoofTesting.assertEqualsToScaleS(truthView_1_to_i(1), found.view_1_to_2, 1e-2, 1e-3);
        BoofTesting.assertEqualsToScaleS(truthView_1_to_i(2), found.view_1_to_3, 1e-2, 1e-3);
    }
    // System.out.println("Passed "+countSuccess+" / "+totalTrials);
    assertTrue(minimumFractionSuccess * totalTrials <= countSuccess, "Failed " + (totalTrials - countSuccess) + " min " + (minimumFractionSuccess * totalTrials - countSuccess));
}
Also used : MetricCameraTriple(boofcv.alg.geo.selfcalib.MetricCameraTriple) AssociatedTriple(boofcv.struct.geo.AssociatedTriple) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) ElevateViewInfo(boofcv.struct.calib.ElevateViewInfo)

Example 2 with ElevateViewInfo

use of boofcv.struct.calib.ElevateViewInfo in project BoofCV by lessthanoptimal.

the class CommonProjectiveToMetricCamerasChecks method checkScene.

/**
 * @param singleCamera if true then the algorithm will be told all views come from one camera
 */
private void checkScene(boolean singleCamera) {
    ProjectiveToMetricCameras alg = createEstimator(singleCamera);
    assertTrue(alg.getMinimumViews() >= 1);
    assertTrue(alg.getMinimumViews() <= 3);
    List<ElevateViewInfo> views = new ArrayList<>();
    for (int i = 0; i < 3; i++) {
        int cameraIdx = singleCamera ? 0 : i;
        views.add(new ElevateViewInfo(imageWidth, imageHeight, cameraIdx));
    }
    List<DMatrixRMaj> inputCameras = new ArrayList<>();
    inputCameras.add(P2);
    inputCameras.add(P3);
    MetricCameras results = new MetricCameras();
    // Compute the model
    assertTrue(alg.process(views, inputCameras, observationsN, results));
    assertEquals(2, results.motion_1_to_k.size);
    assertEquals(3, results.intrinsics.size);
    // Check results
    checkEquals(cameraA, results.intrinsics.get(0));
    checkEquals(cameraB, results.intrinsics.get(1));
    checkEquals(cameraC, results.intrinsics.get(2));
    BoofTesting.assertEqualsToScaleS(truthView_1_to_i(1), results.motion_1_to_k.get(0), rotationTol, translationTol);
    BoofTesting.assertEqualsToScaleS(truthView_1_to_i(2), results.motion_1_to_k.get(1), rotationTol, translationTol);
    // The largest translation should be close to 1.0
    double largestTranslation = 0;
    for (Se3_F64 m : results.motion_1_to_k.toList()) {
        largestTranslation = Math.max(largestTranslation, m.T.norm());
    }
    assertEquals(1.0, largestTranslation, 0.001);
}
Also used : ArrayList(java.util.ArrayList) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ElevateViewInfo(boofcv.struct.calib.ElevateViewInfo) MetricCameras(boofcv.alg.geo.MetricCameras) Se3_F64(georegression.struct.se.Se3_F64)

Example 3 with ElevateViewInfo

use of boofcv.struct.calib.ElevateViewInfo in project BoofCV by lessthanoptimal.

the class CommonProjectiveToMetricCamerasChecks method unexpected_number_of_dimensions.

/**
 * Incorrect number of input dimensions
 */
@Test
void unexpected_number_of_dimensions() {
    standardScene();
    simulateScene(0);
    List<ElevateViewInfo> views = new ArrayList<>();
    List<DMatrixRMaj> inputCameras = new ArrayList<>();
    for (int i = 0; i < 2; i++) {
        views.add(new ElevateViewInfo(imageWidth, imageHeight, i));
    }
    inputCameras.add(P2);
    inputCameras.add(P3);
    ProjectiveToMetricCameras alg = createEstimator(false);
    assertThrows(RuntimeException.class, () -> alg.process(views, inputCameras, observationsN, new MetricCameras()));
}
Also used : ArrayList(java.util.ArrayList) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ElevateViewInfo(boofcv.struct.calib.ElevateViewInfo) MetricCameras(boofcv.alg.geo.MetricCameras) Test(org.junit.jupiter.api.Test)

Example 4 with ElevateViewInfo

use of boofcv.struct.calib.ElevateViewInfo in project BoofCV by lessthanoptimal.

the class TestProjectiveToMetricCameraDualQuadratic method averageCommonCameras.

/**
 * Have some cameras be duplicated and others not. See if it averages correctly
 */
@Test
void averageCommonCameras() {
    List<ElevateViewInfo> views = new ArrayList<>();
    views.add(new ElevateViewInfo(300, 400, 1));
    views.add(new ElevateViewInfo(300, 400, 0));
    views.add(new ElevateViewInfo(300, 400, 0));
    views.add(new ElevateViewInfo(300, 400, 2));
    var solutions = new FastArray<>(Intrinsic.class);
    for (int i = 0; i < 4; i++) {
        Intrinsic cam = new Intrinsic();
        cam.fx = 100 + i;
        cam.fy = 200 + i;
        cam.skew = 400 + i;
        solutions.add(cam);
    }
    var selfcalib = new SelfCalibrationLinearDualQuadratic(1.0);
    var alg = new ProjectiveToMetricCameraDualQuadratic(selfcalib);
    // process
    alg.averageCommonCameras(views, solutions, 3);
    // check results
    assertEquals(3, alg.cameraCounts.size);
    assertEquals(3, alg.workCameras.size);
    // see if it counted the cameras correctly
    assertEquals(2, alg.cameraCounts.get(0));
    assertEquals(1, alg.cameraCounts.get(1));
    assertEquals(1, alg.cameraCounts.get(2));
    // See if the values are as epected
    CameraPinhole cam0 = alg.workCameras.get(0);
    CameraPinhole cam1 = alg.workCameras.get(1);
    CameraPinhole cam2 = alg.workCameras.get(2);
    assertEquals(101.5, cam0.fx, UtilEjml.TEST_F64);
    assertEquals(201.5, cam0.fy, UtilEjml.TEST_F64);
    assertEquals(401.5, cam0.skew, UtilEjml.TEST_F64);
    assertEquals(100, cam1.fx, UtilEjml.TEST_F64);
    assertEquals(200, cam1.fy, UtilEjml.TEST_F64);
    assertEquals(400, cam1.skew, UtilEjml.TEST_F64);
    assertEquals(103, cam2.fx, UtilEjml.TEST_F64);
    assertEquals(203, cam2.fy, UtilEjml.TEST_F64);
    assertEquals(403, cam2.skew, UtilEjml.TEST_F64);
}
Also used : SelfCalibrationLinearDualQuadratic(boofcv.alg.geo.selfcalib.SelfCalibrationLinearDualQuadratic) ArrayList(java.util.ArrayList) FastArray(org.ddogleg.struct.FastArray) CameraPinhole(boofcv.struct.calib.CameraPinhole) ElevateViewInfo(boofcv.struct.calib.ElevateViewInfo) Intrinsic(boofcv.alg.geo.selfcalib.SelfCalibrationLinearDualQuadratic.Intrinsic) Test(org.junit.jupiter.api.Test)

Example 5 with ElevateViewInfo

use of boofcv.struct.calib.ElevateViewInfo in project BoofCV by lessthanoptimal.

the class TestProjectiveInitializeAllCommon method lookupInfoForMetricElevation.

/**
 * Looks up features then tests using triangulation and checks for perfect results.
 */
@Test
void lookupInfoForMetricElevation() {
    int numViews = 4;
    var dbSimilar = new MockLookupSimilarImages(numViews, 0xDEADBEEF);
    var dbCams = new MockLookUpCameraInfo(800, 800);
    var alg = new ProjectiveInitializeAllCommon();
    alg.utils.dbSimilar = dbSimilar;
    alg.utils.dbCams = dbCams;
    // sanity check that all features are visible in all views. Requirement of metric escalation
    for (int i = 0; i < dbSimilar.viewIds.size(); i++) {
        assertEquals(dbSimilar.numFeatures, dbSimilar.viewObs.get(i).size());
    }
    // dividing number of features by two because only even observations are inliers
    alg.utils.structure.initialize(numViews, dbSimilar.numFeatures / 2);
    alg.utils.observations.initialize(numViews);
    // Transform that makes view[0] identity
    DMatrixRMaj H = new DMatrixRMaj(4, 4);
    MultiViewOps.projectiveToIdentityH(dbSimilar.listCameraMatrices.get(0), H);
    // construct projective SBA scene from metric ground truth
    for (int viewIdx = 0; viewIdx < dbSimilar.viewIds.size(); viewIdx++) {
        DMatrixRMaj P = new DMatrixRMaj(3, 4);
        CommonOps_DDRM.mult(dbSimilar.listCameraMatrices.get(viewIdx), H, P);
        alg.viewsByStructureIndex.add(dbSimilar.graph.nodes.get(viewIdx));
        alg.utils.structure.views.get(viewIdx).worldToView.setTo(P);
        alg.utils.structure.views.get(viewIdx).width = viewIdx;
        // only features with an even ID will be inliers
        DogArray_I32 inliers = alg.inlierIndexes.grow();
        int[] featureIDs = dbSimilar.viewToFeat.get(viewIdx);
        SceneObservations.View oview = alg.utils.observations.views.get(viewIdx);
        for (int obsIdx = 0; obsIdx < featureIDs.length; obsIdx++) {
            int featureID = featureIDs[obsIdx];
            if (featureID % 2 == 1)
                continue;
            inliers.add(oview.size());
            Point2D_F64 pixel = dbSimilar.viewObs.get(viewIdx).get(obsIdx);
            oview.add(featureID / 2, (float) pixel.x, (float) pixel.y);
        }
    }
    // Call the function we are testing
    List<String> viewIds = new ArrayList<>();
    DogArray<ElevateViewInfo> views = new DogArray<>(ElevateViewInfo::new);
    DogArray<DMatrixRMaj> cameraMatrices = new DogArray<>(() -> new DMatrixRMaj(3, 4));
    DogArray<AssociatedTupleDN> observations = new DogArray<>(AssociatedTupleDN::new);
    alg.lookupInfoForMetricElevation(viewIds, views, cameraMatrices, observations);
    // check what can be checked trivially by comparing to the db
    assertEquals(4, viewIds.size());
    assertEquals(4, views.size());
    assertEquals(3, cameraMatrices.size());
    assertEquals(dbSimilar.numFeatures / 2, observations.size());
    for (int viewIdx = 0; viewIdx < 4; viewIdx++) {
        assertEquals(dbSimilar.viewIds.get(viewIdx), viewIds.get(viewIdx));
        assertEquals(viewIdx, views.get(viewIdx).shape.width);
        // only one camera
        assertEquals(0, views.get(viewIdx).cameraID);
    }
    // See if it unscrambled the observations
    for (int obsIdx = 0; obsIdx < dbSimilar.numFeatures / 2; obsIdx++) {
        for (int viewIdx = 0; viewIdx < 4; viewIdx++) {
            Point2D_F64 expected = dbSimilar.viewObs.get(viewIdx).get(dbSimilar.featToView.get(viewIdx)[obsIdx * 2]);
            Point2D_F64 found = observations.get(obsIdx).get(viewIdx);
            assertEquals(0.0, expected.distance(found), UtilEjml.TEST_F32);
        }
    }
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) ArrayList(java.util.ArrayList) DogArray_I32(org.ddogleg.struct.DogArray_I32) DogArray(org.ddogleg.struct.DogArray) AssociatedTupleDN(boofcv.struct.geo.AssociatedTupleDN) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) Point2D_F64(georegression.struct.point.Point2D_F64) ElevateViewInfo(boofcv.struct.calib.ElevateViewInfo) Test(org.junit.jupiter.api.Test)

Aggregations

ElevateViewInfo (boofcv.struct.calib.ElevateViewInfo)10 ArrayList (java.util.ArrayList)8 DMatrixRMaj (org.ejml.data.DMatrixRMaj)6 MetricCameras (boofcv.alg.geo.MetricCameras)5 Test (org.junit.jupiter.api.Test)5 CameraPinhole (boofcv.struct.calib.CameraPinhole)4 DogArray (org.ddogleg.struct.DogArray)3 VerbosePrint (org.ddogleg.struct.VerbosePrint)3 SelfCalibrationLinearDualQuadratic (boofcv.alg.geo.selfcalib.SelfCalibrationLinearDualQuadratic)2 Se3_F64 (georegression.struct.se.Se3_F64)2 DogArray_I32 (org.ddogleg.struct.DogArray_I32)2 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)1 ProjectiveToMetricCameras (boofcv.abst.geo.selfcalib.ProjectiveToMetricCameras)1 MetricCameraTriple (boofcv.alg.geo.selfcalib.MetricCameraTriple)1 CameraState (boofcv.alg.geo.selfcalib.RefineDualQuadraticAlgebraicError.CameraState)1 ResolveSignAmbiguityPositiveDepth (boofcv.alg.geo.selfcalib.ResolveSignAmbiguityPositiveDepth)1 Intrinsic (boofcv.alg.geo.selfcalib.SelfCalibrationLinearDualQuadratic.Intrinsic)1 TwoViewToCalibratingHomography (boofcv.alg.geo.selfcalib.TwoViewToCalibratingHomography)1 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)1 AssociatedTuple (boofcv.struct.geo.AssociatedTuple)1