Search code examples
c++opencvface-detectionface-recognition

How to align face images c++ opencv


I am developing a C++ application for face authentication. First, I have to detect the face and pre-process the image.

  1. For face detection I have used the HaarCascadeClassifier. The problem is that the this tool or this algorithm gives me a facial region detected by a little bit large rectangle that englobes hair and some of the background. Is there a solution to change the dimension of this rectangle? I used "frontalfacecascaadclassifier.xml".
  2. For face pre-processing i want to do face alignment exactly like this technique. How would I go about accomplishing this?

Solution

  • Can't you then use another Haar classifier to find each eye (eyes are very easy to find) then assuming the person has two eyes and we define a 'level' face to mean the eyes are horizontal.

    Simply measure the anlge between the two eyes and rotate the image by that angle.

    angle = atan ( eye1.Y - eye2.Y ) / (eye1.X - eye2.X )