forked from kyamagu/mexopencv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStereoBM.m
318 lines (293 loc) · 11.4 KB
/
StereoBM.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
classdef StereoBM < handle
%STEREOBM Class for computing stereo correspondence using the block matching algorithm
%
% Class for computing stereo correspondence using the block matching
% algorithm, introduced and contributed to OpenCV by K. Konolige.
%
% ## Usage
%
% bm = cv.StereoBM('NumDisparities',64, ...);
% bm.MinDisparity = 0;
% disparity = bm.compute(left, right);
%
% See also: cv.StereoBM.StereoBM, cv.StereoBM.compute, cv.StereoSGBM,
% cv.getValidDisparityROI, cv.filterSpeckles, cv.validateDisparity,
% disparity, stereoAnaglyph
%
properties (SetAccess = private)
% Object ID
id
end
properties (Dependent)
% Minimum possible disparity value, default 0
MinDisparity
% Maximum disparity minus minimum disparity, positive and divisble by
% 16. default 64
NumDisparities
% SAD window size, odd within 5..255 and not larger than image width
% or height. default 21
BlockSize
% Maximum size of smooth disparity regions to consider their noise
% speckles and invalidate (when `SpeckleRange>=0` and
% `SpeckleWindowSize>0`). See `maxSpeckleSize` in cv.filterSpeckles,
% default 0
SpeckleWindowSize
% Maximum disparity variation within each connected component (when
% `SpeckleRange>=0` and `SpeckleWindowSize>0`). See `maxDiff` in
% cv.filterSpeckles, default 0
SpeckleRange
% Maximum allowed difference (in integer pixel units) in the
% left-right disparity check (when `Disp12MaxDiff>=0`). see
% cv.validateDisparity, default -1
Disp12MaxDiff
% pre-filtering type, one of: 'NormalizedResponse' or 'XSobel' (default)
PreFilterType
% pre-filtering size, odd and betweeen 5..255, default 9
PreFilterSize
% Truncation value for prefiltering image pixels, within 1..63,
% default 31
PreFilterCap
% texture threshold, non-negative. default 10
TextureThreshold
% uniqueness ratio, non-negative. default 15
UniquenessRatio
% currently unused. default 0
SmallerBlockSize
% computes disparity for ROI in first image. default [0,0,0,0].
% see cv.getValidDisparityROI
ROI1
% computes disparity for ROI in second image. default [0,0,0,0].
% see cv.getValidDisparityROI
ROI2
end
methods
function this = StereoBM(varargin)
%STEREOBM Creates StereoBM object
%
% bm = cv.StereoBM()
% bm = cv.StereoBM('OptionName', optionValue, ...)
%
% ## Options
% * __NumDisparities__ the disparity search range. For each pixel
% algorithm will find the best disparity from 0 (default minimum
% disparity) to `NumDisparities`. The search range can then be
% shifted by changing the minimum disparity. default 0 (which
% uses 64 by default).
% * __BlockSize__ the linear size of the blocks compared by the
% algorithm. The size should be odd (as the block is centered at
% the current pixel). Larger block size implies smoother, though
% less accurate disparity map. Smaller block size gives more
% detailed disparity map, but there is is higher chance for
% algorithm to find a wrong correspondence. default 21.
%
% The function creates cv.StereoBM object. You can then call
% cv.StereoBM.compute to compute disparity for a specific stereo
% pair.
%
% See also: cv.StereoBM.compute
%
this.id = StereoBM_(0, 'new', varargin{:});
end
function delete(this)
%DELETE Destructor
%
% bm.delete()
%
% See also: cv.StereoBM
%
if isempty(this.id), return; end
StereoBM_(this.id, 'delete');
end
function disparity = compute(this, left, right)
%COMPUTE Computes disparity map for the specified stereo pair
%
% disparity = bm.compute(left, right)
%
% ## Input
% * __left__ Left 8-bit single-channel image.
% * __right__ Right image of the same size and the same type as
% the left one.
%
% ## Output
% * __disparity__ Output disparity map. It has the same size as
% the input images. Some algorithms, like cv.StereoBM or
% cv.StereoSGBM compute 16-bit fixed-point disparity map (where
% each disparity value has 4 fractional bits), whereas other
% algorithms output 32-bit floating-point disparity map.
%
% The method executes the BM algorithm on a rectified stereo pair.
% Note that the method is not constant, thus you should not use
% the same cv.StereoBM instance from within different threads
% simultaneously.
%
% See also: cv.StereoBM.StereoBM
%
disparity = StereoBM_(this.id, 'compute', left, right);
end
end
%% Algorithm
methods
function clear(this)
%CLEAR Clears the algorithm state
%
% obj.clear()
%
% See also: cv.StereoBM.empty
%
StereoBM_(this.id, 'clear');
end
function b = empty(this)
%EMPTY Checks if algorithm object is empty
%
% b = obj.empty()
%
% ## Output
% * __b__ Returns true if the algorithm object is empty
% (e.g. in the very beginning or after unsuccessful read).
%
% See also: cv.StereoBM.clear
%
b = StereoBM_(this.id, 'empty');
end
function name = getDefaultName(this)
%GETDEFAULTNAME Returns the algorithm string identifier
%
% name = obj.getDefaultName()
%
% ## Output
% * __name__ This string is used as top level XML/YML node tag
% when the object is saved to a file or string.
%
% See also: cv.StereoBM.save, cv.StereoBM.load
%
name = StereoBM_(this.id, 'getDefaultName');
end
function save(this, filename)
%SAVE Saves the algorithm to a file
%
% obj.save(filename)
%
% ## Input
% * __filename__ Name of the file to save to.
%
% This method stores the algorithm parameters in a file storage.
%
% See also: cv.StereoBM.load
%
StereoBM_(this.id, 'save', filename);
end
function load(this, fname_or_str, varargin)
%LOAD Loads algorithm from a file or a string
%
% obj.load(fname)
% obj.load(str, 'FromString',true)
% obj.load(..., 'OptionName',optionValue, ...)
%
% ## Input
% * __fname__ Name of the file to read.
% * __str__ String containing the serialized model you want to
% load.
%
% ## Options
% * __ObjName__ The optional name of the node to read (if empty,
% the first top-level node will be used). default empty
% * __FromString__ Logical flag to indicate whether the input is a
% filename or a string containing the serialized model.
% default false
%
% This method reads algorithm parameters from a file storage.
% The previous model state is discarded.
%
% See also: cv.StereoBM.save
%
StereoBM_(this.id, 'load', fname_or_str, varargin{:});
end
end
%% Getters/Setters
methods
function value = get.PreFilterCap(this)
value = StereoBM_(this.id, 'get', 'PreFilterCap');
end
function set.PreFilterCap(this, value)
StereoBM_(this.id, 'set', 'PreFilterCap', value);
end
function value = get.PreFilterSize(this)
value = StereoBM_(this.id, 'get', 'PreFilterSize');
end
function set.PreFilterSize(this, value)
StereoBM_(this.id, 'set', 'PreFilterSize', value);
end
function value = get.PreFilterType(this)
value = StereoBM_(this.id, 'get', 'PreFilterType');
end
function set.PreFilterType(this, value)
StereoBM_(this.id, 'set', 'PreFilterType', value);
end
function value = get.ROI1(this)
value = StereoBM_(this.id, 'get', 'ROI1');
end
function set.ROI1(this, value)
StereoBM_(this.id, 'set', 'ROI1', value);
end
function value = get.ROI2(this)
value = StereoBM_(this.id, 'get', 'ROI2');
end
function set.ROI2(this, value)
StereoBM_(this.id, 'set', 'ROI2', value);
end
function value = get.SmallerBlockSize(this)
value = StereoBM_(this.id, 'get', 'SmallerBlockSize');
end
function set.SmallerBlockSize(this, value)
StereoBM_(this.id, 'set', 'SmallerBlockSize', value);
end
function value = get.TextureThreshold(this)
value = StereoBM_(this.id, 'get', 'TextureThreshold');
end
function set.TextureThreshold(this, value)
StereoBM_(this.id, 'set', 'TextureThreshold', value);
end
function value = get.UniquenessRatio(this)
value = StereoBM_(this.id, 'get', 'UniquenessRatio');
end
function set.UniquenessRatio(this, value)
StereoBM_(this.id, 'set', 'UniquenessRatio', value);
end
function value = get.BlockSize(this)
value = StereoBM_(this.id, 'get', 'BlockSize');
end
function set.BlockSize(this, value)
StereoBM_(this.id, 'set', 'BlockSize', value);
end
function value = get.Disp12MaxDiff(this)
value = StereoBM_(this.id, 'get', 'Disp12MaxDiff');
end
function set.Disp12MaxDiff(this, value)
StereoBM_(this.id, 'set', 'Disp12MaxDiff', value);
end
function value = get.MinDisparity(this)
value = StereoBM_(this.id, 'get', 'MinDisparity');
end
function set.MinDisparity(this, value)
StereoBM_(this.id, 'set', 'MinDisparity', value);
end
function value = get.NumDisparities(this)
value = StereoBM_(this.id, 'get', 'NumDisparities');
end
function set.NumDisparities(this, value)
StereoBM_(this.id, 'set', 'NumDisparities', value);
end
function value = get.SpeckleRange(this)
value = StereoBM_(this.id, 'get', 'SpeckleRange');
end
function set.SpeckleRange(this, value)
StereoBM_(this.id, 'set', 'SpeckleRange', value);
end
function value = get.SpeckleWindowSize(this)
value = StereoBM_(this.id, 'get', 'SpeckleWindowSize');
end
function set.SpeckleWindowSize(this, value)
StereoBM_(this.id, 'set', 'SpeckleWindowSize', value);
end
end
end