use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.
the class TestBundleAdjustmentProjectiveResidualFunction method multipleCalls.
void multipleCalls(boolean homogenous) {
SceneStructureProjective structure = homogenous ? createSceneH(rand) : createScene3D(rand);
SceneObservations obs = createObservations(rand, structure);
double[] param = new double[structure.getParameterCount()];
new CodecSceneStructureProjective().encode(structure, param);
BundleAdjustmentProjectiveResidualFunction alg = new BundleAdjustmentProjectiveResidualFunction();
alg.configure(structure, obs);
double[] expected = new double[alg.getNumOfOutputsM()];
double[] found = new double[alg.getNumOfOutputsM()];
alg.process(param, expected);
alg.process(param, found);
assertArrayEquals(expected, found, UtilEjml.TEST_F64);
}
use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.
the class TestBundleAdjustmentProjectiveSchurJacobian_DSCC 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_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 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;
}
use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.
the class TestCodecSceneStructureProjective method createScene3D.
static SceneStructureProjective createScene3D(Random rand) {
SceneStructureProjective out = new SceneStructureProjective(false);
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++) {
out.setPoint(i, i + 1, i + 2 * rand.nextGaussian(), 2 * i - 3 * rand.nextGaussian());
}
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] = 0.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;
}
use of boofcv.abst.geo.bundle.SceneStructureProjective in project BoofCV by lessthanoptimal.
the class TestPruneStructureFromSceneProjective method createPerfectScene.
private void createPerfectScene() {
structure = new SceneStructureProjective(true);
structure.initialize(10, 500);
CameraPinhole intrinsic = new CameraPinhole(400, 410, 0.1, 500, 501, 1000, 1000);
DMatrixRMaj K = PerspectiveOps.pinholeToMatrix(intrinsic, (DMatrixRMaj) null);
for (int viewIdx = 0; viewIdx < structure.views.size; viewIdx++) {
Se3_F64 worldToView = new Se3_F64();
if (viewIdx > 0) {
worldToView.T.x = rand.nextGaussian() * 0.5;
worldToView.T.y = rand.nextGaussian() * 0.5;
worldToView.T.z = rand.nextGaussian() * 0.05;
// increased rotation variance until a few of the points weren't always visible
ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, rand.nextGaussian() * 0.5, rand.nextGaussian() * 0.1, rand.nextGaussian() * 0.1, worldToView.R);
}
DMatrixRMaj cameraMatrix = PerspectiveOps.createCameraMatrix(worldToView.R, worldToView.T, K, null);
structure.setView(viewIdx, viewIdx == 0, cameraMatrix, intrinsic.width, intrinsic.height);
}
List<Point4D_F64> points = UtilPoint4D_F64.randomN(center, 1.0, 0.5, structure.points.size, rand);
for (int i = 0; i < points.size(); i++) {
Point4D_F64 p = points.get(i);
double s = rand.nextGaussian();
if (// make sure it isn't scaled by zero
Math.abs(s) < 1e-5)
s = rand.nextDouble() + 0.01;
p.scale(s);
structure.points.data[i].set(p.x, p.y, p.z, p.w);
}
createRestOfScene();
}
Aggregations