Search in sources :

Example 21 with CameraPinhole

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

the class TestSelfCalibrationLinearRotationSingle method two_axis.

@Test
void two_axis() {
    CameraPinhole intrinsic = new CameraPinhole(400, 420, 0.1, 450, 475, 0, 0);
    renderRotateTwoAxis(intrinsic);
    performTest(intrinsic);
}
Also used : CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Example 22 with CameraPinhole

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

the class TestSelfCalibrationLinearRotationSingle method checkFailure.

private void checkFailure() {
    // compute planes at infinity
    List<Homography2D_F64> homographies = new ArrayList<>();
    for (int i = 0; i < listP.size(); i++) {
        DMatrixRMaj P = listP.get(i);
        Equation eq = new Equation();
        eq.alias(P, "P", planeAtInfinity, "p");
        eq.process("H = P(:,0:2) - P(:,3)*p'");
        Homography2D_F64 H = new Homography2D_F64();
        DConvertMatrixStruct.convert(eq.lookupDDRM("H"), H);
        homographies.add(H);
    }
    SelfCalibrationLinearRotationSingle alg = new SelfCalibrationLinearRotationSingle();
    CameraPinhole found = new CameraPinhole();
    assertFalse(alg.estimate(homographies, found));
}
Also used : ArrayList(java.util.ArrayList) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Equation(org.ejml.equation.Equation) Homography2D_F64(georegression.struct.homography.Homography2D_F64) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Example 23 with CameraPinhole

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

the class TestSelfCalibrationLinearRotationSingle method checkLinearSystem.

@Test
void checkLinearSystem() {
    CameraPinhole intrinsic = new CameraPinhole(400, 420, 0.1, 450, 475, 0, 0);
    renderRotationOnly(intrinsic);
    DMatrixRMaj K = new DMatrixRMaj(3, 3);
    PerspectiveOps.pinholeToMatrix(intrinsic, K);
    DMatrixRMaj w = new DMatrixRMaj(3, 3);
    CommonOps_DDRM.multTransB(K, K, w);
    // compute planes at infinity
    List<Homography2D_F64> homographies = new ArrayList<>();
    for (int i = 0; i < listP.size(); i++) {
        // System.out.println("projective "+i);
        DMatrixRMaj P = listP.get(i);
        Equation eq = new Equation();
        eq.alias(P, "P", planeAtInfinity, "p", K, "K", w, "w");
        eq.process("H = P(:,0:2) - P(:,3)*p'");
        // eq.process("w2 = H*w*H'");
        // eq.process("w2 = w2 - w");
        // System.out.println("w");
        // eq.lookupDDRM("w").print();
        // System.out.println("w2");
        // eq.lookupDDRM("w2").print();
        Homography2D_F64 H = new Homography2D_F64();
        DConvertMatrixStruct.convert(eq.lookupDDRM("H"), H);
        homographies.add(H);
    // H.print();
    }
    SelfCalibrationLinearRotationSingle alg = new SelfCalibrationLinearRotationSingle();
    alg.ensureDeterminantOfOne(homographies);
    int N = homographies.size();
    DMatrixRMaj A = new DMatrixRMaj(6 * N, 6);
    DMatrixRMaj X = new DMatrixRMaj(6, 1);
    DMatrixRMaj found = new DMatrixRMaj(A.numRows, 1);
    for (int i = 0; i < homographies.size(); i++) {
        alg.add(i, homographies.get(i), A);
    }
    X.data[0] = w.data[0];
    X.data[1] = w.data[1];
    X.data[2] = w.data[2];
    X.data[3] = w.data[4];
    X.data[4] = w.data[5];
    X.data[5] = w.data[8];
    CommonOps_DDRM.mult(A, X, found);
    assertEquals(0, NormOps_DDRM.normF(found), UtilEjml.TEST_F64);
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) ArrayList(java.util.ArrayList) Equation(org.ejml.equation.Equation) CameraPinhole(boofcv.struct.calib.CameraPinhole) Homography2D_F64(georegression.struct.homography.Homography2D_F64) Test(org.junit.jupiter.api.Test)

Example 24 with CameraPinhole

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

the class TestSelfCalibrationLinearRotationSingle method one_axis.

/**
 * One axis rotation will fail
 */
@Test
void one_axis() {
    CameraPinhole intrinsic = new CameraPinhole(400, 420, 0.1, 450, 475, 0, 0);
    renderRotateOneAxis(intrinsic);
    checkFailure();
}
Also used : CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Example 25 with CameraPinhole

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

the class TestRefineTwoViewPinholeRotation method evaluateImperfect.

private void evaluateImperfect(CameraPinhole intrinsic1, CameraPinhole intrinsic2, List<AssociatedPair> pairs) {
    var alg = new RefineTwoViewPinholeRotation();
    // Apply some constraints. Yes this test isn't exhaustive at all.
    alg.assumeUnityAspect = true;
    alg.zeroSkew = true;
    alg.assumeSameIntrinsics = false;
    alg.knownFocalLength = false;
    // Focal length and rotation are going to be way off as a test
    CameraPinhole found1 = new CameraPinhole(200, 200, 0.0, 530, 530, 1000, 1000);
    CameraPinhole found2 = new CameraPinhole(1000, 1000, 0.0, 430, 430, 800, 800);
    DMatrixRMaj R = CommonOps_DDRM.identity(3);
    alg.converge.maxIterations = 40;
    // alg.setVerbose(System.out, null);
    assertTrue(alg.refine(pairs, R, found1, found2));
    // Should be significantly better
    assertTrue(alg.errorAfter * 1e5 <= alg.errorBefore);
    // Check constraints
    assertEquals(found1.fx, found1.fy);
    assertEquals(found2.fx, found2.fy);
    assertEquals(0.0, found1.skew);
    assertEquals(0.0, found2.skew);
    // Based on manual inspection there seems to be redundancy in these equations some place that I've
    // not yet dug out. The error is zero but K1 and K2 are significantly different. R is "close"
    // very crude test for focal length
    assertEquals(intrinsic1.fx, found1.fx, 150);
    assertEquals(intrinsic2.fx, found2.fy, 150);
    // Compute the number of radians different the two rotations are
    DMatrixRMaj diffR = CommonOps_DDRM.multTransA(view1_to_view2.R, R, null);
    double angle = ConvertRotation3D_F64.matrixToRodrigues(diffR, null).theta;
    assertEquals(0.0, angle, 0.05);
}
Also used : DMatrixRMaj(org.ejml.data.DMatrixRMaj) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Aggregations

CameraPinhole (boofcv.struct.calib.CameraPinhole)154 Test (org.junit.jupiter.api.Test)81 Se3_F64 (georegression.struct.se.Se3_F64)36 DMatrixRMaj (org.ejml.data.DMatrixRMaj)32 Point2D_F64 (georegression.struct.point.Point2D_F64)24 ArrayList (java.util.ArrayList)23 Point3D_F64 (georegression.struct.point.Point3D_F64)19 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)12 SceneStructureMetric (boofcv.abst.geo.bundle.SceneStructureMetric)11 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)11 Test (org.junit.Test)10 GrayF32 (boofcv.struct.image.GrayF32)9 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)8 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)8 BufferedImage (java.awt.image.BufferedImage)8 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)7 VerbosePrint (org.ddogleg.struct.VerbosePrint)7 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)6 WorldToCameraToPixel (boofcv.alg.geo.WorldToCameraToPixel)6 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)5