Search in sources :

Example 46 with Point2Transform2_F64

use of boofcv.struct.distort.Point2Transform2_F64 in project BoofCV by lessthanoptimal.

the class ExampleStereoTwoViewsOneCamera method convertToNormalizedCoordinates.

/**
 * Convert a set of associated point features from pixel coordinates into normalized image coordinates.
 */
public static List<AssociatedPair> convertToNormalizedCoordinates(List<AssociatedPair> matchedFeatures, CameraPinholeBrown intrinsic) {
    Point2Transform2_F64 p_to_n = LensDistortionFactory.narrow(intrinsic).undistort_F64(true, false);
    List<AssociatedPair> calibratedFeatures = new ArrayList<>();
    for (AssociatedPair p : matchedFeatures) {
        AssociatedPair c = new AssociatedPair();
        p_to_n.compute(p.p1.x, p.p1.y, c.p1);
        p_to_n.compute(p.p2.x, p.p2.y, c.p2);
        calibratedFeatures.add(c);
    }
    return calibratedFeatures;
}
Also used : AssociatedPair(boofcv.struct.geo.AssociatedPair) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) ArrayList(java.util.ArrayList)

Example 47 with Point2Transform2_F64

use of boofcv.struct.distort.Point2Transform2_F64 in project BoofCV by lessthanoptimal.

the class TestBundlePinholeBrown method compareForward.

