function [ H] = compute2DHomographyUsingDLT( p1,p2) %B. Vandeportaele %compute the Homography H using the DLT Algorithm for 4 2D points %correspondences such as : p2=H.p1 u11=p1(1,1);u12=p1(1,2); u13=p1(1,3);u14=p1(1,4); v11=p1(2,1);v12=p1(2,2); v13=p1(2,3);v14=p1(2,4); u21=p2(1,1);u22=p2(1,2); u23=p2(1,3);u24=p2(1,4); v21=p2(2,1);v22=p2(2,2); v23=p2(2,3);v24=p2(2,4); A=[ -u11, -v11, -1, 0, 0, 0, u11*u21, u21*v11; 0, 0, 0, -u11, -v11, -1, u11*v21, v21*v11; -u12, -v12, -1, 0, 0, 0, u12*u22, u22*v12; 0, 0, 0, -u12, -v12, -1, u12*v22, v22*v12; -u13, -v13, -1, 0, 0, 0, u13*u23, u23*v13; 0, 0, 0, -u13, -v13, -1, u13*v23, v23*v13; -u14, -v14, -1, 0, 0, 0, u14*u24, u24*v14; 0, 0, 0, -u14, -v14, -1, u14*v24, v24*v14]; B =[ -u21; -v21; -u22; -v22; -u23; -v23; -u24; -v24]; %solve A*Hv=B Hv=inv(A)*B; %reconstruct the homography matrix from the vector solution H=[Hv(1:3)';Hv(4:6)';Hv(7:8)',1]; end