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);
}
Aggregations