Search in sources :

Example 6 with SceneStructureProjective

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

Example 7 with SceneStructureProjective

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));
}
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 8 with SceneStructureProjective

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;
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) BundleCameraProjective(boofcv.alg.geo.bundle.cameras.BundleCameraProjective) DMatrixRMaj(org.ejml.data.DMatrixRMaj) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Example 9 with SceneStructureProjective

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;
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) BundleCameraProjective(boofcv.alg.geo.bundle.cameras.BundleCameraProjective) DMatrixRMaj(org.ejml.data.DMatrixRMaj) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Example 10 with SceneStructureProjective

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();
}
Also used : SceneStructureProjective(boofcv.abst.geo.bundle.SceneStructureProjective) DMatrixRMaj(org.ejml.data.DMatrixRMaj) UtilPoint4D_F64(georegression.geometry.UtilPoint4D_F64) Point4D_F64(georegression.struct.point.Point4D_F64) CameraPinhole(boofcv.struct.calib.CameraPinhole) Se3_F64(georegression.struct.se.Se3_F64)

Aggregations

SceneStructureProjective (boofcv.abst.geo.bundle.SceneStructureProjective)12 DMatrixRMaj (org.ejml.data.DMatrixRMaj)7 SceneObservations (boofcv.abst.geo.bundle.SceneObservations)6 Test (org.junit.jupiter.api.Test)5 CameraPinhole (boofcv.struct.calib.CameraPinhole)3 Point4D_F64 (georegression.struct.point.Point4D_F64)3 BundleCameraProjective (boofcv.alg.geo.bundle.cameras.BundleCameraProjective)2 Point2D_F64 (georegression.struct.point.Point2D_F64)2 DMatrixSparseCSC (org.ejml.data.DMatrixSparseCSC)2 SceneStructureCommon (boofcv.abst.geo.bundle.SceneStructureCommon)1 UtilPoint4D_F64 (georegression.geometry.UtilPoint4D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1 DogArray_I32 (org.ddogleg.struct.DogArray_I32)1