diff options
Diffstat (limited to 'SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m')
-rwxr-xr-x | SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m new file mode 100755 index 0000000..8addf52 --- /dev/null +++ b/SD-VBS/common/toolbox/toolbox_basic/TOOLBOX_calib/UnWarpPlane.m | |||
@@ -0,0 +1,54 @@ | |||
1 | function [u_hori,u_vert] = UnWarpPlane(x1,x2,x3,x4); | ||
2 | |||
3 | % Recovers the two 3D directions of the rectangular patch x1x2x3x4 | ||
4 | % x1 is the origin point, ie any point of planar coordinate (x,y) on the | ||
5 | % rectangular patch will be projected on the image plane at: | ||
6 | % x1 + x * u_hori + y * u_vert | ||
7 | % | ||
8 | % Note: u_hori and u_vert are also the two vanishing points. | ||
9 | |||
10 | |||
11 | if nargin < 4, | ||
12 | |||
13 | x4 = x1(:,4); | ||
14 | x3 = x1(:,3); | ||
15 | x2 = x1(:,2); | ||
16 | x1 = x1(:,1); | ||
17 | |||
18 | end; | ||
19 | |||
20 | |||
21 | % Image Projection: | ||
22 | L1 = cross(x1,x2); | ||
23 | L2 = cross(x4,x3); | ||
24 | L3 = cross(x2,x3); | ||
25 | L4 = cross(x1,x4); | ||
26 | |||
27 | % Vanishing point: | ||
28 | V1 = cross(L1,L2); | ||
29 | V2 = cross(L3,L4); | ||
30 | |||
31 | % Horizon line: | ||
32 | H = cross(V1,V2); | ||
33 | |||
34 | if H(3) < 0, H = -H; end; | ||
35 | |||
36 | |||
37 | H = H / norm(H); | ||
38 | |||
39 | |||
40 | X1 = x1 / dot(H,x1); | ||
41 | X2 = x2 / dot(H,x2); | ||
42 | X3 = x3 / dot(H,x3); | ||
43 | X4 = x4 / dot(H,x4); | ||
44 | |||
45 | scale = X1(3); | ||
46 | |||
47 | X1 = X1/scale; | ||
48 | X2 = X2/scale; | ||
49 | X3 = X3/scale; | ||
50 | X4 = X4/scale; | ||
51 | |||
52 | |||
53 | u_hori = X2 - X1; | ||
54 | u_vert = X4 - X1; | ||