Search in sources :

Example 11 with SceneObservations

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);
    }
}
Also used : UtilPoint3D_F64(georegression.geometry.UtilPoint3D_F64) Point3D_F64(georegression.struct.point.Point3D_F64) SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) Point2D_F64(georegression.struct.point.Point2D_F64) CameraPinhole(boofcv.struct.calib.CameraPinhole) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.jupiter.api.Test)

Example 12 with SceneObservations

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;
    }
}
Also used : SceneStructureMetric(boofcv.abst.geo.bundle.SceneStructureMetric) SceneObservations(boofcv.abst.geo.bundle.SceneObservations)

Example 13 with SceneObservations

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;
}
Also used : SceneObservations(boofcv.abst.geo.bundle.SceneObservations) SceneStructureCommon(boofcv.abst.geo.bundle.SceneStructureCommon)

Example 14 with SceneObservations

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));
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) DMatrixSparseCSC(org.ejml.data.DMatrixSparseCSC) Test(org.junit.jupiter.api.Test)

Example 15 with SceneObservations

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);
            }
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) SceneObservations(boofcv.abst.geo.bundle.SceneObservations) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) UtilPoint4D_F64(georegression.geometry.UtilPoint4D_F64) Point4D_F64(georegression.struct.point.Point4D_F64) SceneStructureCommon(boofcv.abst.geo.bundle.SceneStructureCommon)

Aggregations

SceneObservations (boofcv.abst.geo.bundle.SceneObservations)32 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)21 VerbosePrint (org.ddogleg.struct.VerbosePrint)10 SceneStructureProjective (boofcv.abst.geo.bundle.SceneStructureProjective)7 Se3_F64 (georegression.struct.se.Se3_F64)6 Test (org.junit.jupiter.api.Test)6 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)5 Point2D_F64 (georegression.struct.point.Point2D_F64)4 Point3D_F64 (georegression.struct.point.Point3D_F64)4 Point4D_F64 (georegression.struct.point.Point4D_F64)4 DMatrixRMaj (org.ejml.data.DMatrixRMaj)4 CodecSceneStructureMetric (boofcv.alg.geo.bundle.CodecSceneStructureMetric)3 BundlePinholeSimplified (boofcv.alg.geo.bundle.cameras.BundlePinholeSimplified)3 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 DetectDescribePoint (boofcv.abst.feature.detdesc.DetectDescribePoint)2 TriangulateNViewsMetricH (boofcv.abst.geo.TriangulateNViewsMetricH)2 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)2 AssociatedTriple (boofcv.struct.geo.AssociatedTriple)2 PointIndex2D_F64 (boofcv.struct.geo.PointIndex2D_F64)2 ArrayList (java.util.ArrayList)2