use of boofcv.alg.distort.PixelTransformHomography_F32 in project BoofCV by lessthanoptimal.
the class ExampleImageStitching method renderStitching.
/**
* Renders and displays the stitched together images
*/
public static void renderStitching(BufferedImage imageA, BufferedImage imageB, Homography2D_F64 fromAtoB) {
// specify size of output image
double scale = 0.5;
// Convert into a BoofCV color format
Planar<GrayF32> colorA = ConvertBufferedImage.convertFromPlanar(imageA, null, true, GrayF32.class);
Planar<GrayF32> colorB = ConvertBufferedImage.convertFromPlanar(imageB, null, true, GrayF32.class);
// Where the output images are rendered into
Planar<GrayF32> work = colorA.createSameShape();
// Adjust the transform so that the whole image can appear inside of it
Homography2D_F64 fromAToWork = new Homography2D_F64(scale, 0, colorA.width / 4, 0, scale, colorA.height / 4, 0, 0, 1);
Homography2D_F64 fromWorkToA = fromAToWork.invert(null);
// Used to render the results onto an image
PixelTransformHomography_F32 model = new PixelTransformHomography_F32();
InterpolatePixelS<GrayF32> interp = FactoryInterpolation.bilinearPixelS(GrayF32.class, BorderType.ZERO);
ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distort = DistortSupport.createDistortPL(GrayF32.class, model, interp, false);
distort.setRenderAll(false);
// Render first image
model.set(fromWorkToA);
distort.apply(colorA, work);
// Render second image
Homography2D_F64 fromWorkToB = fromWorkToA.concat(fromAtoB, null);
model.set(fromWorkToB);
distort.apply(colorB, work);
// Convert the rendered image into a BufferedImage
BufferedImage output = new BufferedImage(work.width, work.height, imageA.getType());
ConvertBufferedImage.convertTo(work, output, true);
Graphics2D g2 = output.createGraphics();
// draw lines around the distorted image to make it easier to see
Homography2D_F64 fromBtoWork = fromWorkToB.invert(null);
Point2D_I32[] corners = new Point2D_I32[4];
corners[0] = renderPoint(0, 0, fromBtoWork);
corners[1] = renderPoint(colorB.width, 0, fromBtoWork);
corners[2] = renderPoint(colorB.width, colorB.height, fromBtoWork);
corners[3] = renderPoint(0, colorB.height, fromBtoWork);
g2.setColor(Color.ORANGE);
g2.setStroke(new BasicStroke(4));
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
g2.drawLine(corners[0].x, corners[0].y, corners[1].x, corners[1].y);
g2.drawLine(corners[1].x, corners[1].y, corners[2].x, corners[2].y);
g2.drawLine(corners[2].x, corners[2].y, corners[3].x, corners[3].y);
g2.drawLine(corners[3].x, corners[3].y, corners[0].x, corners[0].y);
ShowImages.showWindow(output, "Stitched Images", true);
}
use of boofcv.alg.distort.PixelTransformHomography_F32 in project BoofCV by lessthanoptimal.
the class UtilImageMotion method createPixelTransform.
/**
* Given a motion model create a PixelTransform used to distort the image
*
* @param transform Motion transform
* @return PixelTransform_F32 used to distort the image
*/
public static PixelTransform2_F32 createPixelTransform(InvertibleTransform transform) {
PixelTransform2_F32 pixelTran;
if (transform instanceof Homography2D_F64) {
Homography2D_F32 t = ConvertFloatType.convert((Homography2D_F64) transform, null);
pixelTran = new PixelTransformHomography_F32(t);
} else if (transform instanceof Homography2D_F32) {
pixelTran = new PixelTransformHomography_F32((Homography2D_F32) transform);
} else if (transform instanceof Affine2D_F64) {
Affine2D_F32 t = UtilAffine.convert((Affine2D_F64) transform, null);
pixelTran = new PixelTransformAffine_F32(t);
} else if (transform instanceof Affine2D_F32) {
pixelTran = new PixelTransformAffine_F32((Affine2D_F32) transform);
} else {
throw new RuntimeException("Unknown model type");
}
return pixelTran;
}
Aggregations