1

I want to creating an affine transform such that after the transform happens the image is still centered around the blue dot, and the top red dot is 45% from the top of the image, and the bottom red dot is 25% from the bottom of the image here is an example:enter image description here

This is what I currently have right now: enter image description here

To do the affine transform I setup the source and destination points like so:

src = [[231, 281],[283,243],[285,379]] # blue dot, top red dot, bottom red dot
dst = [[231, 281], [283, 243*0.45], [285, 379 * 0.75]]

And found the transformation matrix:

M = cv2.getAffineTransform(src, dst)

But when I printed out the matrix I got this:

M = [[   1.           -0.            0.        ]
    [  -2.33606605    1.32038334  449.60354104]]

Which is obviously wrong as the -2.336 appearing in M[1,0] means that the transformation matrix is sheering in the y-direction, therefore it was no surprise that my image ended up like this:

enter image description here

My question is what am I doing wrong? Am I picking the wrong points to define the affine transform?

EDIT: After trying the suggestion by @Miki this was the result enter image description here

YellowPillow
  • 4,100
  • 6
  • 31
  • 57
  • 1
    This is wierd because you told it to be wierd, Use `dst = [[231, 281], [283, image_height*0.45], [285, image_height * 0.75]]` – Miki Mar 29 '17 at 11:44
  • Updated my question, it still isn't what is desired but it does look better! Any other suggestions? – YellowPillow Mar 29 '17 at 11:55
  • You need to move also the blue point.. now it is still in the same position. In general, you should use more points (all landmarks maybe?) and fix a destination position (relative to image size) – Miki Mar 29 '17 at 11:56
  • The only destination points that I know are the three points (the blue one which is the mean coordinates of the most left and most right facial landmarks, and the two red ones), so how would I use all the landmarks? Also since I want the blue point to be the center of the image, wouldn't the blue point have to be the same coordinates? Thanks for your help! – YellowPillow Mar 29 '17 at 12:07
  • Why aren't you change the X (first) coordinates in the dst vectors? –  Mar 29 '17 at 12:34
  • Because I want the X coordinates to stay in the same place, the only thing that I want to do is to scale the image so that the top red dot is 45% away from the top of the image and the bottom red dot is 75% away from the bottom of the image – YellowPillow Mar 29 '17 at 12:37

0 Answers0