Search in sources :

Example 11 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestMultiViewOps method canonicalCamera.

@Test
public void canonicalCamera() {
    DMatrixRMaj K = PerspectiveOps.calibrationMatrix(200, 250, 0.0, 100, 110);
    DMatrixRMaj R = ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 1, 2, -0.5, null);
    Vector3D_F64 T = new Vector3D_F64(0.5, 0.7, -0.3);
    DMatrixRMaj E = MultiViewOps.createEssential(R, T);
    DMatrixRMaj F = MultiViewOps.createFundamental(E, K);
    Point3D_F64 e1 = new Point3D_F64();
    Point3D_F64 e2 = new Point3D_F64();
    CommonOps_DDRM.scale(-2.0 / F.get(0, 1), F);
    MultiViewOps.extractEpipoles(F, e1, e2);
    DMatrixRMaj P = MultiViewOps.canonicalCamera(F, e2, new Vector3D_F64(1, 1, 1), 2);
    // recompose the fundamental matrix using the special equation for canonical cameras
    DMatrixRMaj foundF = new DMatrixRMaj(3, 3);
    DMatrixRMaj crossEpi = new DMatrixRMaj(3, 3);
    GeometryMath_F64.crossMatrix(e2, crossEpi);
    DMatrixRMaj M = new DMatrixRMaj(3, 3);
    CommonOps_DDRM.extract(P, 0, 3, 0, 3, M, 0, 0);
    CommonOps_DDRM.mult(crossEpi, M, foundF);
    // see if they are equal up to a scale factor
    CommonOps_DDRM.scale(1.0 / foundF.get(0, 1), foundF);
    CommonOps_DDRM.scale(1.0 / F.get(0, 1), F);
    assertTrue(MatrixFeatures_DDRM.isIdentical(F, foundF, 1e-8));
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Vector3D_F64(georegression.struct.point.Vector3D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.Test)

Example 12 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestMultiViewOps method extractCameraMatrices.

@Test
public void extractCameraMatrices() {
    DMatrixRMaj P2 = new DMatrixRMaj(3, 4);
    DMatrixRMaj P3 = new DMatrixRMaj(3, 4);
    TrifocalTensor input = tensor.copy();
    MultiViewOps.extractCameraMatrices(input, P2, P3);
    // make sure the input was not modified
    for (int i = 0; i < 3; i++) assertTrue(MatrixFeatures_DDRM.isIdentical(tensor.getT(i), input.getT(i), 1e-8));
    // Using found camera matrices render the point's location
    Point3D_F64 X = new Point3D_F64(0.1, 0.05, 2);
    Point2D_F64 x1 = new Point2D_F64(X.x / X.z, X.y / X.z);
    Point2D_F64 x2 = PerspectiveOps.renderPixel(P2, X);
    Point2D_F64 x3 = PerspectiveOps.renderPixel(P3, X);
    // validate correctness by testing a constraint on the points
    DMatrixRMaj A = new DMatrixRMaj(3, 3);
    MultiViewOps.constraint(tensor, x1, x2, x3, A);
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            assertEquals(0, A.get(i, j), 1e-7);
        }
    }
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) TrifocalTensor(boofcv.struct.geo.TrifocalTensor) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Test(org.junit.Test)

Example 13 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method renderPixel_cameramatrix.

