Search in sources :

Example 6 with PointToPixelTransform_F32

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

the class CalibrationDetectorCircleHexagonalGrid method setLensDistortion.

@Override
public void setLensDistortion(@Nullable LensDistortionNarrowFOV distortion, int width, int height) {
    if (distortion == null)
        detector.getEllipseDetector().setLensDistortion(null, null);
    else {
        Point2Transform2_F32 pointDistToUndist = distortion.undistort_F32(true, true);
        Point2Transform2_F32 pointUndistToDist = distortion.distort_F32(true, true);
        PixelTransform<Point2D_F32> distToUndist = new PointToPixelTransform_F32(pointDistToUndist);
        PixelTransform<Point2D_F32> undistToDist = new PointToPixelTransform_F32(pointUndistToDist);
        detector.getEllipseDetector().setLensDistortion(distToUndist, undistToDist);
    }
}
Also used : PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) Point2D_F32(georegression.struct.point.Point2D_F32) Point2Transform2_F32(boofcv.struct.distort.Point2Transform2_F32)

Example 7 with PointToPixelTransform_F32

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

the class RemoveLensDistortionApp method addUndistorted.

private void addUndistorted(final String name, final Point2Transform2_F32 model) {
    // Set up image distort
    InterpolatePixel<T> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, undist.getImageType());
    ImageDistort<T, T> undistorter = FactoryDistort.distort(false, interp, undist.getImageType());
    undistorter.setModel(new PointToPixelTransform_F32(model));
    undistorter.apply(dist, undist);
    final BufferedImage out = ConvertBufferedImage.convertTo(undist, null, true);
    // Add this rectified image
    SwingUtilities.invokeLater(() -> gui.addItem(new ImagePanel(out), name));
}
Also used : PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ImagePanel(boofcv.gui.image.ImagePanel)

Example 8 with PointToPixelTransform_F32

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

the class FisheyePinholeApp method processImage.

@Override
public void processImage(int sourceID, long frameID, BufferedImage buffered, ImageBase input) {
    synchronized (imageLock) {
        // create a copy of the input image for output purposes
        if (buffFisheye.getWidth() != buffered.getWidth() || buffFisheye.getHeight() != buffered.getHeight()) {
            buffFisheye = new BufferedImage(buffered.getWidth(), buffered.getHeight(), BufferedImage.TYPE_INT_BGR);
            panelFisheye.setPreferredSize(new Dimension(buffered.getWidth(), buffered.getHeight()));
            panelFisheye.setImageUI(buffFisheye);
            distortImage.setModel(new PointToPixelTransform_F32(distorter));
        }
        buffFisheye.createGraphics().drawImage(buffered, 0, 0, null);
        fisheye.setTo((T) input);
        rerenderPinhole();
    }
}
Also used : PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Example 9 with PointToPixelTransform_F32

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

the class ExampleFisheyeToPinhole method main.

public static void main(String[] args) {
    // Path to image data and calibration data
    String fisheyePath = UtilIO.pathExample("fisheye/theta/");
    // load the fisheye camera parameters
    CameraUniversalOmni fisheyeModel = CalibrationIO.load(new File(fisheyePath, "front.yaml"));
    // Specify what the pinhole camera should look like
    CameraPinhole pinholeModel = new CameraPinhole(400, 400, 0, 300, 300, 600, 600);
    // Create the transform from pinhole to fisheye views
    LensDistortionNarrowFOV pinholeDistort = new LensDistortionPinhole(pinholeModel);
    LensDistortionWideFOV fisheyeDistort = new LensDistortionUniversalOmni(fisheyeModel);
    NarrowToWidePtoP_F32 transform = new NarrowToWidePtoP_F32(pinholeDistort, fisheyeDistort);
    // Load fisheye RGB image
    BufferedImage bufferedFisheye = UtilImageIO.loadImage(fisheyePath, "front_table.jpg");
    Planar<GrayU8> fisheyeImage = ConvertBufferedImage.convertFrom(bufferedFisheye, true, ImageType.pl(3, GrayU8.class));
    // Create the image distorter which will render the image
    InterpolatePixel<Planar<GrayU8>> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, BorderType.ZERO, fisheyeImage.getImageType());
    ImageDistort<Planar<GrayU8>, Planar<GrayU8>> distorter = FactoryDistort.distort(false, interp, fisheyeImage.getImageType());
    // Pass in the transform created above
    distorter.setModel(new PointToPixelTransform_F32(transform));
    // Render the image. The camera will have a rotation of 0 and will thus be looking straight forward
    Planar<GrayU8> pinholeImage = fisheyeImage.createNew(pinholeModel.width, pinholeModel.height);
    distorter.apply(fisheyeImage, pinholeImage);
    BufferedImage bufferedPinhole0 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // rotate the virtual pinhole camera to the right
    transform.setRotationWideToNarrow(ConvertRotation3D_F32.eulerToMatrix(EulerType.YXZ, 0.8f, 0, 0, null));
    distorter.apply(fisheyeImage, pinholeImage);
    BufferedImage bufferedPinhole1 = ConvertBufferedImage.convertTo(pinholeImage, null, true);
    // Display the results
    ListDisplayPanel panel = new ListDisplayPanel();
    panel.addImage(bufferedPinhole0, "Pinehole Forward");
    panel.addImage(bufferedPinhole1, "Pinehole Right");
    panel.addImage(bufferedFisheye, "Fisheye");
    panel.setPreferredSize(new Dimension(600, 450));
    ShowImages.showWindow(panel, "Fisheye to Pinhole", true);
}
Also used : LensDistortionPinhole(boofcv.alg.distort.pinhole.LensDistortionPinhole) ListDisplayPanel(boofcv.gui.ListDisplayPanel) LensDistortionNarrowFOV(boofcv.alg.distort.LensDistortionNarrowFOV) LensDistortionWideFOV(boofcv.alg.distort.LensDistortionWideFOV) NarrowToWidePtoP_F32(boofcv.alg.distort.NarrowToWidePtoP_F32) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) CameraUniversalOmni(boofcv.struct.calib.CameraUniversalOmni) PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) Planar(boofcv.struct.image.Planar) GrayU8(boofcv.struct.image.GrayU8) LensDistortionUniversalOmni(boofcv.alg.distort.universal.LensDistortionUniversalOmni) File(java.io.File)

