use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class RectifyImageOps 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(CameraPinholeRadial 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 = 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 TestRectifyImageOps method transform_PixelToRect_and_RectToPixel_F32.
/**
* Transforms and then performs the inverse transform to distorted rectified pixel
*/
@Test
public void transform_PixelToRect_and_RectToPixel_F32() {
CameraPinholeRadial param = new CameraPinholeRadial().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 1e-4);
FMatrixRMaj rect = new FMatrixRMaj(3, 3, true, 1.1f, 0, 0, 0, 2, 0, 0.1f, 0, 3);
Point2Transform2_F32 forward = RectifyImageOps.transformPixelToRect(param, rect);
Point2Transform2_F32 inverse = RectifyImageOps.transformRectToPixel(param, rect);
float x = 20, y = 30;
Point2D_F32 out = new Point2D_F32();
forward.compute(x, y, out);
// sanity check
assertTrue(Math.abs(x - out.x) > 1e-4);
assertTrue(Math.abs(y - out.y) > 1e-4);
inverse.compute(out.x, out.y, out);
assertEquals(x, out.x, 1e-4);
assertEquals(y, out.y, 1e-4);
}
use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class TestLensDistortionOps method transformChangeModel_F32_FULLVIEW_modified.
/**
* Checks to see if the returned modified model is correct
*/
@Test
public void transformChangeModel_F32_FULLVIEW_modified() {
// distorted pixel in original image
float pixelX = 12.5f, pixelY = height - 3;
CameraPinholeRadial orig = new CameraPinholeRadial().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 0.05);
CameraPinhole desired = new CameraPinhole(orig);
Point2Transform2_F32 distToNorm = LensDistortionOps.narrow(orig).undistort_F32(true, false);
Point2D_F32 norm = new Point2D_F32();
distToNorm.compute(pixelX, pixelY, norm);
CameraPinholeRadial adjusted = new CameraPinholeRadial();
Point2Transform2_F32 distToAdj = LensDistortionOps.transformChangeModel_F32(AdjustmentType.FULL_VIEW, orig, desired, false, adjusted);
Point2D_F32 adjPixel = new Point2D_F32();
Point2D_F32 normFound = new Point2D_F32();
distToAdj.compute(pixelX, pixelY, adjPixel);
PerspectiveOps.convertPixelToNorm(adjusted, adjPixel, normFound);
// see if the normalized image coordinates are the same
assertEquals(norm.x, normFound.x, 1e-3);
assertEquals(norm.y, normFound.y, 1e-3);
}
use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class TestLensDistortionOps method transformChangeModel_F32_NONE_modified.
@Test
public void transformChangeModel_F32_NONE_modified() {
// distorted pixel in original image
float pixelX = 12.5f, pixelY = height - 3;
CameraPinholeRadial orig = new CameraPinholeRadial().fsetK(300, 320, 0, 150, 130, width, height).fsetRadial(0.1, 0.05);
CameraPinhole desired = new CameraPinhole(orig);
Point2Transform2_F32 distToNorm = LensDistortionOps.narrow(orig).undistort_F32(true, false);
Point2D_F32 norm = new Point2D_F32();
distToNorm.compute(pixelX, pixelY, norm);
CameraPinhole adjusted = new CameraPinhole();
Point2Transform2_F32 distToAdj = LensDistortionOps.transformChangeModel_F32(AdjustmentType.NONE, orig, desired, false, adjusted);
Point2D_F32 adjPixel = new Point2D_F32();
Point2D_F32 normFound = new Point2D_F32();
distToAdj.compute(pixelX, pixelY, adjPixel);
PerspectiveOps.convertPixelToNorm(adjusted, adjPixel, normFound);
// see if the normalized image coordinates are the same
assertEquals(norm.x, normFound.x, 1e-3);
assertEquals(norm.y, normFound.y, 1e-3);
}
use of boofcv.struct.distort.Point2Transform2_F32 in project BoofCV by lessthanoptimal.
the class GeneralLensDistortionNarrowFOVChecks method forwardsBackwards_F32.
@Test
public 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);
}
}
Aggregations