TITLE: How to compute homography matrix H from corresponding points (2d-2d planar Homography)
QUESTION [38 upvotes]: I went through this thread
Mapping Irregular Quadrilateral to a Rectangle
If i know the 4 corresponding points in image say 
p1->p1'
p2->p2'
p3->p3'
p4->p4'
then how to compute pi(x,y) from pi'(x,y)


i don't know how to compute elements in Homography matrix H from those 8 known points
[x']= [h11 h12 h13]  [x]
[y']= [h21 h22 h23]  [y]
[(1)]=[h31 h32 (1)] [(1)]
[Excuse me. I am not sure if I should extend this question, or create a new one, since I can't post comments on threads]
I want to ask the same question, but using absolute values so I can visualize it.
Lets say my points on the image plane are:
p[0] = x:407 y:253
p[1] = x:386 y:253
p[2] = x:406 y:232
p[3] = x:385 y:232

these points are in a 500px width x 333px height image plane with 0,0 at top left corner. These points represents a picture of a real plane where a 30mm side square are located. Assuming this picture was taken by a fixed camera at origin heading Z axis.
So, I know the physical distance between p0,p1 ; p0,p2 ; p1,p3; p2,p3 are 30mm. 
But is it possible to get the X,Y,Z from each of these points using only this information above?

REPLY [8 votes]: Rather than taking SVD of the system, there is an easier way to solve this. since the last component in the $H$ vector is considered as $1$, we can add one more constraint equation $(h9=1)$ (since $h_{33}$ is considered $1$) to this set and convert $P$ matrix into $9\times 9$ matrix and system will become non-homogenous.
$PH = \begin{bmatrix}
-x_1 & -y_1 & -1 & 0 & 0 & 0 & x_1x_1' & y_1x_1' & x_1' \\
0 & 0 & 0 & -x_1 & -y_1 & -1 & x_1y_1' & y_1y_1' & y_1' \\
-x_2 & -y_2 & -1 & 0 & 0 & 0 & x_2x_2' & y_2x_2' & x_2' \\
0 & 0 & 0 & -x_2 & -y_2 & -1 & x_2y_2' & y_2y_2' & y_2' \\
-x_3 & -y_3 & -1 & 0 & 0 & 0 & x_3x_3' & y_3x_3' & x_3' \\
0 & 0 & 0 & -x_3 & -y_3 & -1 & x_3y_3' & y_3y_3' & y_3' \\
-x_4 & -y_4 & -1 & 0 & 0 & 0 & x_4x_4' & y_4x_4' & x_4' \\
0 & 0 & 0 & -x_4 & -y_4 & -1 & x_4y_4' & y_4y_4' & y_4' \\
0 & 0 & 0 & 0 & 0 & 0 & 0 & 0 & 1\\
\end{bmatrix} \begin{bmatrix}h1 \\ h2 \\ h3 \\ h4 \\ h5 \\ h6 \\ h7 \\ h8 \\h9 \end{bmatrix} = \begin{bmatrix}0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\ 0 \\1 \end{bmatrix}$
This is a $Ax=b$ kind of problem which can be solved much faster than computing SVD.