title: How would I achieve this in opencv with an affine transform?
body: <p>I was wondering how I would replicate what is being done in this image:
  <a href="https://i.stack.imgur.com/mVm7S.png" rel="noreferrer"><img src="https://i.stack.imgur.com/mVm7S.png" alt="enter image description here"></a></p>
  
  <p>To break it down:</p>
  
  <ol>
  <li>Get facial landmarks using dlib (green dots)</li>
  <li>Rotate the image so that the eyes are horizontal</li>
  <li>Find the midpoint of the face by averaging the left most and right most landmarks (blue dot) and center the image on the x-axis</li>
  <li>Fix the position along the y-axis by by placing the eye center 45% from the top of the image, and the mouth center 25% from the image</li>
  </ol>
  
  <p>Right now this is what I have:
  <a href="https://i.stack.imgur.com/OE3VW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/OE3VW.png" alt="enter image description here"></a></p>
  
  <p>I am kind of stuck on step 3, which I think can be done by an affine transform? But I'm completely stumped on step 4, I have no idea how I would achieve it.</p>
  
  <p>Please tell me if you need me to provide the code!</p>
  
  <p>EDIT: So after look at @Gal Dreiman's answer I was able to center the face perfectly so that the blue dot in the the center of my image. </p>
  
  <p><a href="https://i.stack.imgur.com/DL8L4.png" rel="noreferrer"><img src="https://i.stack.imgur.com/DL8L4.png" alt="enter image description here"></a></p>
  
  <p>Although when I implemented the second part of his answer I end up getting something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/J0NhW.png" rel="noreferrer"><img src="https://i.stack.imgur.com/J0NhW.png" alt="enter image description here"></a></p>
  
  <p>I see that the points have been transformed to the right places, but it's not the outcome that I had desired as it is sheered quite dramatically. Any ideas?</p>
  
  <p><strong>EDIT 2:</strong></p>
  
  <p>After switching the x, y coordinates for the center points around, this is what I got:</p>
  
  <p><a href="https://i.stack.imgur.com/oOHen.png" rel="noreferrer"><img src="https://i.stack.imgur.com/oOHen.png" alt="enter image description here"></a></p>