-
Notifications
You must be signed in to change notification settings - Fork 37
/
TestVision_Example_Small.m
171 lines (133 loc) · 4.87 KB
/
TestVision_Example_Small.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
clc
clear
addpath('./g2o_files/');
addpath('./auxilliary/')
addpath('./Math/');
addpath('./Factor/');
addpath('./Geometry/');
pose0=[eye(3) zeros(3,1)];
pose1=[expm(skew([ 0.1 ;-0.05; 0.2 ])) [ 2; -2 ;-1] ];
pose2=[expm(skew([ -0.15 ; 0.05; -0.2 ])) [ -1.5; 2.3 ;-1.2] ];
pose3=[expm(skew([ 0.4 ; -0.1; 0.35 ])) [ -3; -2.7 ;-2] ];
f=cell(1,10);
f{1} = [ 1; 2 ;4 ];
f{2} = [ -1; 2 ;7];
f{3} = [ -2; 1 ; 11 ];
f{4} = [ -1.5; 2.4 ; 7.6 ];
f{5}= [ 3; 2 ; 9.4 ];
f{6}= [ -4; 4 ; 3 ];
f{7}= [ 4; -6 ; 5 ];
f{8}= [ 5; -2 ; 9.5 ];
f{9}= [ 0; 0 ; 4 ];
f{10}= [ 0.2; 0.5 ; 5 ];
fprintf('Ground Truth of landmarks\n')
%%%%% co-planar
% f{1} = [ 1; 2 ;5 ];
% f{2} = [ -1; 2 ;5];
% f{3} = [ -2; 1 ; 5 ];
% f{4} = [ -1.5; 2.4 ; 5 ];
% f{5}= [ 3; 2 ; 5 ];
% f{6}= [ -4; 4 ; 5 ];
% f{7}= [ 4; -6 ; 5 ];
% f{8}= [ 5; -2 ; 5];
% f{9}= [ 0; 0 ; 5 ];
% f{10}= [ 0.2; 0.5 ; 5 ];
[ Graph ] = InitializeGraph;
Graph.Fixed.IDname.pose0 = 1;
Graph.Fixed.IDname.pose1 = 1;
Graph.Fixed.IDname.pose2 = 1;
Graph.Fixed.IDname.pose3 = 1;
LandmarkManager=[];
k=1;
for i=1:10
fea = f{i};
landmark_id = ['landmark' num2str(i)];
[ UV_i_0 ] = GenerateUV_randn( pose0, f{i} );
R = pose0(1:3,1:3); p = pose0(1:3,4); d = norm(R'*( fea - p ));
Measurement_i_0.value = UV_i_0;
NodeArray=cell(2,2);
NodeArray{1,1}='Pose3';NodeArray{1,2}='pose0';
NodeArray{2,1}='Landmark3';NodeArray{2,2}=['landmark' num2str(i)];
LandmarkManager.(landmark_id).pose0 = UV_i_0;
if k
Measurement_i_0.inf = eye(3); %eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'VisionTest_Factor', NodeArray, Measurement_i_0 );
else
Measurement_i_0.inf = eye(2);
[ Graph ] = AddComplexEdge( Graph, 'Vision_Factor', NodeArray, Measurement_i_0 );
end
[ UV_i_1 ] = GenerateUV_randn( pose1, f{i} );
LandmarkManager.(landmark_id).pose1 = UV_i_1;
R = pose1(1:3,1:3); p = pose1(1:3,4); d = norm(R'*( fea - p ));
Measurement_i_1.value = UV_i_1;
Measurement_i_1.inf = eye(2);
NodeArray{1,2}='pose1';
if k
Measurement_i_1.inf = eye(3); %eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'VisionTest_Factor', NodeArray, Measurement_i_1 );
else
Measurement_i_1.inf = eye(2);
[ Graph ] = AddComplexEdge( Graph, 'Vision_Factor', NodeArray, Measurement_i_1 );
end
[ UV_i_2 ] = GenerateUV_randn( pose2, f{i} );
LandmarkManager.(landmark_id).pose2 = UV_i_2;
R = pose2(1:3,1:3); p = pose2(1:3,4); d = norm(R'*( fea - p ));
Measurement_i_2.value = UV_i_2;
Measurement_i_2.inf = eye(1);
NodeArray{1,2}='pose2';
if k
Measurement_i_2.inf = eye(3); %eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'VisionTest_Factor', NodeArray, Measurement_i_2 );
else
Measurement_i_2.inf = eye(2);
[ Graph ] = AddComplexEdge( Graph, 'Vision_Factor', NodeArray, Measurement_i_2 );
end
[ UV_i_3 ] = GenerateUV_randn( pose3, f{i} );
LandmarkManager.(landmark_id).pose3 = UV_i_3;
R = pose3(1:3,1:3); p = pose3(1:3,4); d = norm(R'*( fea - p ));
Measurement_i_3.value = UV_i_3;
Measurement_i_3.inf = eye(1);
NodeArray{1,2}='pose3';
if k
Measurement_i_3.inf = eye(3); % eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'VisionTest_Factor', NodeArray, Measurement_i_3 );
else
Measurement_i_3.inf = eye(2);
[ Graph ] = AddComplexEdge( Graph, 'Vision_Factor', NodeArray, Measurement_i_3 );
end
end
%%% Set initial guess via ground truth+noise
Graph.Nodes.Pose3.Values.pose0=pose0;
noise1 = [ expm(skew(randn(3,1)*0)) randn(3,1)*0];
Graph.Nodes.Pose3.Values.pose1=se3_group(pose1, noise1 ) ;
noise2 = [ expm(skew(rand(3,1)*0)) randn(3,1)*0];
Graph.Nodes.Pose3.Values.pose2=se3_group(pose2, noise2 ) ;
noise3 = [ expm(skew(randn(3,1)*0)) randn(3,1)*.0];
Graph.Nodes.Pose3.Values.pose3=se3_group(pose3, noise3 ) ;
PoseValue.pose0 = pose0;
PoseValue.pose1 = pose1;
PoseValue.pose2 = pose2;
PoseValue.pose3 = pose3;
Y=cell(10,1);
for i=1:10
G_i=f{i};
Graph.Nodes.Landmark3.Values.(['landmark' num2str(i)])=f{i}+12*rand(3,1);
%Graph.Nodes.Landmark3.Values.(['landmark' num2str(i)])=[-10 ; -10 ; -10];
X_i=Graph.Nodes.Landmark3.Values.(['landmark' num2str(i)]);
Y{i}=X_i;
end
%%% Set initial guess
[ Landmarks_values ] = Cal_triangulate( PoseValue , LandmarkManager );
Graph.Nodes.Landmark3.Values=Landmarks_values;
%[ Graph ] = PerformGO( Graph );
tic
[ Graph ] = PerformGO_DLnew_sch( Graph );
toc
for i=1:10
G_i=f{i};
X_i=Graph.Nodes.Landmark3.Values.(['landmark' num2str(i)]);
Y_i=Y{i};
fprintf('%d, %f, %f, %f \n', i, G_i(1),X_i(1),Y_i(1) )
fprintf('%d, %f, %f, %f \n', i, G_i(2),X_i(2),Y_i(2) )
fprintf('%d, %f, %f, %f \n', i, G_i(3),X_i(3),Y_i(3) )
end