首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >带openimaj的Facecrop

带openimaj的Facecrop
EN

Stack Overflow用户
提问于 2019-07-14 05:11:07
回答 1查看 208关注 0票数 0

裁剪MBFImage

我使用优秀的openimaj库1.3.8检测到一张脸,但我很难从原始图像中裁剪这张脸,并将裁剪后的脸保存到某个文件中。裁剪的面必须在800x600像素,所以我需要一些缩放以及。

这必须是一项简单的任务,但是api很庞大,我找不到适合这个用例的教程

也许你可以告诉我在哪里可以找到信息?

代码语言:javascript
复制
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;

import org.openimaj.image.DisplayUtilities;
import org.openimaj.image.FImage;
import org.openimaj.image.ImageUtilities;
import org.openimaj.image.MBFImage;
import org.openimaj.image.colour.RGBColour;
import org.openimaj.image.colour.Transforms;
import org.openimaj.image.processing.face.detection.DetectedFace;
import org.openimaj.image.processing.face.detection.FaceDetector;
import org.openimaj.image.processing.face.detection.HaarCascadeDetector;
import org.openimaj.math.geometry.shape.Rectangle;


public class App {
    public static void main(String[] args) throws Exception, IOException {


        final MBFImage image = ImageUtilities.readMBF(new File("d:\\java\\face\\bin.jpeg"));

        FaceDetector<DetectedFace, FImage> fd = new HaarCascadeDetector(200);
        List<DetectedFace> faces = fd.detectFaces(Transforms.calculateIntensity(image));
        System.out.println("# Found faces, one per line.");
        System.out.println("# <x>, <y>, <width>, <height>");

        for (Iterator<DetectedFace> iterator = faces.iterator(); iterator.hasNext();) {
            DetectedFace face = iterator.next();
            Rectangle bounds = face.getBounds();

            image.drawShape(face.getBounds(), RGBColour.RED);

            // System.out.println(bounds.x + ";" + bounds.y + ";" + bounds.width + ";" +
            // bounds.height);

        }

        DisplayUtilities.display(image);

    }
}
EN

回答 1

Stack Overflow用户

发布于 2019-07-15 02:00:59

已解决

代码语言:javascript
复制
        DetectedFace face = iterator.next();
        Rectangle bounds = face.getBounds();

        Point2d center = bounds.calculateCentroid();

        // image.drawShape(bounds, RGBColour.RED);

        // auf 800 x 600 bringen

        float b = (bounds.width * 800) / 600;

        MBFImage crop = image.extractCenter(
                (int) center.getX() , 
                (int) center.getY()  ,
                (int) bounds.width , 
                (int) b  ) ;


        ResizeProcessor resize = new ResizeProcessor(800,600);
        MBFImage small = crop.processInplace(resize);

        DisplayUtilities.display(small);
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57022871

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档