Search in sources :

Example 1 with CameraKannalaBrandt

use of boofcv.struct.calib.CameraKannalaBrandt in project BoofCV by lessthanoptimal.

the class TestKannalaBrandtPtoS_F64 method jacobianOfDistorted.

/**
 * Compare to numerical Jacobian
 */
@Test
void jacobianOfDistorted() {
    CameraKannalaBrandt model = new CameraKannalaBrandt().fsetK(500, 550, 0.0, 600, 650);
    model.fsetSymmetric(1.0, 0.4).fsetRadial(1.1, 0.2, -0.01).fsetTangent(0.5, -0.1, 0.06, 0.12).fsetRadialTrig(0.01, 0.03, -0.03, 0.04).fsetTangentTrig(0.01, 0.2, 0.1, 0.4);
    FunctionNtoM function = new FunctionNtoM() {

        @Override
        public void process(/**/
        double[] input, /**/
        double[] output) {
            double theta = (double) input[0];
            double psi = (double) input[1];
            double r = (double) polynomial(model.symmetric, theta);
            double cospsi = Math.cos(psi);
            double sinpsi = Math.sin(psi);
            // distortion terms. radial and tangential
            double dr = (double) (polynomial(model.radial, theta) * polytrig(model.radialTrig, cospsi, sinpsi));
            double dt = (double) (polynomial(model.tangent, theta) * polytrig(model.tangentTrig, cospsi, sinpsi));
            // put it all together to get normalized image coordinates
            output[0] = (r + dr) * cospsi - dt * sinpsi;
            output[1] = (r + dr) * sinpsi + dt * cospsi;
        }

        @Override
        public int getNumOfInputsN() {
            return 2;
        }

        @Override
        public int getNumOfOutputsM() {
            return 2;
        }
    };
    var kb = new KannalaBrandtPtoS_F64(model);
    FunctionNtoMxN<DMatrixRMaj> jacobian = new FunctionNtoMxN<>() {

        final DMatrix2x2 a = new DMatrix2x2();

        @Override
        public int getNumOfInputsN() {
            return 2;
        }

        @Override
        public int getNumOfOutputsM() {
            return 2;
        }

        @Override
        public DMatrixRMaj declareMatrixMxN() {
            return new DMatrixRMaj(2, 2);
        }

        @Override
        public void process(/**/
        double[] input, DMatrixRMaj output) {
            double theta = (double) input[0];
            double psi = (double) input[1];
            double cospsi = Math.cos(psi);
            double sinpsi = Math.sin(psi);
            kb.jacobianOfDistorted(theta, cospsi, sinpsi, a);
            BoofMiscOps.convertMatrix(a, output);
        }
    };
    // DerivativeChecker.jacobianPrint(function, jacobian, new double[]{0.2, -0.4}, 1e-4);
    assertTrue(DerivativeChecker.jacobian(function, jacobian, new /**/
    double[] { 0.2, -0.4 }, UtilEjml.TEST_F64_SQ, Math.sqrt(UtilEjml.EPS)));
}
Also used : FunctionNtoMxN(org.ddogleg.optimization.functions.FunctionNtoMxN) DMatrix2x2(org.ejml.data.DMatrix2x2) CameraKannalaBrandt(boofcv.struct.calib.CameraKannalaBrandt) DMatrixRMaj(org.ejml.data.DMatrixRMaj) FunctionNtoM(org.ddogleg.optimization.functions.FunctionNtoM) Test(org.junit.jupiter.api.Test)

Example 2 with CameraKannalaBrandt

use of boofcv.struct.calib.CameraKannalaBrandt in project BoofCV by lessthanoptimal.

the class TestKannalaBrandtPtoS_F64 method simpleSanityCheck_Everything.

/**
 * The entire motion model will be exercised here
 */
@Test
void simpleSanityCheck_Everything() {
    CameraKannalaBrandt model = new CameraKannalaBrandt().fsetK(500, 550, 0.0, 600, 650);
    model.fsetSymmetric(1.0, 0.4).fsetRadial(1.1, 0.2, -0.01).fsetTangent(0.5, -0.1, 0.06, 0.12).fsetRadialTrig(0.01, 0.02, -0.03, 0.04).fsetTangentTrig(0.01, 0.2, 0.1, 0.4);
    var expected = new Point3D_F64(0.1, -0.12, 0.8);
    var pixel = new Point2D_F64();
    var found = new Point3D_F64();
    new KannalaBrandtStoP_F64(model).compute(expected.x, expected.y, expected.z, pixel);
    new KannalaBrandtPtoS_F64(model).compute(pixel.x, pixel.y, found);
    // make sure both have them have a norm of 1
    expected.divideIP(expected.norm());
    found.divideIP(found.norm());
    // The paper says this will be noisy. Using Newton's method seems to be much more accurate
    assertEquals(0.0, expected.distance(found), 1e-4);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) CameraKannalaBrandt(boofcv.struct.calib.CameraKannalaBrandt) Test(org.junit.jupiter.api.Test)

Example 3 with CameraKannalaBrandt

use of boofcv.struct.calib.CameraKannalaBrandt in project BoofCV by lessthanoptimal.

the class TestBundleKannalaBrandt method jacobian_all.

/**
 * Check the Jacobian with all parameters
 */
@Test
void jacobian_all() {
    CameraKannalaBrandt model = new CameraKannalaBrandt().fsetK(500, 550, 0.1, 600, 650);
    model.fsetSymmetric(1.0, 0.4).fsetRadial(1.1, 0.2, -0.01).fsetTangent(0.5, -0.1, 0.06).fsetRadialTrig(0.01, 0.02, -0.03, 0.12).fsetTangentTrig(0.01, 0.2, 0.1, 0.4);
    BundleKannalaBrandt alg = new BundleKannalaBrandt(model);
    double[] parameters = new double[alg.getIntrinsicCount()];
    alg.getIntrinsic(parameters, 0);
    new GenericChecksBundleAdjustmentCamera(alg, 0.01) {
    }.setParameters(new double[][] { parameters }).checkAll();
}
Also used : CameraKannalaBrandt(boofcv.struct.calib.CameraKannalaBrandt) Test(org.junit.jupiter.api.Test)

Example 4 with CameraKannalaBrandt

use of boofcv.struct.calib.CameraKannalaBrandt in project BoofCV by lessthanoptimal.

the class TestBundleKannalaBrandt method compareForward.

/**
 * Compare the forward distortion to the lens distortion model
 */
@Test
void compareForward() {
    CameraKannalaBrandt model = new CameraKannalaBrandt().fsetK(500, 550, 0.1, 600, 650);
    model.fsetSymmetric(1.0, 0.4).fsetRadial(1.1, 0.2, -0.01).fsetTangent(0.5, -0.1, 0.06).fsetRadialTrig(0.01, 0.02, -0.03, 0.12).fsetTangentTrig(0.01, 0.2, 0.1, 0.4);
    BundleKannalaBrandt alg = new BundleKannalaBrandt(model);
    Point3Transform2_F64 n2p = LensDistortionFactory.wide(model).distortStoP_F64();
    Point2D_F64 found = new Point2D_F64();
    double X = 0.1, Y = -0.2, Z = 2;
    alg.project(X, Y, Z, found);
    Point2D_F64 expected = new Point2D_F64();
    // convert to unit sphere
    double n = Math.sqrt(X * X + Y * Y + Z * Z);
    n2p.compute(X / n, Y / n, Z / n, expected);
    Assertions.assertTrue(found.distance(expected) < UtilEjml.TEST_F64);
}
Also used : Point2D_F64(georegression.struct.point.Point2D_F64) CameraKannalaBrandt(boofcv.struct.calib.CameraKannalaBrandt) Point3Transform2_F64(boofcv.struct.distort.Point3Transform2_F64) Test(org.junit.jupiter.api.Test)

Example 5 with CameraKannalaBrandt

use of boofcv.struct.calib.CameraKannalaBrandt in project BoofCV by lessthanoptimal.

the class TestCalibrationIO method save_load_KannalaBrandt.

@Test
void save_load_KannalaBrandt() {
    // try simplified case with only symmetric distortion
    CameraKannalaBrandt model;
    model = new CameraKannalaBrandt().fsetK(500, 550, 0.1, 600, 650);
    model.fsetSymmetric(1.0, 0.4);
    save_load_KannalaBrandt(model);
    // Full distortion model
    model = new CameraKannalaBrandt().fsetK(500, 550, 0.1, 600, 650);
    model.fsetSymmetric(1.0, 0.4).fsetRadial(1.1, 0.2, -0.01).fsetTangent(0.5, -0.1, 0.06, 0.12).fsetRadialTrig(0.01, 0.03, -0.03, 0.04).fsetTangentTrig(0.01, 0.2, 0.1, 0.4);
    save_load_KannalaBrandt(model);
}
Also used : CameraKannalaBrandt(boofcv.struct.calib.CameraKannalaBrandt) Test(org.junit.jupiter.api.Test)

Aggregations

CameraKannalaBrandt (boofcv.struct.calib.CameraKannalaBrandt)11 Test (org.junit.jupiter.api.Test)10 Point2D_F64 (georegression.struct.point.Point2D_F64)5 Point3D_F64 (georegression.struct.point.Point3D_F64)4 Point3Transform2_F64 (boofcv.struct.distort.Point3Transform2_F64)1 ArrayList (java.util.ArrayList)1 FunctionNtoM (org.ddogleg.optimization.functions.FunctionNtoM)1 FunctionNtoMxN (org.ddogleg.optimization.functions.FunctionNtoMxN)1 DMatrix2x2 (org.ejml.data.DMatrix2x2)1 DMatrixRMaj (org.ejml.data.DMatrixRMaj)1