forked from suuman/selectKeyImagesLines
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathselect_ReferenceImages.m
executable file
·166 lines (141 loc) · 5.4 KB
/
select_ReferenceImages.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
%%
% THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
% * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
% * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
% * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
% * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
% * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
% * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
% * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
% * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
% * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
% * POSSIBILITY OF SUCH DAMAGE.
% *
% /*
% * Author: Suman Raj Bista
% * @Inria Rennes Breatgne Atlantique
% * Reference images selection Refer our paper
% S. R. Bista, P. R. Giordano and F. Chaumette, "Appearance-Based Indoor Navigation by IBVS Using Line Segments,"
% in IEEE Robotics and Automation Letters, vol. 1, no. 1, pp. 423-430, Jan. 2016. doi: 10.1109/LRA.2016.252190
% *
% */
clear all;
close all;
clc;
%%
% set path for linematching and trifocal tensor estimation
addpath('./tftLine');
addpath('./linematching');
%%
% folder that contains all the images in png
% path of basefolder.
%%
bf = '../../linenav_officetest';
%% threshold .. no of miminum match lines
thres = 20;
%%
% image seq is inside imgs folder
[imList]=getImages([bf '/imgs_acquired']);
% key/reference images will be stored in kfls folder
KFD = [bf '/ref_imgs'];
%%
mp = [];
matchedlines = [];
indxmatch=[];
aaa=[];
lc = [];
ct = 0;
global imSize;
% imSize = [640 480];
sfc = 0;
ct=0;
%%
for j=1:length(imList)
%% read images
im = imList{j}
gim = imread(imList{j});
if(size(gim,3)==3)
gim = rgb2gray(gim);
end
imSize = [size(gim,2) size(gim,1)];
imwrite(gim,'tmpimg.pgm');
%% detect lines
status = detectLines('tmpimg.pgm','edlines.out');
lines = load('edlines.out');
ct = ct +1;
% ct = 1;
if ct == 1
%% get ist image
istim = j;
gim_t = gim;
im_t = im;
linest= lines;
save('lines_l.tmp', 'lines', '-ascii', '-tabs');
system(['cp ',im,' ',KFD]);
% save([KFD,'/kl_',im(end-7:end-3),'txt'],'lines', '-ascii', '-tabs');
dlmwrite([KFD,'/kl_',im(end-7:end-3),'txt'],lines,'delimiter','\t','precision','%.12f');
linesmatch =[];
matchedlines = [];
indxmatch=[];
pr = 1;
disp('New Key Image Added');
else
% save(, 'lines', '-ascii', '-tabs');
dlmwrite('lines_r.tmp',lines,'delimiter','\t','precision','%.12f');
% match
status = matchLines('lines_l.tmp','lines_r.tmp','matched.lines');
matchindex = load('matched.lines');
if length(matchindex)<10
%
status = 1;
sfc = sfc+1;
if (sfc>2)
ct = 0;
sfc = 0;
end
else
sfc = 0;
end
%% match lines
if status == 0
dt = lines;
linest = load('lines_l.tmp');
lines = load('lines_r.tmp');
matchindex = matchindex+1;
linesprev = linest(matchindex(:,1),:);
linest= lines(matchindex(:,2),:);
% save('lines_t.tmp', 'linesprev', '-ascii', '-tabs');
dlmwrite('lines_l.tmp',linesprev,'delimiter','\t','precision','%.12f');
if ct>2
try
matchedlines = getmatchedlinesin3v(linesmatch,matchindex,lines);
[TT,scorecheck,validindex] = calLineReconsError(matchedlines);
catch
ct =0; %if 3 view line m,atching fialed. Add new ref image
continue;
end
%
inliers = validindex<0.1;
cr = sum(inliers)/length(validindex);
[cr sum(inliers) length(validindex)]
if (length(validindex) <thres || (cr <0.5 && pr<0.5))
ct = 0; %if no of inilers<thres or inliers ratio in prev and current frame <0.5 => add new key image
end
pr=cr;
end
linesmatch= [linesprev(:,1:4) linest(:,1:4)];
end
end
fflush(stdout())
end
%% add last image of sequence as ref. image
im = imList{j-1}
gim = imread(imList{j-1});
imwrite(gim,'tmpimg.pgm');
% detect lines
status = detectLines('tmpimg.pgm','edlines.out')
lines = load('edlines.out');
system(['cp ',im,' ',KFD]);
% save([KFD,'/kl_',im(end-8:end-3),'txt'],'lines', '-ascii', '-tabs');
dlmwrite([KFD,'/kl_',im(end-8:end-3),'txt'],lines,'delimiter','\t','precision','%.12f');
system('rm *.tmp *.lines *.out *.pgm');