use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.
the class TestBundleAdjustmentProjectiveSchurJacobian_DDRM method compareToNumerical_Homogenous.
@Test
void compareToNumerical_Homogenous() {
SceneStructureProjective structure = createSceneH(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 TestBundleAdjustmentProjectiveSchurJacobian_DSCC 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_DSCC alg = new BundleAdjustmentProjectiveSchurJacobian_DSCC();
FunctionNtoMxN<DMatrixSparseCSC> jac = new SchurJacobian_to_NtoMxN.DSCC(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 TestCodecSceneStructureProjective method encode_decode.
@Test
void encode_decode() {
SceneStructureProjective original = createScene3D(rand);
CodecSceneStructureProjective codec = new CodecSceneStructureProjective();
int N = original.getUnknownViewCount() * 12 + original.points.size * 3 + original.getUnknownCameraParameterCount();
double[] param = new double[N];
codec.encode(original, param);
SceneStructureProjective found = createScene3D(rand);
codec.decode(param, found);
for (int i = 0; i < original.points.size; i++) {
assertTrue(original.points.data[i].distance(found.points.data[i]) < UtilEjml.TEST_F64);
}
for (int i = 0; i < original.cameras.size; i++) {
SceneStructureCommon.Camera o = original.cameras.data[i];
SceneStructureCommon.Camera f = found.cameras.data[i];
double[] po = new double[o.model.getIntrinsicCount()];
double[] pf = new double[f.model.getIntrinsicCount()];
o.model.getIntrinsic(po, 0);
f.model.getIntrinsic(pf, 0);
assertArrayEquals(po, pf, UtilEjml.TEST_F64);
}
for (int i = 0; i < original.views.size; i++) {
SceneStructureProjective.View o = original.views.data[i];
SceneStructureProjective.View f = found.views.data[i];
assertTrue(MatrixFeatures_DDRM.isIdentical(o.worldToView, f.worldToView, UtilEjml.TEST_F64));
}
}
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, MockLookupSimilarImages db, DogArray_I32 seedConnIdx, int numFeatures, double reprojectionTol) {
final SceneStructureProjective structure = alg.getStructure();
// Sanity check the number of each type of structure
assertEquals(seedConnIdx.size + 1, structure.views.size);
assertEquals(numFeatures, structure.points.size);
alg.inlierIndexes.forEach(list -> assertEquals(numFeatures, list.size));
int dbIndexSeed = db.viewIds.indexOf(alg.getPairwiseGraphViewByStructureIndex(0).id);
// Check results for consistency. Can't do a direct comparison 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();
for (int i = 0; i < numFeatures; i++) {
int seedFeatureIdx = alg.inlierIndexes.get(0).get(i);
int truthFeatIdx = db.viewToFeat.get(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 = db.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
int viewFeatIdx = db.featToView.get(viewDbIdx)[truthFeatIdx];
Point2D_F64 expected = db.viewObs.get(viewDbIdx).get(viewFeatIdx);
assertEquals(0.0, expected.distance(found), reprojectionTol);
}
}
}
use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.
the class TestCodecSceneStructureProjective method createSceneH.
static SceneStructureProjective createSceneH(Random rand) {
SceneStructureProjective out = new SceneStructureProjective(true);
out.initialize(2, 4, 5);
out.setCamera(0, true, new BundleCameraProjective());
// out.setCamera(1,true,new BundleCameraProjective());
out.setCamera(1, false, new CameraPinhole(100, 110, 0.0001, rand.nextGaussian() / 100, rand.nextGaussian() / 100, 1, 1));
for (int i = 0; i < 5; i++) {
double w = rand.nextDouble() * 0.1;
out.setPoint(i, i + 1, i + 2 * rand.nextGaussian(), 2 * i - 3 * rand.nextGaussian(), 0.9 + w);
}
for (int i = 0; i < 4; i++) {
boolean fixed = i % 2 == 0;
DMatrixRMaj P = new DMatrixRMaj(3, 4);
if (fixed) {
for (int j = 0; j < 12; j++) {
P.data[j] = 10.1 + j * 0.2;
}
} else
RandomMatrices_DDRM.fillUniform(P, rand);
out.setView(i, fixed, P, width, height);
out.views.data[i].camera = i / 2;
}
// Assign first point to all views then the other points to just one view
for (int i = 0; i < 4; i++) {
out.points.data[0].views.add(i);
}
for (int i = 1; i < out.points.size; i++) {
out.points.data[i].views.add(i - 1);
}
return out;
}
Aggregations