1

I want to align several faces I have at my disposal here using openImaj. I want to read a jpg face photo, align it and finally save it as in jpg after alignment. 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 ?

Dhanuka
  • 2,826
  • 5
  • 27
  • 38
Joseph
  • 789
  • 1
  • 9
  • 23

1 Answers1

2

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. 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"));
Jon
  • 841
  • 4
  • 5
  • Thank you @Jon for your example. I have imported the following classes in my java netbeans IDE 8.0 platform. They are ; '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;' but I keep on fixing other dependencies. Is that normal? – Joseph Jun 27 '15 at 10:40
  • Could I be missing any other openImaj API? When I build I do not see any errors but when I run, I find a new class that I must fix, when I clean and run again another class that needs me to add another java API throws an exception. I have been doing that for the past like 5 hours until I thought I must be doing something so wrong. For the above imports, I did them from openImaj provided API libraries in 1.3.1 folder. Please recommend where I can source for the latest openImaj API libraries other than the ones for 25-Sep-2014 if at all that is where I am going wrong. I will appreciate. – Joseph Jun 27 '15 at 10:47
  • You really need to use an automated dependency manager - read this: http://stackoverflow.com/questions/25602141/openimaj-jar-files – Jon Jun 28 '15 at 07:54