1 | % By Philip Torr 2002
|
---|
2 | % copyright Microsoft Corp.
|
---|
3 | % so we display an epipolar line in an image
|
---|
4 |
|
---|
5 |
|
---|
6 | function torr_compare_epipoles(Fmat1,Fmat2,matches, m3)
|
---|
7 |
|
---|
8 | x1 = matches(:,1);
|
---|
9 | y1 = matches(:,2);
|
---|
10 | u1 = matches(:,3) - x1;
|
---|
11 | v1 = matches(:,4) - y1;
|
---|
12 |
|
---|
13 |
|
---|
14 | if nargin < 7
|
---|
15 | m3 = 256
|
---|
16 | end
|
---|
17 |
|
---|
18 | % (x2 y2 m3) F (x1 y1 m3)'
|
---|
19 | % (image 2) F ( image 1)'
|
---|
20 |
|
---|
21 | f1 = figure
|
---|
22 | m1 = max(max(matches));
|
---|
23 | m2 = min(min(matches));
|
---|
24 | m2 = -m2;
|
---|
25 | g = max(m1,m2);
|
---|
26 |
|
---|
27 | axis([-g g -g g])
|
---|
28 | hold on
|
---|
29 |
|
---|
30 | %for(i = 1:length(x1))
|
---|
31 | plot (matches(:,1), matches(:,2),'r+')
|
---|
32 | plot (matches(:,3), matches(:,4),'r+')
|
---|
33 | %end
|
---|
34 |
|
---|
35 | quiver(x1, y1, u1, v1, 0)
|
---|
36 |
|
---|
37 | hold off
|
---|
38 |
|
---|
39 | f2 = figure
|
---|
40 | m1 = max(max(matches));
|
---|
41 | m2 = min(min(matches));
|
---|
42 | m2 = -m2;
|
---|
43 | g = max(m1,m2);
|
---|
44 |
|
---|
45 | axis([-g g -g g])
|
---|
46 | hold on
|
---|
47 |
|
---|
48 | %for(i = 1:length(x1))
|
---|
49 | plot (matches(:,1), matches(:,2),'r+')
|
---|
50 | plot (matches(:,3), matches(:,4),'r+')
|
---|
51 | %end
|
---|
52 |
|
---|
53 | quiver(x1, y1, u1, v1, 0)
|
---|
54 |
|
---|
55 | hold off
|
---|
56 |
|
---|
57 | button = 1;
|
---|
58 | while ~isempty(button)
|
---|
59 |
|
---|
60 | %this takes one image and draws the corresponding epipolar line.
|
---|
61 | % Fmat = [[f(1) f(2) f(3)]; [f(4) f(5) f(6)];[f(7) f(8) f(9)]]
|
---|
62 | %
|
---|
63 |
|
---|
64 |
|
---|
65 | figure(f1);
|
---|
66 | %
|
---|
67 | % [U,S,V] = svd(Fmat);
|
---|
68 | % S(3,3) = 0;
|
---|
69 | % F2 = U*S*V';
|
---|
70 |
|
---|
71 | % [v,d] = eig(Fmat1);
|
---|
72 | % epipole = v(:,3);
|
---|
73 | % epipole = epipole * (m3/epipole(3);
|
---|
74 | % %Fmat * ee
|
---|
75 | %
|
---|
76 |
|
---|
77 |
|
---|
78 | hold on
|
---|
79 | [Xcur,Ycur,button] = GINPUT(1);
|
---|
80 | plot(Xcur,Ycur, 'g+');
|
---|
81 |
|
---|
82 | xxx1 = [Xcur,Ycur, 256.0];
|
---|
83 |
|
---|
84 | % (x2 y2 m3) F (x1 y1 m3)'
|
---|
85 | % (image 2) F ( image 1)'
|
---|
86 |
|
---|
87 | el2 = Fmat1 * xxx1';
|
---|
88 |
|
---|
89 |
|
---|
90 | figure(f2)
|
---|
91 |
|
---|
92 | %define two points x1 = 0, x2 =
|
---|
93 | % note x 1 + y 2 + m3 3 = 0
|
---|
94 | % y = (-m3 3 - x 1 ) / 2
|
---|
95 |
|
---|
96 | nr = 512;
|
---|
97 | nc = 512;
|
---|
98 |
|
---|
99 | x1 = -400000;
|
---|
100 | % y1 = - el2(3) * 256/el2(2);
|
---|
101 | y1 =( -x1 * el2(1) - el2(3) * 256)/el2(2);
|
---|
102 |
|
---|
103 | x2 = nr;
|
---|
104 | y2 = (- el2(3) * 256 - x2 * el2(1))/el2(2);
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 | hold on
|
---|
109 | a = [x1,x2];
|
---|
110 | b = [ y1,y2 ];
|
---|
111 | line(a,b,'Color','r');
|
---|
112 |
|
---|
113 |
|
---|
114 |
|
---|
115 | el2 = Fmat2 * xxx1';
|
---|
116 |
|
---|
117 |
|
---|
118 | %define two points x1 = 0, x2 =
|
---|
119 | % note x 1 + y 2 + m3 3 = 0
|
---|
120 | % y = (-m3 3 - x 1 ) / 2
|
---|
121 |
|
---|
122 |
|
---|
123 | x1 = -400;
|
---|
124 | y1 =( -x1 * el2(1) - el2(3) * 256)/el2(2);
|
---|
125 |
|
---|
126 | x2 = nr;
|
---|
127 | y2 = (- el2(3) * 256 - x2 * el2(1))/el2(2);
|
---|
128 |
|
---|
129 |
|
---|
130 |
|
---|
131 | hold on
|
---|
132 | a = [x1,x2];
|
---|
133 | b = [ y1,y2 ];
|
---|
134 |
|
---|
135 | figure(f1);
|
---|
136 | plot(Xcur,Ycur, 'g+');
|
---|
137 | figure(f2);
|
---|
138 | line(a,b,'Color','g');
|
---|
139 |
|
---|
140 | end
|
---|
141 |
|
---|
142 | %
|
---|
143 | % function g = display_mat(matches, x1,y1, u1, v1)
|
---|
144 | %
|
---|
145 | % m1 = max(max(matches));
|
---|
146 | % m2 = min(min(matches));
|
---|
147 | % m2 = -m2;
|
---|
148 | % g = max(m1,m2);
|
---|
149 | %
|
---|
150 | % axis([-g g -g g])
|
---|
151 | % hold on
|
---|
152 | %
|
---|
153 | % for(i = 1:length(x1))
|
---|
154 | % plot (matches(i,1), matches(i,2),'r+')
|
---|
155 | % plot (matches(i,3), matches(i,4),'r+')
|
---|
156 | % end
|
---|
157 | %
|
---|
158 | % quiver(x1, y1, u1, v1, 0)
|
---|
159 | %
|
---|
160 | % hold off |
---|