1

我想使用 openImaj 对齐我在这里可以使用的几个面。我想读取一张jpg人脸照片,对齐它,最后在对齐后将它保存为jpg。这是我卡住的地方。见下文

     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);

    }
}

我需要什么代码才能将 face_test.jpg 对准 face_aligned.jpg ?

4

1 回答 1

2

对准器与面部检测器结合使用,因此您需要使用检测器来查找面部,然后将其传递给对准器。不同的对准器与不同的检测器实现相关联,因为它们需要不同的信息来执行对准;例如仿射对准器需要由 FKEFaceDetector 找到的面部关键点。基本代码如下所示:

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"));
于 2015-06-27T07:50:16.140 回答