use of boofcv.abst.geo.bundle.SceneStructureProjective 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));
}
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, MockLookupSimilarImagesRealistic db, DogArray_I32 seedConnIdx, double reprojectionTol) {
final SceneStructureProjective structure = alg.getStructure();
// Sanity check the number of each type of structure
assertEquals(seedConnIdx.size + 1, structure.views.size);
List<String> viewIds = BoofMiscOps.collectList(db.views, v -> v.id);
int dbIndexSeed = viewIds.indexOf(alg.getPairwiseGraphViewByStructureIndex(0).id);
// Check results for consistency. Can't do a direct comparision 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();
DogArray_I32 inlierToSeed = alg.inlierIndexes.get(0);
for (int i = 0; i < inlierToSeed.size; i++) {
int seedFeatureIdx = inlierToSeed.get(i);
int truthFeatIdx = db.observationToFeatureIdx(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 = 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
Point2D_F64 expected = db.featureToObservation(viewDbIdx, truthFeatIdx).pixel;
assertEquals(0.0, expected.distance(found), reprojectionTol);
}
}
}
Aggregations