Why does an affine transform work only on three of the corners? I am trying to use a linear transformation to straighten out the camera angle on this image:



In other words, I want to transform the image into a head-on view of the whiteboard.

I applied an affine transformation to that image, identifying the top left, top right, and bottom left corners, thinking that it would turn the image into a 1080x720 rectangle. However, here's what I ended up with:



As you can see, it is NOT a rectangle, but some sort of misshapen quadrilateral. It's close, but not exactly a head-on view of the whiteboard!

What exactly happened here? I really thought an affine transformation would work.
An affine transformation doesn't have enough freedom to do what you want. Affine transforms can be constructed to map any triangle to any other triangle, but they can't map any quadrilateral to any other quadrilateral.

One way to see this is that the matrix for a 2D affine transform has only 6 free coefficients. That's enough to specify what it does to 3 points, but not 4.

For this task you likely want a projective transformation. A 2D projective transformation has enough freedom to map any convex quadrilateral to any other.