Search in sources :

Example 1 with PixelTransformHomography_F32

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);
}
Also used : PixelTransformHomography_F32(boofcv.alg.distort.PixelTransformHomography_F32) Homography2D_F64(georegression.struct.homography.Homography2D_F64) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) GrayF32(boofcv.struct.image.GrayF32) Planar(boofcv.struct.image.Planar) Point2D_I32(georegression.struct.point.Point2D_I32)

Example 2 with PixelTransformHomography_F32

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;
}
Also used : Affine2D_F64(georegression.struct.affine.Affine2D_F64) Affine2D_F32(georegression.struct.affine.Affine2D_F32) PixelTransformHomography_F32(boofcv.alg.distort.PixelTransformHomography_F32) Homography2D_F32(georegression.struct.homography.Homography2D_F32) PixelTransformAffine_F32(boofcv.alg.distort.PixelTransformAffine_F32) Homography2D_F64(georegression.struct.homography.Homography2D_F64) PixelTransform2_F32(boofcv.struct.distort.PixelTransform2_F32)

Aggregations

PixelTransformHomography_F32 (boofcv.alg.distort.PixelTransformHomography_F32)2 Homography2D_F64 (georegression.struct.homography.Homography2D_F64)2 PixelTransformAffine_F32 (boofcv.alg.distort.PixelTransformAffine_F32)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 PixelTransform2_F32 (boofcv.struct.distort.PixelTransform2_F32)1 GrayF32 (boofcv.struct.image.GrayF32)1 Planar (boofcv.struct.image.Planar)1 Affine2D_F32 (georegression.struct.affine.Affine2D_F32)1 Affine2D_F64 (georegression.struct.affine.Affine2D_F64)1 Homography2D_F32 (georegression.struct.homography.Homography2D_F32)1 Point2D_I32 (georegression.struct.point.Point2D_I32)1 BufferedImage (java.awt.image.BufferedImage)1