Search in sources :

Example 96 with CameraPinhole

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

the class TestRefineDualQuadraticAlgebraicError method solveFixedAspect.

@Test
void solveFixedAspect() {
    List<CameraPinhole> expected = new ArrayList<>();
    List<CameraPinhole> found = new ArrayList<>();
    for (int i = 0; i < 30; i++) {
        expected.add(new CameraPinhole(400 + i * 5, 420, 0.0, 410, 420, 0, 0));
        found.add(new CameraPinhole(expected.get(i)));
        double scaleF = 1.0 + (rand.nextDouble() - 0.5) / 10.0;
        found.get(i).fx *= scaleF;
        found.get(i).fy *= scaleF;
        found.get(i).cx += 2 * rand.nextGaussian();
        found.get(i).cy += 2 * rand.nextGaussian();
    }
    var alg = new RefineDualQuadraticAlgebraicError();
    alg.setKnownAspect(true);
    checkRefine(alg, expected, found, 5);
}
Also used : ArrayList(java.util.ArrayList) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Example 97 with CameraPinhole

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

the class TestRefineDualQuadraticAlgebraicError method checkRefine.

private void checkRefine(RefineDualQuadraticAlgebraicError alg, List<CameraPinhole> expected, List<CameraPinhole> noisy, double tol) {
    // alg.setVerbose(System.out, null);
    renderGood(expected);
    setState(alg, noisy, planeAtInfinity.get(0), planeAtInfinity.get(1), planeAtInfinity.get(2));
    assertTrue(alg.refine());
    List<CameraState> found = alg.getCameras().toList();
    // checking against size of noisy, since noisy is number of cameras
    assertEquals(noisy.size(), found.size());
    // estimate gets worse
    for (int i = 0; i < noisy.size(); i++) {
        CameraPinhole e = expected.get(i);
        CameraState f = found.get(i);
        if (alg.isKnownAspect()) {
            assertEquals(e.fx, f.fx, tol);
            assertEquals(e.fy / e.fx, f.aspectRatio, 0.01);
        } else {
            assertEquals(e.fx, f.fx, tol);
            assertEquals(e.fy / e.fx, f.aspectRatio, 0.05);
        }
        if (alg.isKnownPrinciplePoint()) {
            assertEquals(e.cx, f.cx, UtilEjml.TEST_F64_SQ);
            assertEquals(e.cy, f.cy, UtilEjml.TEST_F64_SQ);
        } else {
            assertEquals(e.cx, f.cx, tol);
            assertEquals(e.cy, f.cy, tol);
        }
    }
}
Also used : CameraState(boofcv.alg.geo.selfcalib.RefineDualQuadraticAlgebraicError.CameraState) CameraPinhole(boofcv.struct.calib.CameraPinhole)

Example 98 with CameraPinhole

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

the class TestSelfCalibrationLinearRotationMulti method convertW.

@Test
void convertW() {
    double tol = 0.001;
    Homography2D_F64 K = new Homography2D_F64(300, 1, 320, 0, 305, 330, 0, 0, 1);
    Homography2D_F64 W = new Homography2D_F64();
    CommonOps_DDF3.multTransB(K, K, W);
    CommonOps_DDF3.invert(W, W);
    CameraPinhole found = new CameraPinhole();
    SelfCalibrationLinearRotationMulti alg = new SelfCalibrationLinearRotationMulti();
    alg.setConstraints(false, false, false, -1);
    alg.convertW(W, found);
    assertEquals(K.a11, found.fx, tol);
    assertEquals(K.a12, found.skew, tol);
    assertEquals(K.a13, found.cx, tol);
    assertEquals(K.a22, found.fy, tol);
    assertEquals(K.a23, found.cy, tol);
    // Add zero Skew
    K.a12 = 0;
    CommonOps_DDF3.multTransB(K, K, W);
    CommonOps_DDF3.invert(W, W);
    alg.setConstraints(true, false, false, -1);
    alg.convertW(W, found);
    assertEquals(K.a11, found.fx, tol);
    assertEquals(0, found.skew, tol);
    assertEquals(K.a13, found.cx, tol);
    assertEquals(K.a22, found.fy, tol);
    assertEquals(K.a23, found.cy, tol);
    // Add origin at zero
    K.a13 = K.a23 = 0;
    CommonOps_DDF3.multTransB(K, K, W);
    CommonOps_DDF3.invert(W, W);
    alg.setConstraints(true, true, false, -1);
    alg.convertW(W, found);
    assertEquals(K.a11, found.fx, tol);
    assertEquals(0, found.skew, tol);
    assertEquals(0, found.cx, tol);
    assertEquals(K.a22, found.fy, tol);
    assertEquals(0, found.cy, tol);
    // Add known aspect ratio
    double aspect = K.a22 / K.a11;
    CommonOps_DDF3.multTransB(K, K, W);
    CommonOps_DDF3.invert(W, W);
    alg.setConstraints(true, true, true, aspect);
    alg.convertW(W, found);
    assertEquals(K.a11, found.fx, tol);
    assertEquals(0, found.skew, tol);
    assertEquals(0, found.cx, tol);
    assertEquals(K.a22, found.fy, tol);
    assertEquals(0, found.cy, tol);
    // sanity check. give it a bad skew and see what happens
    alg.setConstraints(true, true, true, aspect * aspect);
    alg.convertW(W, found);
    assertTrue(Math.abs(K.a22 - found.fy) > tol);
}
Also used : Homography2D_F64(georegression.struct.homography.Homography2D_F64) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Example 99 with CameraPinhole

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

the class TestSelfCalibrationLinearRotationMulti method before.

@BeforeEach
public void before() {
    camera = new CameraPinhole(400, 410, 0, 500, 520, 0, 0);
    PerspectiveOps.pinholeToMatrix(camera, K);
}
Also used : CameraPinhole(boofcv.struct.calib.CameraPinhole) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 100 with CameraPinhole

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

the class TestSelfCalibrationLinearRotationMulti method perfect_AllLinear.

@Test
void perfect_AllLinear() {
    // set the principle point to zero
    camera = new CameraPinhole(400, 420, 0, 510, 540, 0, 0);
    PerspectiveOps.pinholeToMatrix(camera, K);
    renderRotationOnly(camera);
    List<Homography2D_F64> viewsI_to_view0 = computeHomographies();
    SelfCalibrationLinearRotationMulti alg = new SelfCalibrationLinearRotationMulti();
    alg.setConstraints(true, false, true, camera.fy / camera.fx);
    assertSame(alg.estimate(viewsI_to_view0), GeometricResult.SUCCESS);
    DogArray<CameraPinhole> found = alg.getFound();
    for (int i = 0; i < found.size; i++) {
        CameraPinhole f = found.get(i);
        assertEquals(camera.fx, f.fx, UtilEjml.TEST_F64);
        assertEquals(camera.fy, f.fy, UtilEjml.TEST_F64);
        assertEquals(camera.skew, f.skew, UtilEjml.TEST_F64);
        assertEquals(camera.cx, f.cx, UtilEjml.TEST_F64);
        assertEquals(camera.cy, f.cy, UtilEjml.TEST_F64);
    }
}
Also used : CameraPinhole(boofcv.struct.calib.CameraPinhole) Homography2D_F64(georegression.struct.homography.Homography2D_F64) Test(org.junit.jupiter.api.Test)

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