[Math] Extracting perspective transformation from a 2D projection

3dgeometrytransformation

I have a 2D projection of a flat, rectangular object in 3D space, like this one:

enter image description here

I know all sorts of information about this shape—its opposite sides have the same length, the sides meet at right angles, the ratio of one side length to another. However, I don't know the details of the projection or the vertices coordinates in 3D space.

I'd like to compute the perspective transformation I'd use to, e.g., paint text over the 2D image so that it matches the camera's perspective as if it existed on the 3D model.

Best Answer

Given the four points of the transformed rectangle, you can compute 2D perspective transform by solving system of eight linear equations.

The stability of the solution depends on coordinate system, precision of point locations and distance from nearest degenerate configuration.

A method proposed by Hartley & Zisserman (Multiple-View Geometry) is thus a Normalized Direct Linear Transformation, which does preconditioning prior to solving the linear equations (the preconditioner is basically an affine transform that maps coordinates of two quadrilaterals into common frame and scale).

Note that linear solution of the problem minimizes only algebraic distance and has little geometrical meaning. Iterative solution with geometric cost function (e.g. symmetric transfer error) should be considered in presence of noise. This essay may be helpful.

You can find more under the keywords "homography estimation".