forked from UTS-RI/Matlab-Graph-Optimization
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ComplexEdge_Vision_Example_Small.m
146 lines (109 loc) · 4.11 KB
/
ComplexEdge_Vision_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
clc
clear
addpath('./g2o_files/');
addpath('./auxilliary/')
addpath('./Math/');
addpath('./Factor/');
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 ;9 ];
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 ; 14 ];
f{7}= [ 4; -6 ; 10 ];
f{8}= [ 5; -2 ; 9.5 ];
f{9}= [ 0; 0 ; 4 ];
f{10}= [ 0.2; 0.5 ; 5 ];
fprintf('Ground Truth of landmarks\n')
[ Graph ] = InitializeGraph;
Graph.Fixed.IDname.pose0 = 1;
%Graph.Fixed.IDname.pose1 = 1;
k=0;
for i=1:10
fea = f{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)];
if k
Measurement_i_0.inf = eye(2); %eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'LinearVision_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} );
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)/(d^2)*525^2;
NodeArray{1,2}='pose1';
if k
Measurement_i_1.inf = eye(2); %eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'LinearVision_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} );
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(2)/(d^2);
NodeArray{1,2}='pose2';
if k
Measurement_i_2.inf = eye(2); %eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'LinearVision_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} );
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(2)/(d^2);
NodeArray{1,2}='pose3';
if k
Measurement_i_3.inf = eye(2); % eye(2)/(d^2)*525^2;
[ Graph ] = AddComplexEdge( Graph, 'LinearVision_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(randn(3,1)*0.1)) randn(3,1)*0.2];
Graph.Nodes.Pose3.Values.pose2=se3_group(pose2, noise2 ) ;
noise3 = [ expm(skew(randn(3,1)*0.1)) randn(3,1)*0.2];
Graph.Nodes.Pose3.Values.pose3=se3_group(pose3, noise3 ) ;
Y=cell(10,1);
for i=1:10
G_i=f{i};
Graph.Nodes.Landmark3.Values.(['landmark' num2str(i)])=f{i}+1*randn(3,1);
X_i=Graph.Nodes.Landmark3.Values.(['landmark' num2str(i)]);
Y{i}=X_i;
end
%Graph.Nodes.Landmark3.Values.landmark1=[1.02;2.1;9.1];
%Y{1} = [1;1;1];
%%% Set initial guess
%[ Graph ] = PerformGO( Graph );
tic
[ Graph ] = PerformGO_DL( Graph );
toc
%[ Graph ] = PerformGO( Graph );
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