@Test
void compareForward() {
    CameraPinholeBrown cam = new CameraPinholeBrown(1);
    cam.fx = 300;
    cam.fy = 200;
    cam.cx = cam.cy = 400;
    cam.radial[0] = 0.01;
    cam.skew = 0.001;
    cam.t1 = 0.01;
    cam.t2 = -0.01;
    BundlePinholeBrown alg = BundleAdjustmentOps.convert(cam, (BundlePinholeBrown) null);
    Point2Transform2_F64 n2p = LensDistortionFactory.narrow(cam).distort_F64(false, true);
    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();
    n2p.compute(X / Z, Y / Z, expected);
    assertEquals(0.0, found.distance(expected), UtilEjml.TEST_F64);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Point2D_F64(georegression.struct.point.Point2D_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) Test(org.junit.jupiter.api.Test)

Example 48 with Point2Transform2_F64

use of boofcv.struct.distort.Point2Transform2_F64 in project BoofCV by lessthanoptimal.

the class TestPerspectiveOps method convertPixelToNorm_intrinsic_F64.

@Test
void convertPixelToNorm_intrinsic_F64() {
    CameraPinholeBrown intrinsic = new CameraPinholeBrown(100, 150, 0.1, 120, 209, 500, 600).fsetRadial(0.1, -0.05);
    Point2Transform2_F64 p2n = LensDistortionFactory.narrow(intrinsic).undistort_F64(true, false);
    Point2D_F64 pixel = new Point2D_F64(100, 120);
    Point2D_F64 expected = new Point2D_F64();
    p2n.compute(pixel.x, pixel.y, expected);
    Point2D_F64 found = PerspectiveOps.convertPixelToNorm(intrinsic, pixel, null);
    assertEquals(expected.x, found.x, UtilEjml.TEST_F64);
    assertEquals(expected.y, found.y, UtilEjml.TEST_F64);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) Test(org.junit.jupiter.api.Test)

Example 49 with Point2Transform2_F64

use of boofcv.struct.distort.Point2Transform2_F64 in project BoofCV by lessthanoptimal.

the class BaseChecksPnP method createObservations.

public List<Point2D3D> createObservations(Se3_F64 worldToCamera, double nominalZ, int total) {
    Se3_F64 cameraToWorld = worldToCamera.invert(null);
    // transform from pixel coordinates to normalized pixel coordinates, which removes lens distortion
    Point2Transform2_F64 pixelToNorm = LensDistortionFactory.narrow(intrinsic).undistort_F64(true, false);
    List<Point2D3D> observations = new ArrayList<>();
    Point2D_F64 norm = new Point2D_F64();
    PlaneNormal3D_F64 plane3D = new PlaneNormal3D_F64();
    plane3D.n.setTo(0, 0, 1);
    GeometryMath_F64.mult(worldToCamera.R, plane3D.n, plane3D.n);
    plane3D.p.setTo(worldToCamera.T.x, worldToCamera.T.y, worldToCamera.T.z);
    LineParametric3D_F64 ray = new LineParametric3D_F64();
    Point3D_F64 cameraPt = new Point3D_F64();
    for (int i = 0; i < total; i++) {
        // randomly pixel a point inside the image
        double x = rand.nextDouble() * intrinsic.width;
        double y = rand.nextDouble() * intrinsic.height;
        pixelToNorm.compute(x, y, norm);
        if (worldPointsZZero) {
            // find the world plane in the image
            ray.slope.setTo(norm.x, norm.y, 1);
            Intersection3D_F64.intersection(plane3D, ray, cameraPt);
        } else {
            cameraPt.z = rand.nextDouble() + nominalZ;
            cameraPt.x = norm.x * cameraPt.z;
            cameraPt.y = norm.y * cameraPt.z;
        }
        // Change the point's reference frame from camera to world
        Point3D_F64 worldPt = new Point3D_F64();
        SePointOps_F64.transform(cameraToWorld, cameraPt, worldPt);
        if (worldPointsZZero) {
            if (Math.abs(worldPt.z) > 1e-8)
                throw new RuntimeException("Bug");
            // make it exactly zero
            worldPt.z = 0;
        }
        // Save the perfect noise free observation
        Point2D3D o = new Point2D3D();
        o.getLocation().setTo(worldPt);
        o.getObservation().setTo(norm.x, norm.y);
        observations.add(o);
    }
    return observations;
}
Also used : Point2D3D(boofcv.struct.geo.Point2D3D) Point3D_F64(georegression.struct.point.Point3D_F64) Point2D_F64(georegression.struct.point.Point2D_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) ArrayList(java.util.ArrayList) LineParametric3D_F64(georegression.struct.line.LineParametric3D_F64) Se3_F64(georegression.struct.se.Se3_F64) PlaneNormal3D_F64(georegression.struct.plane.PlaneNormal3D_F64)

Example 50 with Point2Transform2_F64

use of boofcv.struct.distort.Point2Transform2_F64 in project BoofCV by lessthanoptimal.

the class TestLensDistortionOps_F64 method transformChangeModel_EXPAND_modified.

/**
 * Sees if the adjusted intrinsic parameters is correct but computing normalized image coordinates first
 * with the original distorted image and then with the adjusted undistorted image.
 */
@Test
void transformChangeModel_EXPAND_modified() {
    // distorted pixel in original image
    double pixelX = 12.5, pixelY = height - 3;
    CameraPinholeBrown orig = new CameraPinholeBrown().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 0.05);
    CameraPinhole desired = new CameraPinhole(orig);
    Point2Transform2_F64 distToNorm = LensDistortionFactory.narrow(orig).undistort_F64(true, false);
    Point2D_F64 norm = new Point2D_F64();
    distToNorm.compute(pixelX, pixelY, norm);
    CameraPinholeBrown adjusted = new CameraPinholeBrown();
    Point2Transform2_F64 distToAdj = LensDistortionOps_F64.transformChangeModel(AdjustmentType.EXPAND, orig, desired, false, adjusted);
    Point2D_F64 adjPixel = new Point2D_F64();
    Point2D_F64 normFound = new Point2D_F64();
    distToAdj.compute(pixelX, pixelY, adjPixel);
    PerspectiveOps.convertPixelToNorm(adjusted, adjPixel, normFound);
    // see if the normalized image coordinates are the same
    assertEquals(norm.x, normFound.x, 1e-3);
    assertEquals(norm.y, normFound.y, 1e-3);
}
Also used : CameraPinholeBrown(boofcv.struct.calib.CameraPinholeBrown) Point2D_F64(georegression.struct.point.Point2D_F64) Point2Transform2_F64(boofcv.struct.distort.Point2Transform2_F64) CameraPinhole(boofcv.struct.calib.CameraPinhole) Test(org.junit.jupiter.api.Test)

Aggregations

Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)66 Point2D_F64 (georegression.struct.point.Point2D_F64)32 Test (org.junit.jupiter.api.Test)16 Point3D_F64 (georegression.struct.point.Point3D_F64)15 CameraPinholeBrown (boofcv.struct.calib.CameraPinholeBrown)13 SequencePoint2Transform2_F64 (boofcv.struct.distort.SequencePoint2Transform2_F64)11 Se3_F64 (georegression.struct.se.Se3_F64)11 CameraPinhole (boofcv.struct.calib.CameraPinhole)9 LensDistortionBrown (boofcv.alg.distort.brown.LensDistortionBrown)8 PointToPixelTransform_F64 (boofcv.struct.distort.PointToPixelTransform_F64)8 ArrayList (java.util.ArrayList)8 PointTransformHomography_F64 (boofcv.alg.distort.PointTransformHomography_F64)7 AssociatedPair (boofcv.struct.geo.AssociatedPair)6 GrayF32 (boofcv.struct.image.GrayF32)6 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)5 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)5 GrayU8 (boofcv.struct.image.GrayU8)5 RectangleLength2D_F64 (georegression.struct.shapes.RectangleLength2D_F64)5 DMatrixRMaj (org.ejml.data.DMatrixRMaj)4 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)3