-
Notifications
You must be signed in to change notification settings - Fork 0
/
GUI_DepthResolution_v4.m
325 lines (257 loc) · 11 KB
/
GUI_DepthResolution_v4.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
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
% #######################################################
% Both the color & IR images of the Freiburg 3 sequences have already been
% undistorted (i.e. Calibrated), therefore the distortion parameters are
% all zero. So no kinect calibration is required on the dataset.
% http://nicolas.burrus.name/index.php/Research/KinectCalibration
% http://vision.in.tum.de/data/datasets/rgbd-dataset/file_formats
% ######################################################
function varargout = GUI_DepthResolution_v4(varargin)
% GUI_DEPTHRESOLUTION_V4 MATLAB code for GUI_DepthResolution_v4.fig
% Edit the above text to modify the response to help GUI_DepthResolution_v4
% Last Modified by GUIDE v2.5 24-Aug-2014 17:42:45
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI_DepthResolution_v4_OpeningFcn, ...
'gui_OutputFcn', @GUI_DepthResolution_v4_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
end
% --- Executes just before GUI_DepthResolution_v4 is made visible.
function GUI_DepthResolution_v4_OpeningFcn(hObject, ~, handles, varargin)
% hObject handle to figure
% Choose default command line output for GUI_DepthResolution_v4
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% ################# Custom Opening Cmds ##################### %
set(handles.btnLoadKinectData,'Enable','off');
set(handles.btnPauseFrame,'Enable','off');
clc;
% #################---------------------##################### %
end
% --- Outputs from this function are returned to the command line.
function varargout = GUI_DepthResolution_v4_OutputFcn(~, ~, handles)
% hObject handle to figure
% Get default command line output from handles structure
varargout{1} = handles.output;
end
%% ==========================================================
% ######### ######### Edited Functions ######### #########%%
% ==========================================================
% --- Executes on button press in btnLoadDataset.
function btnLoadDataset_Callback(~, ~, handles) %#ok<*DEFNU>
% hObject handle to btnLoadDataset (see GCBO)
clc;
global depthImgMeters;
global img1;
global h5;
global h2;
global img2;
DatasetPath = uigetdir(pwd); % Get path to dataset folder
addpath(genpath(DatasetPath)) % Add Subfolder to search path
if ~isdir(DatasetPath)
errorMessage = sprintf('Error: The following folder does not exist:\n%s', myFolder);
uiwait(warndlg(errorMessage));
return;
end
% --Variables--
% DatasetPath: Path of dataset selected by user
% RGBpath: Path or 'rgb' folder (assumed to be inside DatasetPath by default)
% RGBFiles: Number of png rgb files
% RGBpath: Path or 'depth' folder (assumed to be inside DatasetPath by default)
% RGBFiles: Number of png depth files
RGBpath=fullfile(DatasetPath,'rgb');
DEPTHpath=fullfile(DatasetPath,'/depth');
% Process Files in Folder 'dataset/rgb'
fileRGB = fullfile(RGBpath, '*.png');
rgbFileList = dir(fileRGB);
RGBFiles = length(rgbFileList);
set(handles.txtRGBNumber, 'string', RGBFiles)
% Process Files in Folder 'dataset/depth'
fileDepth = fullfile(DEPTHpath, '*.png');
depthFileList = dir(fileDepth);
DepthFiles = length(depthFileList);
set(handles.txtDepthNumber, 'string', DepthFiles) % Display no of files
[h1, h2, h3, h4, h5] = createAxes();
set(handles.btnPauseFrame,'Enable','on');
% ... T3h L00p ...
for i = 1:DepthFiles
% ---------------- show rgb image ----------------
findobj('Tag','dispRGB');
axes(h1);
img1 = imread([rgbFileList(i).name]);
imshow(img1);
title('RGB');
index = int2str(i);
set(handles.text5, 'string', index)
% Crop Image pixels each side
% img1 = imcrop(img1,[25 25 589 429]);
% ---------------- show depth image ----------------
axes(h3);
img2 = imread([depthFileList(i).name]);
% Crop Image pixels each side
% img2 = imcrop(img2,[25 25 589 429]);
% show depth image
imagesc(img2);
title('Depth');
set(gca,'XTick',[],'YTick',[]);
% ---------------- show depth in meters ----------------
axes(h4);
imagesc(depthImgMeters);
title('Depth to Meters');
set(gca,'XTick',[],'YTick',[]);
colorbar;
axes(h5);
% imshow(img2);
imshowpair(img1, img2, 'falsecolor')
title('Get User Input (Press Enter after selecting Object Corners)');
set(gca,'XTick',[],'YTick',[]);
end
end
%% ---------------------------------------------
% --- Executes on button press in btnPauseFrame.
function btnPauseFrame_Callback(hObject, ~, handles)
% hObject handle to btnPauseFrame (see GCBO)
% Need to redeclare the global variables in order for them to work in
% Matlab - (lol?!)
global depthImgMeters;
global filledDepth;
global img1;
global h5;
global h2;
global img2;
global sizeX_mm;
global sizeY_mm;
while get(hObject,'Value')
% Get user Input
% pause(0.15);
% ------------------ Zero Fill Image ---------------------------%
[filledDepth, ~] = ftnZeroFill(img2);
axes(h2);
% show filled image
imshowpair(img2,filledDepth,'falsecolor');
title('Filled');
% ------------------ convert depth values to meters ------------%
% This function converts depth values read from the depth image to
% meters and outputs an image with the new values.
depthImgMeters = ftnDepth2meters( filledDepth );
% ------------------ Get vertices from user ------------------ %
set(gcf,'CurrentAxes',h5);
[userCol, userRow] = getpts(gca);
% roundoff current value to get pixels
userCol = abs(round(userCol));
userRow = abs(round(userRow));
% ------------------- Display Poly ---------------------------- %
pos = {[abs(userCol(1)),abs(userRow(1)) ...
abs(userCol(2)),abs(userRow(2)) ...
abs(userCol(3)),abs(userRow(3)) ...
abs(userCol(4)),abs(userRow(4)) ...
abs(userCol(1)),abs(userRow(1)) ...
abs(userCol(1)),abs(userRow(1))]};
Imr = insertShape(img1,'FilledPolygon',pos,'Color','green','Opacity',0.5);
imshow(Imr);
% ------------------ Calculate Meters/pixel resolution ------- %
% Function to calculate the Dynamic Depth Resolution. takes depth
% image as input (with 11-bit data in millimeters extracted
% from Kinects 16-bit depth data). Outputs two corrected
% resoultion depth images, one for row resolution and
% one for column resolution.
[sizeX_mm, sizeY_mm] = ftnCalcDepthResolution ( depthImgMeters, userCol, userRow );
% ------------------ Display on GUI ------------------ %
index = num2str(sizeX_mm,4);
set(handles.txtSizeX, 'string', index) % Display size
index = num2str(sizeY_mm,4);
set(handles.txtSizeY, 'string', index) % Display size
% Converting mm to inch %
% 1m = 39.3701 inch %
sizeX_mm = 39.3701*sizeX_mm;
sizeY_mm = 39.3701*sizeY_mm;
index = num2str(sizeX_mm,4);
set(handles.txtSizeXin, 'string', index) % Display size
index = num2str(sizeY_mm,4);
set(handles.txtSizeYin, 'string', index) % Display size
% --------------------- %
sizeX_mm = 0.0;
sizeY_mm = 0.0;
break;
end
end
% ==========================================================
function [h1, h2, h3, h4, h5] = createAxes()
% Get handles of axes in the figure
axes(findobj('Tag','dispRGB')); % Select Axes to plot
set(gca,'XTick',[],'YTick',[]);
title('RGB');
h1 = gca;
axes(findobj('Tag','dispF')); % Select Axes to plot
set(gca,'XTick',[],'YTick',[]);
title('Filled');
h2 = gca;
axes(findobj('Tag','dispD')); % Select Axes to plot
set(gca,'XTick',[],'YTick',[]);
title('Depth');
h3 = gca;
axes(findobj('Tag','dispFig')); % Select Axes to plot
set(gca,'XTick',[],'YTick',[]);
title('Depth to MiliMeters');
h4 = gca;
axes(findobj('Tag','getUI')); % Select Axes to plot
set(gca,'XTick',[],'YTick',[]);
title('Get User Input');
h5 = gca;
end
% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject handle to figure1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
selection = questdlg(['Close ' get(handles.figure1,'Name') '?'],...
['Close ' get(handles.figure1,'Name') '...'],...
'Yes','No','Yes');
if strcmp(selection,'No')
return;
end
delete(handles.figure1)
% clear all;
% clear classes;
clc;
end
function btnQuit_Callback(hObject, eventdata, handles)
% --- Executes on button press in btnQuit.
% Do while frame paused!
% http://blogs.mathworks.com/videos/2010/12/03/how-to-loop-until-a-button-is-pushed-in-matlab/
% hObject handle to btnQuit (see GCBO)
clc;
figure1_CloseRequestFcn(hObject, eventdata, handles);
end
%% --------------------------------------------------------------------------
% --- Executes on button press in btnLoadKinectData.
function btnLoadKinectData_Callback(~, ~, ~)
% hObject handle to btnLoadKinectData (see GCBO)
clc;
clear;
% close all; % close Current GUI and open new figure
% hgload('Kinect.fig') % Load figure
end
% --- Executes during object deletion, before destroying properties.
function getUI_DeleteFcn(~, ~, ~)
% hObject handle to getUI (see GCBO)
% set(0,'ShowHiddenHandles','on');
% delete(get(0,'Children'));
end
% --- Executes on mouse motion over figure - except title and menu.
function figure1_WindowButtonMotionFcn(~, ~, ~)
% hObject handle to figure1 (see GCBO)
% C = get(figure1.handles,'CurrentPoint'),
end