use of boofcv.abst.geo.bundle.SceneObservations in project BoofCV by lessthanoptimal.
the class TestMultiViewOps method triangulatePoints.
/**
* Construct a scene with perfect observations. See if triangulation returns the same points
*/
@Test
void triangulatePoints() {
CameraPinhole intrinsic = new CameraPinhole(500, 500, 0, 500, 500, 1000, 1000);
List<Point3D_F64> points = UtilPoint3D_F64.random(new Point3D_F64(0, 0, 2), -0.5, 0.5, 100, rand);
Se3_F64 view0_to_view1 = SpecialEuclideanOps_F64.eulerXyz(0.3, 0, 0, 0.1, -0.1, 0, null);
SceneStructureMetric structure = new SceneStructureMetric(false);
SceneObservations observations = new SceneObservations();
observations.initialize(2);
structure.initialize(1, 2, points.size());
structure.setCamera(0, true, intrinsic);
structure.setView(0, 0, true, new Se3_F64());
structure.setView(1, 0, false, view0_to_view1);
SceneObservations.View v0 = observations.getView(0);
SceneObservations.View v1 = observations.getView(1);
for (int i = 0; i < points.size(); i++) {
Point3D_F64 X = points.get(i);
Point2D_F64 p0 = PerspectiveOps.renderPixel(intrinsic, X, null);
Point2D_F64 p1 = PerspectiveOps.renderPixel(view0_to_view1, intrinsic, X, null);
v0.add(i, (float) p0.x, (float) p0.y);
v1.add(i, (float) p1.x, (float) p1.y);
structure.connectPointToView(i, 0);
structure.connectPointToView(i, 1);
}
MultiViewOps.triangulatePoints(structure, observations);
Point3D_F64 X = new Point3D_F64();
for (int i = 0; i < points.size(); i++) {
structure.getPoints().get(i).get(X);
assertEquals(0, points.get(i).distance(X), UtilEjml.TEST_F64_SQ);
}
}
use of boofcv.abst.geo.bundle.SceneObservations in project BoofCV by lessthanoptimal.
the class TestBundleAdjustmentMetricResidualFunction method changeInParamChangesOutput.
void changeInParamChangesOutput(boolean homogenous) {
SceneStructureMetric structure = createScene(rand, homogenous, false, false);
double[] param = new double[structure.getParameterCount()];
new CodecSceneStructureMetric().encode(structure, param);
// Create random observations
SceneObservations obs = createObservations(rand, structure);
BundleAdjustmentMetricResidualFunction alg = new BundleAdjustmentMetricResidualFunction();
alg.configure(structure, obs);
double[] original = new double[alg.getNumOfOutputsM()];
double[] found = new double[alg.getNumOfOutputsM()];
alg.process(param, original);
for (int paramIndex = 0; paramIndex < original.length; paramIndex++) {
double v = param[paramIndex];
param[paramIndex] += 0.001;
alg.process(param, found);
boolean identical = true;
for (int i = 0; i < found.length; i++) {
if (Math.abs(original[i] - found[i]) > UtilEjml.TEST_F64) {
identical = false;
break;
}
}
assertFalse(identical);
param[paramIndex] = v;
}
}
use of boofcv.abst.geo.bundle.SceneObservations in project BoofCV by lessthanoptimal.
the class TestBundleAdjustmentProjectiveResidualFunction method createObservations.
static SceneObservations createObservations(Random rand, SceneStructureProjective structure) {
SceneObservations obs = new SceneObservations();
obs.initialize(structure.views.size);
for (int j = 0; j < structure.points.size; j++) {
SceneStructureCommon.Point p = structure.points.data[j];
for (int i = 0; i < p.views.size; i++) {
SceneObservations.View v = obs.getView(p.views.get(i));
v.point.add(j);
v.observations.add(rand.nextInt(300) + 20);
v.observations.add(rand.nextInt(300) + 20);
}
}
return obs;
}
use of boofcv.abst.geo.bundle.SceneObservations 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.SceneObservations in project BoofCV by lessthanoptimal.
the class TestPruneStructureFromSceneProjective method createRestOfScene.
private void createRestOfScene() {
observations = new SceneObservations();
observations.initialize(structure.views.size);
Point4D_F64 X = new Point4D_F64();
Point3D_F64 xx = new Point3D_F64();
Point2D_F64 x = new Point2D_F64();
for (int viewIdx = 0; viewIdx < structure.views.size; viewIdx++) {
SceneStructureProjective.View vs = structure.views.data[viewIdx];
DMatrixRMaj P = vs.worldToView;
int width = vs.width;
int height = vs.height;
SceneObservations.View vo = observations.views.data[viewIdx];
for (int pointIdx = 0; pointIdx < structure.points.size; pointIdx++) {
SceneStructureCommon.Point ps = structure.points.data[pointIdx];
ps.get(X);
GeometryMath_F64.mult(P, X, xx);
// behind the camera. I think...
if (Math.signum(X.w) * xx.z < 0)
continue;
x.x = xx.x / xx.z;
x.y = xx.y / xx.z;
if (x.x >= 0 && x.x <= width && x.y >= 0 && x.y <= height) {
ps.views.add(viewIdx);
vo.add(pointIdx, (float) x.x, (float) x.y);
}
}
}
}
Aggregations