Search in sources :

Example 1 with CompatibleProjectiveHomography

use of boofcv.alg.geo.pose.CompatibleProjectiveHomography in project BoofCV by lessthanoptimal.

the class TestProjectiveInitializeAllCommon method checkCameraMatrices.

/**
 * Check camera matrices directly by computing a matrix which allows direct comparision of the two sets
 */
private void checkCameraMatrices(ProjectiveInitializeAllCommon alg, MockLookupSimilarImagesRealistic db) {
    List<DMatrixRMaj> listA = new ArrayList<>();
    List<DMatrixRMaj> listB = new ArrayList<>();
    // Undo the shift in pixel coordinates
    DMatrixRMaj M = CommonOps_DDRM.identity(3);
    M.set(0, 2, db.intrinsic.cx);
    M.set(1, 2, db.intrinsic.cy);
    List<String> viewIds = BoofMiscOps.collectList(db.views, v -> v.id);
    for (int i = 0; i < 3; i++) {
        View view = alg.getPairwiseGraphViewByStructureIndex(i);
        DMatrixRMaj P = new DMatrixRMaj(3, 4);
        CommonOps_DDRM.mult(M, alg.utils.structure.views.get(i).worldToView, P);
        listA.add(P);
        int viewDbIdx = viewIds.indexOf(view.id);
        listB.add(db.views.get(viewDbIdx).camera);
    }
    DMatrixRMaj H = new DMatrixRMaj(4, 4);
    CompatibleProjectiveHomography compatible = new CompatibleProjectiveHomography();
    assertTrue(compatible.fitCameras(listA, listB, H));
    DMatrixRMaj found = new DMatrixRMaj(3, 4);
    for (int i = 0; i < listA.size(); i++) {
        CommonOps_DDRM.mult(listA.get(i), H, found);
        DMatrixRMaj expected = listB.get(i);
        double scale = expected.get(0, 0) / found.get(0, 0);
        CommonOps_DDRM.scale(scale, found);
        assertTrue(MatrixFeatures_DDRM.isEquals(expected, found, matrixTol));
    }
}
Also used : CompatibleProjectiveHomography(boofcv.alg.geo.pose.CompatibleProjectiveHomography) DMatrixRMaj(org.ejml.data.DMatrixRMaj) ArrayList(java.util.ArrayList) View(boofcv.alg.structure.PairwiseImageGraph.View)

Aggregations

CompatibleProjectiveHomography (boofcv.alg.geo.pose.CompatibleProjectiveHomography)1 View (boofcv.alg.structure.PairwiseImageGraph.View)1 ArrayList (java.util.ArrayList)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1