简体   繁体   English

使用openImaj API库进行人脸对齐

[英]Face alignment using openImaj API libraries

I want to align several faces I have at my disposal here using openImaj. 我想使用openImaj对齐我可以使用的几个面孔。 I want to read a jpg face photo, align it and finally save it as in jpg after alignment. 我想阅读一张jpg脸部照片,将其对齐,最后在对齐后将其另存为jpg。 Here is where I am stuck. 这就是我卡住的地方。 See below 见下文

     public class FaceImageAlignment {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) throws IOException {
        // TODO code application logic here

        BufferedImage img = null;
        img = ImageIO.read(new File("D:/face_test.jpg"));

        //How to align face image using openImaj
        //This is where I am stuck on doing face alignment. I tried doing the following
        AffineAligner imgAlign = new AffineAligner();
        //but I could not figure out how to do face alignment with it



        BufferedImage imgAligned = new BufferedImage(//I will need to put aligned Image here as a BufferedImage);
        File f = new File("D:\\face_aligned.jpg");
        ImageIO.write(imgAligned, "JPEG", f);

    }
}

What Code do I need to have there to face align face_test.jpg to face_aligned.jpg ? 我需要什么代码才能将face_test.jpg与face_aligned.jpg对齐?

Aligners work in combination with face detectors, so you need to use a detector to find the face(s) and then pass that to the aligner. 对准器与面部检测器结合使用,因此您需要使用检测器来找到面部,然后将其传递给对准器。 Different aligners are tied to different detector implementations as they require different information to perform the alignment; 不同的对准器与不同的检测器实现方式绑定在一起,因为它们需要不同的信息来执行对准。 for example the affine aligner needs facial key points found by the FKEFaceDetector. 例如,仿射对齐器需要FKEFaceDetector找到的面部关键点。 Basic code looks something like this: 基本代码如下所示:

FImage img = ImageUtilities.readF(new File("..."));
FKEFaceDetector detector = new FKEFaceDetector();
FaceAligner<KEDetectedFace> aligner = new AffineAligner();
KEDetectedFace face = detector.detectFaces(img).get(0);
FImage alignedFace = aligner.align(face);
ImageUtilities.write(alignedFace, new File("aligned.jpg"));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM