-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.m
155 lines (113 loc) · 4.87 KB
/
main.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
% Load data if requiered
close all
if ~exist('traj', 'var')
load KITTI_VEL_SCAN.mat
end
% point cloud analysis parameters
detector_params.c_edge = 0.1;
detector_params.c_plane = 0.05;
detector_params.distThresholdEdge = 0.3;
detector_params.minClusterSizeEdge = 5;
detector_params.barycenterThresholdEdge = 1.5;
detector_params.distThresholdPlane = 0.3;
detector_params.minClusterSizePlane = 30;
detector_params.barycenterThresholdPlane = 3;
% first filtering of the clouds
filteredCloud_1 = cloudFilter(traj{20}, "HDL64");
[edgeStruct_1.edgeIdx, planeStruct_1.planeIdx,...
labelCloud_1, smoothnessCloud_1] =...
edgePlaneDetector(filteredCloud_1.Location, detector_params);
filteredCloud_2 = cloudFilter(traj{21}, "HDL64");
[edgeStruct_2.edgeIdx, planeStruct_2.planeIdx,...
labelCloud_2, smoothnessCloud_2] =...
edgePlaneDetector(filteredCloud_2.Location, detector_params);
%----------------------------------------------------------------------
% evaluate the corespondence
%----------------------------------------------------------------------
% creating the edgeClouds
edgeStruct_1.edgeCloud = select(filteredCloud_1, ~edgeStruct_1.edgeIdx,...
'OutputSize', 'full');
edgeStruct_2.edgeCloud = select(filteredCloud_2, ~edgeStruct_2.edgeIdx,...
'OutputSize', 'full');
% clustering the edge clouds
edgeStruct_1 = clusteringEdge(edgeStruct_1, detector_params);
edgeStruct_2 = clusteringEdge(edgeStruct_2, detector_params);
% match the subclouds
corespondencesEdge = matchingEdge(edgeStruct_1, edgeStruct_2, detector_params);
% creating the planeCloud
planeStruct_1.planeCloud = select(filteredCloud_1, ~planeStruct_1.planeIdx,...
'OutputSize', 'full');
planeStruct_2.planeCloud = select(filteredCloud_2, ~planeStruct_2.planeIdx,...
'OutputSize', 'full');
% clustering the plane clouds
planeStruct_1 = clusteringPlane(planeStruct_1, detector_params);
planeStruct_2 = clusteringPlane(planeStruct_2, detector_params);
% match the plane clouds
corespondencesPlane = matchingPlane(planeStruct_1,...
planeStruct_2, detector_params);
%--------------------------------------------------------------------------
% finding the correct rigid transform with Levenberg and Marquardt algorithm
%--------------------------------------------------------------------------
% outliers rejection - edge
x0 = [0, 0, 0];
f = @(x)costEdge(corespondencesEdge, edgeStruct_1, edgeStruct_2, x);
% remove outliers
firstEval = f(x0);
inliers = ~isoutlier(firstEval);
inliers = logical(inliers(:,1).*inliers(:,2));
corespondencesEdge = corespondencesEdge(inliers,:);
% global levenberg Marquardt optimisation
x0 = [0,0,0,0,0,0];
lb = [-1.5, -0.05, -0.02, -0.01, -0.01, -pi/6];
ub = [1.5, 0.05, 0.02, 0.01, 0.01, pi/6];
f = @(x)globalCost_bary(corespondencesEdge, corespondencesPlane,...
edgeStruct_1, edgeStruct_2, ...
planeStruct_1, planeStruct_2, x);
try
options = optimoptions('lsqnonlin','FunctionTolerance', 0.001, 'MaxFunctionEvaluations', 1000);
[x,resnorm,residual,exitflag,output,lambda,jacobian] = lsqnonlin(f,x0,lb,ub,options);
catch
warning('optimisation failure')
end
disp(x);
%--------------------------------------------------------------------------
%display the results
%--------------------------------------------------------------------------
size1 = size(filteredCloud_1.Location, 1);
size2 = size(filteredCloud_1.Location, 2);
labelCorespondences_1 = nan(size1,size2);
labelCorespondences_2 = nan(size1,size2);
for i=1:length(corespondencesEdge)
label1 = corespondencesEdge(i,1);
labelCorespondences_1(find(edgeStruct_1.labels==edgeStruct_1.validLabels(label1))) = i;
label2 = corespondencesEdge(i,2);
labelCorespondences_2(find(edgeStruct_2.labels==edgeStruct_2.validLabels(label2))) = i;
end
figure(1)
pcshow(edgeStruct_1.edgeCloud.Location,labelCorespondences_1, 'MarkerSize', 80)
colormap(hsv(size(corespondencesEdge,1)))
title('edge Matched')
labelCorespondences_1 = nan(size1,size2);
labelCorespondences_2 = nan(size1,size2);
for i=1:size(corespondencesPlane,1)
label1 = corespondencesPlane(i,1);
labelCorespondences_1(find(planeStruct_1.labels==planeStruct_1.validLabels(label1))) = i;
label2 = corespondencesPlane(i,2);
labelCorespondences_2(find(planeStruct_2.labels==planeStruct_2.validLabels(label2))) = i;
end
figure;
pcshow(planeStruct_1.planeCloud.Location,labelCorespondences_1)
colormap(hsv(size(corespondencesPlane,1)))
title('plane 1 Matched')
figure;
pcshow(planeStruct_2.planeCloud.Location,labelCorespondences_2)
colormap(hsv(size(corespondencesPlane,1)))
title('plane 2 Matched')
figure(3)
pcshow(filteredCloud_1.Location,labelCloud_1, 'MarkerSize', 20)
colormap([[1 0 0]; [0 1 0]; [0 0 1]]);
title('Point Cloud planes and edges')
figure(4)
pcshow(filteredCloud_2.Location,labelCloud_2, 'MarkerSize', 30)
colormap([[1 0 0]; [0 1 0]; [0 0 1]]);
title('Point Cloud planes and edges')