source: proiecte/pmake3d/make3d_original/Make3dSingleImageStanford_version0.1/third_party/torr/torr_gen_2view_matches.m @ 37

Last change on this file since 37 was 37, checked in by (none), 14 years ago

Added original make3d

File size: 5.1 KB
Line 
1%       By Philip Torr 2002
2%       copyright Microsoft Corp.
3%generates a set of point matches + their F matrix!@
4%torr_gen_2view_matches.m
5%we need to make sure that the object isnt too affine
6function [true_F,x1,y1,x2,y2,nx1,ny1,nx2,ny2,true_C,true_R,true_TX, true_E, true_X, true_t] = ...
7    torr_gen_2view_matches(foc, no_matches, noise_sigma, translation_mult, translation_adder, ...
8    rotation_multplier, min_Z,Z_RAN,m3, other_parameters)
9
10if nargin == 0
11    %default values
12    m3 = 256.0; %third homogeneous coordinate
13   
14    %focal length
15    foc = m3 *3;
16    %number of matches desired
17    no_matches = 100;
18    % noise added to each point
19    noise_sigma = 1;
20   
21    %translation between translation_adder and translation_mult + translation_adder, uniformly distributed.
22    translation_mult = foc * 2;
23    translation_adder = 0;
24   
25    %max number of degrees to rotate
26    rotation_min = 5; %min no of degrees to rotate unless pure_translation == true
27    rotation_multplier = 8;
28   
29    %number of focal lengths nearest and furthest points are from camera one, all other points uniformly
30    % distributed between these two values
31    min_Z = 3;
32    Z_RAN = 10;
33end
34
35
36%not yet implmented
37if nargin < 10
38    pure_translation = 0;
39    pure_rotation = 0;
40    orthographic = 0;
41else
42    pure_translation = other_parameters(1);
43    pure_rotation = other_parameters(2);
44    orthographic = other_parameters(3);
45end
46   
47
48C = eye(3);
49C(1,3) = 0;
50C(2,3) = 0;
51C(3,3) = 1/foc;
52
53R = eye(3);
54t = rand(3,1);
55t = t * (translation_mult *norm(t)) +translation_adder;
56true_t = t;
57T = [0 -t(3) t(2); t(3) 0 -t(1); -t(2) t(1) 0];
58
59%
60% rot_axis = rand(3,1);
61% rot_axis = rot_axis/norm(rot_axis);
62% rot_angle = 1/360 * 2 * pi * rand * rotation_multplier + rotation_min;
63% %Rogregues
64% II = [1 0 0; 0 1 0; 0 0 1];
65% AX = torr_skew_sym(rot_axis);
66% R = cos(rot_angle) * II +sin(rot_angle) * AX + (1 - cos(rot_angle)) * rot_axis * rot_axis';
67
68
69theta = 1/360 * 2 * pi * rand * rotation_multplier;
70n = 1/360 * 2 * pi * rand * rotation_multplier;
71p = 1/360 * 2 * pi * rand * rotation_multplier;
72
73R(1,1) = (1 - cos(p)) * cos(n)* ( cos(n) * cos(theta) + sin(theta) * sin(n) ) + cos(p)* cos(theta);
74R(1,2) = (1 - cos(p))* cos(n) * ( sin(n) *cos(theta) - sin(theta) *cos(n) ) - cos(p) *sin(theta);
75R(1,3) = sin(n) *sin(p);
76R(2,1) = (1 - cos(p)) *sin(n)  *( cos(n) *cos(theta) + sin(theta)* sin(n) ) + cos(p)* sin(theta);
77R(2,2) = (1 - cos(p)) *sin(n) * ( sin(n) *cos(theta) - sin(theta) *cos(n) ) + cos(p)* cos(theta);
78R(2,3) = -cos(n) * sin(p);
79R(3,1) = -sin(p) * ( sin(n) * cos(theta) - sin(theta) * cos(n));
80R(3,2) = sin(p) * ( cos(n) * cos(theta) + sin(theta) * sin(n));
81R(3,3) = cos(p);
82
83%R * R'
84%R' * R
85
86perfect_matches = rand(no_matches,4);
87noisy_matches = rand(no_matches,4);
88m1 = rand(3,no_matches);
89m2 = rand(3,no_matches);
90
91x1 = rand(no_matches,1);
92x2 = rand(no_matches,1);
93y1 = rand(no_matches,1);
94y2 = rand(no_matches,1);
95
96X = rand(3,no_matches);
97
98%noisy data:----
99nx1 = rand(no_matches,1);
100nx2 = rand(no_matches,1);
101ny1 = rand(no_matches,1);
102ny2 = rand(no_matches,1);
103
104for(i = 1:no_matches)
105    X(3,i) = min_Z * foc + Z_RAN * foc * X(3,i);
106    X(1,i) = (X(1,i) * 512 -256 ) *X(3,i)/foc;
107    X(2,i) = (X(2,i) * 512 -256 ) * X(3,i)/foc;
108end
109
110
111m1 = C *X;
112m2 = R *X;
113m2 = m2 + t * ones(1,no_matches);
114m2 = C * m2;
115%   m2 = C * ( R *X + t);
116
117%for(i = 1:no_matches)
118x1 = (m1(1,:)./m1(3,:))';
119y1 = (m1(2,:)./m1(3,:))';
120x2 = (m2(1,:)./m2(3,:))';
121y2 = (m2(2,:)./m2(3,:))';
122
123
124perfect_matches(:,1) = x1(:);
125perfect_matches(:,2) = y1(:);
126perfect_matches(:,3) = x2(:);
127perfect_matches(:,4) = y2(:);
128
129
130
131
132%    noisy_matches(:,1) = x1(:)  + randn(no_matches,1) *noise_multiplier;
133%    noisy_matches(:,2) = y1(:) + randn(no_matches,1) *noise_multiplier;
134%    noisy_matches(:,3) = x2(:) + randn(no_matches,1) *noise_multiplier;
135%    noisy_matches(:,4) = y2(:) + randn(no_matches,1) *noise_multiplier;
136
137noisy_matches(:,1) = x1  + normrnd(0, noise_sigma, no_matches,1);
138noisy_matches(:,2) = y1 +  normrnd(0, noise_sigma, no_matches,1);
139noisy_matches(:,3) = x2 +  normrnd(0, noise_sigma, no_matches,1);
140noisy_matches(:,4) = y2 +  normrnd(0, noise_sigma, no_matches,1);
141
142
143nx1 = noisy_matches(:,1);
144ny1 = noisy_matches(:,2);
145nx2 = noisy_matches(:,3);
146ny2 = noisy_matches(:,4);
147
148
149
150%m2(i)' * F * m1(i)
151
152F = inv(C')  * T * R * inv(C);
153
154%this is the wrong answer for the algebraic residual!!    m1(i)' * F * m2(i)
155
156%note here  m3 = 1, so need to adjust this to check the results...
157MM = [1 0 0; 0 1 0; 0 0 1/m3];
158
159
160F2 = MM * F * MM;
161true_F = F2 / norm(F2);
162
163%return also the true calibration matrix, note we set the 3rd coordinate to m3 so
164% we need to divide the focal length by this in the camera matrixc
165true_C = C;
166true_C(3,3) = true_C(3,3) * m3;
167true_R = R;
168true_TX = T;
169true_E = T * R;
170true_X = X;
171
172%torr_display_matches(perfect_matches);
173%
174% %i think this is the right one
175% f_true = [F2(1) F2(2,:) F2(3,:)];
176% f_true = f_true/norm(f_true);
177%
178%
179% %wrong one
180% fff = [F(:,1)' F(:,2)' F(:,3)']
181% fff = fff/norm(fff);
182
183%e = errf2(fff,x1,y1,x2,y2, no_matches, m3);
Note: See TracBrowser for help on using the repository browser.