2015-06-26 23 views
1

我想使用openImaj对齐我在这里使用的几个面。我想阅读一张jpg脸部照片,对齐它,最后在对齐后保存为jpg格式。这里是我卡住的地方。见下面使用openImaj API库进行面对齐

 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?

回答

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")); 
+0

谢谢@Jon的例子。我在我的java netbeans IDE 8.0平台中导入了以下类。他们是 ; 'import java.io.File; import java.io.IOException; import org.openimaj.image.FImage; import org.openimaj.image.ImageUtilities; import org.openimaj.image.processing.face.alignment.AffineAligner; import org.openimaj.image.processing.face.alignment.FaceAligner; import org.openimaj.image.processing.face.detection.keypoints.FKEFaceDetector; import org.openimaj.image.processing.face.detection.keypoints.KEDetectedFace;'但我一直在修复其他依赖关系。这是正常的吗? –

+0

我可以错过任何其他openImaj API吗?当我编译时,我没有看到任何错误,但是当我运行时,我发现一个新的类,我必须修复,当我清理并再次运行另一个类,需要我添加另一个Java API抛出异常。过去我一直这样做了5个小时,直到我认为我必须做出这样错误的事情。对于上述导入,我从1.3.1文件夹中的openImaj提供的API库中完成了它们。请推荐我可以从哪里获取最新的openImaj API库,而不是2014年9月25日的库。我会感激。 –

+0

你真的需要使用一个自动的依赖管理器 - 阅读它:http://stackoverflow.com/questions/25602141/openimaj-jar-files – Jon