@Test
public void renderPixel_cameramatrix() {
    Point3D_F64 X = new Point3D_F64(0.1, -0.05, 3);
    Se3_F64 worldToCamera = new Se3_F64();
    ConvertRotation3D_F64.eulerToMatrix(EulerType.XYZ, 0.1, -0.05, 0.03, worldToCamera.getR());
    worldToCamera.getT().set(0.2, 0.01, -0.03);
    DMatrixRMaj K = RandomMatrices_DDRM.triangularUpper(3, 0, -1, 1, rand);
    Point3D_F64 X_cam = SePointOps_F64.transform(worldToCamera, X, null);
    Point2D_F64 found;
    DMatrixRMaj P = PerspectiveOps.createCameraMatrix(worldToCamera.R, worldToCamera.T, K, null);
    Point2D_F64 expected = new Point2D_F64();
    expected.x = X_cam.x / X_cam.z;
    expected.y = X_cam.y / X_cam.z;
    GeometryMath_F64.mult(K, expected, expected);
    found = PerspectiveOps.renderPixel(P, X);
    assertEquals(expected.x, found.x, 1e-8);
    assertEquals(expected.y, found.y, 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Example 14 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method renderPixel_intrinsic.

@Test
public void renderPixel_intrinsic() {
    Point3D_F64 X = new Point3D_F64(0.1, -0.05, 3);
    CameraPinholeRadial intrinsic = new CameraPinholeRadial(100, 150, 0.1, 120, 209, 500, 600);
    double normX = X.x / X.z;
    double normY = X.y / X.z;
    Point2D_F64 expected = new Point2D_F64();
    PerspectiveOps.convertNormToPixel(intrinsic, normX, normY, expected);
    Point2D_F64 found = PerspectiveOps.renderPixel(intrinsic, X);
    assertEquals(expected.x, found.x, 1e-8);
    assertEquals(expected.y, found.y, 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F64(georegression.struct.point.Point2D_F64) Test(org.junit.Test)

Example 15 with Point3D_F64

use of georegression.struct.point.Point3D_F64 in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method scaleIntrinsic.

@Test
public void scaleIntrinsic() {
    Point3D_F64 X = new Point3D_F64(0.1, 0.3, 2);
    CameraPinholeRadial param = new CameraPinholeRadial(200, 300, 2, 250, 260, 200, 300);
    DMatrixRMaj K = PerspectiveOps.calibrationMatrix(param, (DMatrixRMaj) null);
    // find the pixel location in the unscaled image
    Point2D_F64 a = PerspectiveOps.renderPixel(new Se3_F64(), K, X);
    PerspectiveOps.scaleIntrinsic(param, 0.5);
    K = PerspectiveOps.calibrationMatrix(param, (DMatrixRMaj) null);
    // find the pixel location in the scaled image
    Point2D_F64 b = PerspectiveOps.renderPixel(new Se3_F64(), K, X);
    assertEquals(a.x * 0.5, b.x, 1e-8);
    assertEquals(a.y * 0.5, b.y, 1e-8);
}
Also used : Point3D_F64(georegression.struct.point.Point3D_F64) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) Point2D_F64(georegression.struct.point.Point2D_F64) DMatrixRMaj(org.ejml.data.DMatrixRMaj) Se3_F64(georegression.struct.se.Se3_F64) Test(org.junit.Test)

Aggregations

Point3D_F64 (georegression.struct.point.Point3D_F64)174 Point2D_F64 (georegression.struct.point.Point2D_F64)85 Test (org.junit.Test)77 Se3_F64 (georegression.struct.se.Se3_F64)74 DMatrixRMaj (org.ejml.data.DMatrixRMaj)46 ArrayList (java.util.ArrayList)17 Vector3D_F64 (georegression.struct.point.Vector3D_F64)15 Point2D3D (boofcv.struct.geo.Point2D3D)13 AssociatedPair (boofcv.struct.geo.AssociatedPair)12 GrayU8 (boofcv.struct.image.GrayU8)9 FastQueue (org.ddogleg.struct.FastQueue)9 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)8 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)7 MotionTransformPoint (georegression.fitting.MotionTransformPoint)7 UtilPoint3D_F64 (georegression.geometry.UtilPoint3D_F64)7 PointTrack (boofcv.abst.feature.tracker.PointTrack)5 StereoParameters (boofcv.struct.calib.StereoParameters)5 TrifocalTensor (boofcv.struct.geo.TrifocalTensor)5 GrayU16 (boofcv.struct.image.GrayU16)5 Stereo2D3D (boofcv.struct.sfm.Stereo2D3D)5