use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class CalibrationDetectorSquareGrid method setLensDistortion.
@Override
public void setLensDistortion(@Nullable LensDistortionNarrowFOV distortion, int width, int height) {
if (distortion == null)
detector.getDetectorSquare().setLensDistortion(width, height, 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.getDetectorSquare().setLensDistortion(width, height, distToUndist, undistToDist);
}
}
use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class RemoveLensDistortionApp method processImage.
@Override
public void processImage(int sourceID, long frameID, final BufferedImage buffered, ImageBase input) {
// strip away distortion parameters
CameraPinhole desired = new CameraPinhole(param);
// distorted image
dist = (T) input.clone();
// storage for undistorted image
undist = (T) input.createSameShape();
// show results and draw a horizontal line where the user clicks to see rectification easier
SwingUtilities.invokeLater(() -> {
gui.reset();
gui.addItem(new ImagePanel(buffered), "Original");
});
// add different types of adjustments
Point2Transform2_F32 add_p_to_p = LensDistortionOps_F32.transformChangeModel(AdjustmentType.NONE, param, desired, true, null);
addUndistorted("No Adjustment", add_p_to_p);
Point2Transform2_F32 expand = LensDistortionOps_F32.transformChangeModel(AdjustmentType.EXPAND, param, desired, true, null);
addUndistorted("Expand", expand);
Point2Transform2_F32 fullView = LensDistortionOps_F32.transformChangeModel(AdjustmentType.FULL_VIEW, param, desired, true, null);
addUndistorted("Full View", fullView);
Point2Transform2_F32 center = LensDistortionOps_F32.transformChangeModel(AdjustmentType.CENTER, param, desired, true, null);
addUndistorted("Center", center);
}
use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class GeneralLensDistortionNarrowFOVChecks method forwardsBackwards_F32.
@Test
void forwardsBackwards_F32() {
LensDistortionNarrowFOV alg = create();
for (int i = 0; i < 4; i++) {
boolean inputPixel = i % 2 == 0;
boolean outputPixel = i / 2 == 0;
Point2Transform2_F32 distort = alg.distort_F32(inputPixel, outputPixel);
Point2Transform2_F32 undistort = alg.undistort_F32(outputPixel, inputPixel);
float inputX, inputY, scale;
if (inputPixel) {
inputX = 21.3f;
inputY = 45.1f;
scale = 10.0f;
} else {
inputX = 0.05f;
inputY = -0.1f;
scale = 0.1f;
}
Point2D_F32 middle = new Point2D_F32();
Point2D_F32 found = new Point2D_F32();
distort.compute(inputX, inputY, middle);
undistort.compute(middle.x, middle.y, found);
assertEquals(inputX, found.x, scale * tol_F32);
assertEquals(inputY, found.y, scale * tol_F32);
}
}
use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class RectifyDistortImageOps method rectifyImage.
/**
* Creates an {@link ImageDistort} for rectifying an image given its radial distortion and
* rectification matrix.
*
* @param param Intrinsic parameters.
* @param rectify Transform for rectifying the image.
* @param imageType Type of single band image the transform is to be applied to.
* @return ImageDistort for rectifying the image.
*/
public static <T extends ImageBase<T>> ImageDistort<T, T> rectifyImage(CameraPinholeBrown param, FMatrixRMaj rectify, BorderType borderType, ImageType<T> imageType) {
boolean skip = borderType == BorderType.SKIP;
if (skip) {
borderType = BorderType.EXTENDED;
}
InterpolatePixel<T> interp = FactoryInterpolation.createPixel(0, 255, InterpolationType.BILINEAR, borderType, imageType);
// only compute the transform once
ImageDistort<T, T> ret = FactoryDistort.distort(true, interp, imageType);
ret.setRenderAll(!skip);
Point2Transform2_F32 transform = RectifyImageOps.transformRectToPixel(param, rectify);
ret.setModel(new PointToPixelTransform_F32(transform));
return ret;
}
use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class LensDistortionOps method changeCameraModel.
/**
* Creates a distortion for modifying the input image from one camera model into another camera model. If
* requested the camera model can be further modified to ensure certain visibility requirements are meet
* and the adjusted camera model will be returned.
*
* @param type How it should modify the image model to ensure visibility of pixels.
* @param borderType How the image border is handled
* @param original The original camera model
* @param desired The desired camera model
* @param modified (Optional) The desired camera model after being rescaled. Can be null.
* @param imageType Type of image.
* @return Image distortion from original camera model to the modified one.
*/
public static <T extends ImageBase<T>, O extends CameraPinhole, D extends CameraPinhole> ImageDistort<T, T> changeCameraModel(AdjustmentType type, BorderType borderType, O original, D desired, @Nullable D modified, ImageType<T> imageType) {
Class bandType = imageType.getImageClass();
boolean skip = borderType == BorderType.SKIP;
// it has to process the border at some point, so if skip is requested just skip stuff truly outside the image
if (skip)
borderType = BorderType.EXTENDED;
InterpolatePixelS interp = FactoryInterpolation.createPixelS(0, 255, InterpolationType.BILINEAR, borderType, bandType);
Point2Transform2_F32 undistToDist = LensDistortionOps_F32.transformChangeModel(type, original, desired, true, modified);
ImageDistort<T, T> distort = FactoryDistort.distort(true, interp, imageType);
distort.setModel(new PointToPixelTransform_F32(undistToDist));
distort.setRenderAll(!skip);
return distort;
}
Aggregations