Search in sources :

Example 6 with ImageDistort

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

the class ExampleRemoveLensDistortion method main.

public static void main(String[] args) {
    String calibDir = UtilIO.pathExample("calibration/mono/Sony_DSC-HX5V_Chess/");
    String imageDir = UtilIO.pathExample("structure/");
    // load calibration parameters from the previously calibrated camera
    CameraPinholeRadial param = CalibrationIO.load(new File(calibDir, "intrinsic.yaml"));
    // Specify a transform that has no lens distortion that you wish to re-render the image as having
    CameraPinhole desired = new CameraPinhole(param);
    // load images and convert the image into a color BoofCV format
    BufferedImage orig = UtilImageIO.loadImage(imageDir, "dist_cyto_01.jpg");
    Planar<GrayF32> distortedImg = ConvertBufferedImage.convertFromPlanar(orig, null, true, GrayF32.class);
    int numBands = distortedImg.getNumBands();
    // create new transforms which optimize view area in different ways.
    // EXPAND makes sure there are no black outside of image pixels inside the image
    // FULL_VIEW will include the entire original image
    // The border is VALUE, which defaults to black, just so you can see it
    ImageDistort allInside = LensDistortionOps.changeCameraModel(AdjustmentType.EXPAND, BorderType.ZERO, param, desired, null, ImageType.pl(numBands, GrayF32.class));
    ImageDistort fullView = LensDistortionOps.changeCameraModel(AdjustmentType.FULL_VIEW, BorderType.ZERO, param, desired, null, ImageType.pl(numBands, GrayF32.class));
    // NOTE: After lens distortion has been removed the intrinsic parameters is changed.  If you pass
    // in  a set of IntrinsicParameters to the 4th variable it will save it there.
    // NOTE: Type information was stripped from ImageDistort simply because it becomes too verbose with it here.
    // Would be nice if this verbosity issue was addressed by the Java language.
    // render and display the different types of views in a window
    displayResults(orig, distortedImg, allInside, fullView);
}
Also used : GrayF32(boofcv.struct.image.GrayF32) CameraPinholeRadial(boofcv.struct.calib.CameraPinholeRadial) ImageDistort(boofcv.alg.distort.ImageDistort) File(java.io.File) CameraPinhole(boofcv.struct.calib.CameraPinhole) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage)

Aggregations

ImageDistort (boofcv.alg.distort.ImageDistort)6 GrayF32 (boofcv.struct.image.GrayF32)4 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)3 BufferedImage (java.awt.image.BufferedImage)3 File (java.io.File)3 Test (org.junit.Test)3 InterpolatePixel (boofcv.alg.interpolate.InterpolatePixel)2 CameraPinhole (boofcv.struct.calib.CameraPinhole)2 CameraPinholeRadial (boofcv.struct.calib.CameraPinholeRadial)2 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)2 GrayU8 (boofcv.struct.image.GrayU8)2 AdjustmentType (boofcv.alg.distort.AdjustmentType)1 RectifyCalibrated (boofcv.alg.geo.rectify.RectifyCalibrated)1 InterpolatePixelS (boofcv.alg.interpolate.InterpolatePixelS)1 ListDisplayPanel (boofcv.gui.ListDisplayPanel)1 RectifiedPairPanel (boofcv.gui.stereo.RectifiedPairPanel)1 StereoParameters (boofcv.struct.calib.StereoParameters)1 Planar (boofcv.struct.image.Planar)1 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)1 Se3_F64 (georegression.struct.se.Se3_F64)1