Example 10 with PointToPixelTransform_F32

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

the class ExamplePointDeformKeyPoints method main.

public static void main(String[] args) {
    BufferedImage orig = UtilImageIO.loadImageNotNull(UtilIO.pathExample("standard/man_mls.jpg"));
    var bufferedOut = new BufferedImage(orig.getWidth(), orig.getHeight(), BufferedImage.TYPE_INT_RGB);
    Planar<GrayF32> input = ConvertBufferedImage.convertFrom(orig, true, ImageType.pl(3, GrayF32.class));
    Planar<GrayF32> output = input.createSameShape();
    var src = new ArrayList<Point2D_F32>();
    var dst = new ArrayList<Point2D_F32>();
    src.add(new Point2D_F32(64, 241));
    src.add(new Point2D_F32(266, 119));
    src.add(new Point2D_F32(265, 240));
    src.add(new Point2D_F32(208, 410));
    src.add(new Point2D_F32(181, 536));
    src.add(new Point2D_F32(335, 409));
    src.add(new Point2D_F32(375, 531));
    src.add(new Point2D_F32(473, 238));
    for (Point2D_F32 p : src) {
        dst.add(p.copy());
    }
    var config = new ConfigDeformPointMLS();
    PointDeformKeyPoints deform = FactoryDistort.deformMls(config);
    deform.setImageShape(input.width, input.height);
    ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distorter = FactoryDistort.distort(true, InterpolationType.BILINEAR, BorderType.ZERO, input.getImageType(), input.getImageType());
    deform.setImageShape(input.width, input.height);
    deform.setSource(src);
    deform.setDestination(dst);
    ConvertBufferedImage.convertTo(output, bufferedOut, true);
    ImagePanel panel = ShowImages.showWindow(bufferedOut, "Point Based Distortion Animation", true);
    int count = 0;
    while (true) {
        // specify new locations of key points
        double theta = count++ * Math.PI / 30;
        // right arm
        dst.get(7).y = (float) (238 + Math.sin(theta) * 30);
        // left arm
        dst.get(0).y = (float) (241 - Math.sin(theta * 2.0) * 20);
        // head
        dst.get(1).x = (float) (266 + Math.sin(theta * 0.25) * 10);
        // tell the deformation algorithm that destination points have changed
        deform.setDestination(dst);
        // Tell the distorter that the model has changed. If cached is set to false you can ignore this step
        distorter.setModel(new PointToPixelTransform_F32(deform));
        // distort the image
        distorter.apply(input, output);
        // Show the results
        ConvertBufferedImage.convertTo(output, bufferedOut, true);
        panel.repaint();
        BoofMiscOps.sleep(30);
    }
}
Also used : ArrayList(java.util.ArrayList) PointDeformKeyPoints(boofcv.abst.distort.PointDeformKeyPoints) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigDeformPointMLS(boofcv.abst.distort.ConfigDeformPointMLS) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.struct.distort.PointToPixelTransform_F32) Planar(boofcv.struct.image.Planar) Point2D_F32(georegression.struct.point.Point2D_F32) ImagePanel(boofcv.gui.image.ImagePanel)

Aggregations

PointToPixelTransform_F32 (boofcv.struct.distort.PointToPixelTransform_F32)17 Point2Transform2_F32 (boofcv.struct.distort.Point2Transform2_F32)8 Point2D_F32 (georegression.struct.point.Point2D_F32)7 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)5 BufferedImage (java.awt.image.BufferedImage)5 LensDistortionPinhole (boofcv.alg.distort.pinhole.LensDistortionPinhole)3 Planar (boofcv.struct.image.Planar)3 LensDistortionNarrowFOV (boofcv.alg.distort.LensDistortionNarrowFOV)2 NarrowToWidePtoP_F32 (boofcv.alg.distort.NarrowToWidePtoP_F32)2 ImagePanel (boofcv.gui.image.ImagePanel)2 FMatrixRMaj (org.ejml.data.FMatrixRMaj)2 ConfigDeformPointMLS (boofcv.abst.distort.ConfigDeformPointMLS)1 PointDeformKeyPoints (boofcv.abst.distort.PointDeformKeyPoints)1 LensDistortionWideFOV (boofcv.alg.distort.LensDistortionWideFOV)1 PointTransformHomography_F32 (boofcv.alg.distort.PointTransformHomography_F32)1 LensDistortionUniversalOmni (boofcv.alg.distort.universal.LensDistortionUniversalOmni)1 InterpolatePixelS (boofcv.alg.interpolate.InterpolatePixelS)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 CameraPinhole (boofcv.struct.calib.CameraPinhole)1 CameraUniversalOmni (boofcv.struct.calib.CameraUniversalOmni)1