Search in sources :

Example 6 with PointToPixelTransform_F32

use of boofcv.alg.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.

the class ImplRectifyImageOps_F32 method allInsideLeft.

public static void allInsideLeft(int imageWidth, int imageHeight, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight) {
    PointTransformHomography_F32 tranLeft = new PointTransformHomography_F32(rectifyLeft);
    RectangleLength2D_F32 bound = LensDistortionOps.boundBoxInside(imageWidth, imageHeight, new PointToPixelTransform_F32(tranLeft));
    float scaleX = imageWidth / (float) bound.width;
    float scaleY = imageHeight / (float) bound.height;
    float scale = (float) Math.max(scaleX, scaleY);
    adjustUncalibrated(rectifyLeft, rectifyRight, bound, scale);
}
Also used : PointTransformHomography_F32(boofcv.alg.distort.PointTransformHomography_F32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) RectangleLength2D_F32(georegression.struct.shapes.RectangleLength2D_F32)

Example 7 with PointToPixelTransform_F32

use of boofcv.alg.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.

the class ImplRectifyImageOps_F32 method allInsideLeft.

public static void allInsideLeft(CameraPinholeRadial paramLeft, FMatrixRMaj rectifyLeft, FMatrixRMaj rectifyRight, FMatrixRMaj rectifyK) {
    // need to take in account the order in which image distort will remove rectification later on
    paramLeft = new CameraPinholeRadial(paramLeft);
    Point2Transform2_F32 tranLeft = transformPixelToRect(paramLeft, rectifyLeft);
    RectangleLength2D_F32 bound = LensDistortionOps.boundBoxInside(paramLeft.width, paramLeft.height, new PointToPixelTransform_F32(tranLeft));
    LensDistortionOps.roundInside(bound);
    float scaleX = paramLeft.width / (float) bound.width;
    float scaleY = paramLeft.height / (float) bound.height;
    float scale = (float) Math.max(scaleX, scaleY);
    adjustCalibrated(rectifyLeft, rectifyRight, rectifyK, bound, scale);
}
Also used : CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) RectangleLength2D_F32(georegression.struct.shapes.RectangleLength2D_F32) SequencePoint2Transform2_F32(boofcv.struct.distort.SequencePoint2Transform2_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Example 8 with PointToPixelTransform_F32

use of boofcv.alg.distort.PointToPixelTransform_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 9 with PointToPixelTransform_F32

use of boofcv.alg.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.

the class RenderSyntheticCamerModelApp method updatedPinholeModel.

@Override
public synchronized void updatedPinholeModel(CameraPinholeRadial desired) {
    if (undist.width != desired.width || undist.height != desired.height) {
        undist.reshape(desired.width, desired.height);
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                gui.setPreferredSize(new Dimension(undist.width, undist.height));
            // gui.invalidate();
            }
        });
    }
    Point2Transform2_F32 add_p_to_p = LensDistortionOps.transformChangeModel_F32(adjustment, origModel, desired, true, null);
    undistorter.setModel(new PointToPixelTransform_F32(add_p_to_p));
    if (inputMethod == InputMethod.IMAGE)
        renderCameraModel();
}
Also used : PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Example 10 with PointToPixelTransform_F32

use of boofcv.alg.distort.PointToPixelTransform_F32 in project BoofCV by lessthanoptimal.

the class FisheyePinholeApp method updatedPinholeModel.

@Override
public void updatedPinholeModel(int width, int height, double fov) {
    final boolean shapeChanged = camWidth != width || camHeight != height;
    this.camWidth = width;
    this.camHeight = height;
    this.hfov = fov;
    synchronized (imageLock) {
        if (shapeChanged) {
            panelPinhole.setPreferredSize(new Dimension(camWidth, camHeight));
            pinhole.reshape(camWidth, camHeight);
            buffPinhole = new BufferedImage(camWidth, camHeight, BufferedImage.TYPE_INT_BGR);
        }
        updateIntrinsic();
        distorter.configure(new LensDistortionPinhole(cameraModel), fisheyeDistort);
        distortImage.setModel(new PointToPixelTransform_F32(distorter));
        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                if (shapeChanged) {
                    panelPinhole.setPreferredSize(new Dimension(camWidth, camHeight));
                    panelPinhole.setMinimumSize(new Dimension(camWidth, camHeight));
                    panelPinhole.setMaximumSize(new Dimension(camWidth, camHeight));
                    imageView.setDividerLocation(-1);
                }
            }
        });
        if (inputMethod == InputMethod.IMAGE) {
            rerenderPinhole();
        }
    }
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)14 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)5 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)4 RectangleLength2D_F32 (georegression.struct.shapes.RectangleLength2D_F32)4 BufferedImage (java.awt.image.BufferedImage)4 PointTransformHomography_F32 (boofcv.alg.distort.PointTransformHomography_F32)3 SequencePoint2Transform2_F32 (boofcv.struct.distort.SequencePoint2Transform2_F32)3 GrayF32 (boofcv.struct.image.GrayF32)3 Point2D_F32 (georegression.struct.point.Point2D_F32)3 PixelTransformCached_F32 (boofcv.alg.distort.PixelTransformCached_F32)2 ImagePanel (boofcv.gui.image.ImagePanel)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 Point2Transform3_F32 (boofcv.struct.distort.Point2Transform3_F32)2 Point3Transform2_F32 (boofcv.struct.distort.Point3Transform2_F32)2 Point3D_F32 (georegression.struct.point.Point3D_F32)2 ConfigDeformPointMLS (boofcv.abst.distort.ConfigDeformPointMLS)1 PointDeformKeyPoints (boofcv.abst.distort.PointDeformKeyPoints)1 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)1 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)1 Point2Transform2_F64 (boofcv.struct.distort.Point2Transform2_F64)1