Search in sources :

Example 1 with Point2Transform3_F32

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

the class TestNarrowToWidePtoP_F32 method checkFOVBounds.

/**
 * Request points at the border and see if it has the expected vertical and horizontal FOV
 */
@Test
public void checkFOVBounds() {
    NarrowToWidePtoP_F32 alg = createAlg();
    Point2D_F32 foundA = new Point2D_F32();
    Point2D_F32 foundB = new Point2D_F32();
    Point3D_F32 vA = new Point3D_F32();
    Point3D_F32 vB = new Point3D_F32();
    // Compute the horizontal FOV
    alg.compute(0, 250, foundA);
    alg.compute(500, 250, foundB);
    Point2Transform3_F32 wideToSphere = createModelWide().undistortPtoS_F32();
    wideToSphere.compute(foundA.x, foundA.y, vA);
    wideToSphere.compute(foundB.x, foundB.y, vB);
    float found = UtilVector3D_F32.acute(new Vector3D_F32(vA), new Vector3D_F32(vB));
    float expected = 2.0f * (float) Math.atan(250.0f / 400.0f);
    assertEquals(expected, found, 0.01f);
    // Compute the vertical FOV
    alg.compute(250, 0, foundA);
    alg.compute(250, 500, foundB);
    wideToSphere.compute(foundA.x, foundA.y, vA);
    wideToSphere.compute(foundB.x, foundB.y, vB);
    found = UtilVector3D_F32.acute(new Vector3D_F32(vA), new Vector3D_F32(vB));
    expected = 2.0f * (float) Math.atan(250.0f / 400.0f);
    assertEquals(expected, found, 0.001f);
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) Vector3D_F32(georegression.struct.point.Vector3D_F32) UtilVector3D_F32(georegression.geometry.UtilVector3D_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform3_F32(boofcv.struct.distort.Point2Transform3_F32) Test(org.junit.Test)

Example 2 with Point2Transform3_F32

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

the class MultiCameraToEquirectangular method addCamera.

/**
 * Adds a camera and attempts to compute the mask from the provided distortion model.  if a pixel is rendered
 * outside the bounds in the input image then it is masked out.  If the forwards/backwards transform is too
 * different then it is masked out.
 *
 * @param cameraToCommon Rigid body transform from this camera to the common frame the equirectangular image
 *                       is in
 * @param factory Distortion model
 * @param width Input image width
 * @param height Input image height
 */
public void addCamera(Se3_F32 cameraToCommon, LensDistortionWideFOV factory, int width, int height) {
    Point2Transform3_F32 p2s = factory.undistortPtoS_F32();
    Point3Transform2_F32 s2p = factory.distortStoP_F32();
    EquiToCamera equiToCamera = new EquiToCamera(cameraToCommon.getR(), s2p);
    GrayF32 equiMask = new GrayF32(equiWidth, equHeight);
    PixelTransform2_F32 transformEquiToCam = new PixelTransformCached_F32(equiWidth, equHeight, new PointToPixelTransform_F32(equiToCamera));
    Point3D_F32 p3b = new Point3D_F32();
    Point2D_F32 p2 = new Point2D_F32();
    for (int row = 0; row < equHeight; row++) {
        for (int col = 0; col < equiWidth; col++) {
            equiToCamera.compute(col, row, p2);
            int camX = (int) (p2.x + 0.5f);
            int camY = (int) (p2.y + 0.5f);
            if (Double.isNaN(p2.x) || Double.isNaN(p2.y) || camX < 0 || camY < 0 || camX >= width || camY >= height)
                continue;
            p2s.compute(p2.x, p2.y, p3b);
            if (Double.isNaN(p3b.x) || Double.isNaN(p3b.y) || Double.isNaN(p3b.z))
                continue;
            double angle = UtilVector3D_F32.acute(equiToCamera.unitCam, p3b);
            if (angle < maskToleranceAngle) {
                equiMask.set(col, row, 1);
            }
        }
    }
    cameras.add(new Camera(equiMask, transformEquiToCam));
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform3_F32(boofcv.struct.distort.Point2Transform3_F32) Point3Transform2_F32(boofcv.struct.distort.Point3Transform2_F32) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32) PixelTransformCached_F32(boofcv.alg.distort.PixelTransformCached_F32)

Example 3 with Point2Transform3_F32

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

the class MultiCameraToEquirectangular method addCamera.

/**
 * Adds a camera and attempts to compute the mask from the provided distortion model.  if a pixel is rendered
 * outside the bounds in the input image then it is masked out.  If the forwards/backwards transform is too
 * different then it is masked out.
 *
 * @param cameraToCommon Rigid body transform from this camera to the common frame the equirectangular image
 *                       is in
 * @param factory Distortion model
 * @param camMask Binary mask with invalid pixels marked as not zero.  Pixels are in camera image frame.
 */
public void addCamera(Se3_F32 cameraToCommon, LensDistortionWideFOV factory, GrayU8 camMask) {
    Point2Transform3_F32 p2s = factory.undistortPtoS_F32();
    Point3Transform2_F32 s2p = factory.distortStoP_F32();
    EquiToCamera equiToCamera = new EquiToCamera(cameraToCommon.getR(), s2p);
    GrayF32 equiMask = new GrayF32(equiWidth, equHeight);
    PixelTransformCached_F32 transformEquiToCam = new PixelTransformCached_F32(equiWidth, equHeight, new PointToPixelTransform_F32(equiToCamera));
    int width = camMask.width;
    int height = camMask.height;
    Point3D_F32 p3b = new Point3D_F32();
    Point2D_F32 p2 = new Point2D_F32();
    for (int row = 0; row < equHeight; row++) {
        for (int col = 0; col < equiWidth; col++) {
            equiToCamera.compute(col, row, p2);
            if (UtilEjml.isUncountable(p2.x) || UtilEjml.isUncountable(p2.y)) {
                // can't have it be an invalid number in the cache, but had to be invalid so that the mask
                // could be set to zero.  So set it to some valid value that won't cause it to blow up
                transformEquiToCam.getPixel(col, row).set(-1, -1);
                continue;
            }
            int camX = (int) (p2.x + 0.5f);
            int camY = (int) (p2.y + 0.5f);
            if (camX < 0 || camY < 0 || camX >= width || camY >= height)
                continue;
            if (camMask.unsafe_get(camX, camY) == 1) {
                p2s.compute(p2.x, p2.y, p3b);
                if (Double.isNaN(p3b.x) || Double.isNaN(p3b.y) || Double.isNaN(p3b.z))
                    continue;
                double angle = UtilVector3D_F32.acute(equiToCamera.unitCam, p3b);
                if (angle < maskToleranceAngle) {
                    equiMask.set(col, row, 1);
                }
            }
        }
    }
    cameras.add(new Camera(equiMask, transformEquiToCam));
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform3_F32(boofcv.struct.distort.Point2Transform3_F32) Point3Transform2_F32(boofcv.struct.distort.Point3Transform2_F32) PixelTransformCached_F32(boofcv.alg.distort.PixelTransformCached_F32)

Example 4 with Point2Transform3_F32

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

the class GeneralLensDistortionWideFOVChecks method pixel_unit_pixel_F32.

@Test
public void pixel_unit_pixel_F32() {
    LensDistortionWideFOV alg = create();
    Point2Transform3_F32 undistort = alg.undistortPtoS_F32();
    Point3Transform2_F32 distort = alg.distortStoP_F32();
    Point3D_F32 middle = new Point3D_F32();
    Point2D_F32 found = new Point2D_F32();
    undistort.compute(240, 260, middle);
    distort.compute(middle.x, middle.y, middle.z, found);
    assertEquals(240, found.x, pixel_tol_F32);
    assertEquals(260, found.y, pixel_tol_F32);
}
Also used : Point3D_F32(georegression.struct.point.Point3D_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform3_F32(boofcv.struct.distort.Point2Transform3_F32) Point3Transform2_F32(boofcv.struct.distort.Point3Transform2_F32) Test(org.junit.Test)

Aggregations

Point2Transform3_F32 (boofcv.struct.distort.Point2Transform3_F32)4 Point2D_F32 (georegression.struct.point.Point2D_F32)4 Point3D_F32 (georegression.struct.point.Point3D_F32)4 Point3Transform2_F32 (boofcv.struct.distort.Point3Transform2_F32)3 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)2 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)2 GrayF32 (boofcv.struct.image.GrayF32)2 Test (org.junit.Test)2 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)1 UtilVector3D_F32 (georegression.geometry.UtilVector3D_F32)1 Vector3D_F32 (georegression.struct.point.Vector3D_F32)1