Search in sources :

Example 1 with ConfigDeformPointMLS

use of boofcv.abst.distort.ConfigDeformPointMLS in project BoofCV by lessthanoptimal.

the class ExamplePointDeformKeyPoints method main.

public static void main(String[] args) {
    BufferedImage orig = UtilImageIO.loadImage(UtilIO.pathExample("standard/man_mls.jpg"));
    BufferedImage bufferedOut = new BufferedImage(orig.getWidth(), orig.getHeight(), BufferedImage.TYPE_INT_RGB);
    Planar<GrayF32> input = ConvertBufferedImage.convertFrom(orig, true, ImageType.pl(3, GrayF32.class));
    Planar<GrayF32> output = input.createSameShape();
    List<Point2D_F32> src = new ArrayList<>();
    List<Point2D_F32> dst = new ArrayList<>();
    src.add(new Point2D_F32(64, 241));
    src.add(new Point2D_F32(266, 119));
    src.add(new Point2D_F32(265, 240));
    src.add(new Point2D_F32(208, 410));
    src.add(new Point2D_F32(181, 536));
    src.add(new Point2D_F32(335, 409));
    src.add(new Point2D_F32(375, 531));
    src.add(new Point2D_F32(473, 238));
    for (Point2D_F32 p : src) {
        dst.add(p.copy());
    }
    ConfigDeformPointMLS config = new ConfigDeformPointMLS();
    PointDeformKeyPoints deform = FactoryDistort.deformMls(config);
    deform.setImageShape(input.width, input.height);
    ImageDistort<Planar<GrayF32>, Planar<GrayF32>> distorter = FactoryDistort.distort(true, InterpolationType.BILINEAR, BorderType.ZERO, input.getImageType(), input.getImageType());
    deform.setImageShape(input.width, input.height);
    deform.setSource(src);
    deform.setDestination(dst);
    ConvertBufferedImage.convertTo(output, bufferedOut, true);
    ImagePanel panel = ShowImages.showWindow(bufferedOut, "Point Based Distortion Animation", true);
    int count = 0;
    while (true) {
        // specify new locations of key points
        double theta = count++ * Math.PI / 30;
        // right arm
        dst.get(7).y = (float) (238 + Math.sin(theta) * 30);
        // left arm
        dst.get(0).y = (float) (241 - Math.sin(theta * 2.0) * 20);
        // head
        dst.get(1).x = (float) (266 + Math.sin(theta * 0.25) * 10);
        // tell the deformation algorithm that destination points have changed
        deform.setDestination(dst);
        // Tell the distorter that the model has changed. If cached is set to false you can ignore this step
        distorter.setModel(new PointToPixelTransform_F32(deform));
        // distort the image
        distorter.apply(input, output);
        // Show the results
        ConvertBufferedImage.convertTo(output, bufferedOut, true);
        panel.repaint();
        BoofMiscOps.sleep(30);
    }
}
Also used : ArrayList(java.util.ArrayList) PointDeformKeyPoints(boofcv.abst.distort.PointDeformKeyPoints) BufferedImage(java.awt.image.BufferedImage) ConvertBufferedImage(boofcv.io.image.ConvertBufferedImage) ConfigDeformPointMLS(boofcv.abst.distort.ConfigDeformPointMLS) GrayF32(boofcv.struct.image.GrayF32) PointToPixelTransform_F32(boofcv.alg.distort.PointToPixelTransform_F32) Planar(boofcv.struct.image.Planar) Point2D_F32(georegression.struct.point.Point2D_F32) ImagePanel(boofcv.gui.image.ImagePanel)

Example 2 with ConfigDeformPointMLS

use of boofcv.abst.distort.ConfigDeformPointMLS in project BoofCV by lessthanoptimal.

the class FactoryDistort method deformMls.

public static PointDeformKeyPoints deformMls(ConfigDeformPointMLS config) {
    if (config == null)
        config = new ConfigDeformPointMLS();
    ImageDeformPointMLS_F32 alg = new ImageDeformPointMLS_F32(config.type);
    alg.setAlpha(config.alpha);
    return new PointDeform_MLS(alg, config.rows, config.cols);
}
Also used : ConfigDeformPointMLS(boofcv.abst.distort.ConfigDeformPointMLS) ImageDeformPointMLS_F32(boofcv.alg.distort.mls.ImageDeformPointMLS_F32) PointDeform_MLS(boofcv.abst.distort.PointDeform_MLS)

Aggregations

ConfigDeformPointMLS (boofcv.abst.distort.ConfigDeformPointMLS)2 PointDeformKeyPoints (boofcv.abst.distort.PointDeformKeyPoints)1 PointDeform_MLS (boofcv.abst.distort.PointDeform_MLS)1 PointToPixelTransform_F32 (boofcv.alg.distort.PointToPixelTransform_F32)1 ImageDeformPointMLS_F32 (boofcv.alg.distort.mls.ImageDeformPointMLS_F32)1 ImagePanel (boofcv.gui.image.ImagePanel)1 ConvertBufferedImage (boofcv.io.image.ConvertBufferedImage)1 GrayF32 (boofcv.struct.image.GrayF32)1 Planar (boofcv.struct.image.Planar)1 Point2D_F32 (georegression.struct.point.Point2D_F32)1 BufferedImage (java.awt.image.BufferedImage)1 ArrayList (java.util.ArrayList)1