@@ -154,6 +154,64 @@ to the flow in the horizontal direction (u), second - vertical (v).
154
154
*/
155
155
CV_EXPORTS_W bool writeOpticalFlow ( const String& path, InputArray flow );
156
156
157
+ /* * @brief Variational optical flow refinement
158
+
159
+ This class implements variational refinement of the input flow field, i.e.
160
+ it uses input flow to initialize the minimization of the following functional:
161
+ \f$E(U) = \int_{\Omega} \delta \Psi(E_I) + \gamma \Psi(E_G) + \alpha \Psi(E_S) \f$,
162
+ where \f$E_I,E_G,E_S\f$ are color constancy, gradient constancy and smoothness terms
163
+ respectively. \f$\Psi(s^2)=\sqrt{s^2+\epsilon^2}\f$ is a robust penalizer to limit the
164
+ influence of outliers. A complete formulation and a description of the minimization
165
+ procedure can be found in @cite Brox2004
166
+ */
167
+ class CV_EXPORTS_W VariationalRefinement : public DenseOpticalFlow
168
+ {
169
+ public:
170
+ /* * @brief calc function overload to handle separate horizontal (u) and vertical (v) flow components
171
+ (to avoid extra splits/merges) */
172
+ CV_WRAP virtual void calcUV (InputArray I0, InputArray I1, InputOutputArray flow_u, InputOutputArray flow_v) = 0;
173
+
174
+ /* * @brief Number of outer (fixed-point) iterations in the minimization procedure.
175
+ @see setFixedPointIterations */
176
+ CV_WRAP virtual int getFixedPointIterations () const = 0;
177
+ /* * @copybrief getFixedPointIterations @see getFixedPointIterations */
178
+ CV_WRAP virtual void setFixedPointIterations (int val) = 0;
179
+
180
+ /* * @brief Number of inner successive over-relaxation (SOR) iterations
181
+ in the minimization procedure to solve the respective linear system.
182
+ @see setSorIterations */
183
+ CV_WRAP virtual int getSorIterations () const = 0;
184
+ /* * @copybrief getSorIterations @see getSorIterations */
185
+ CV_WRAP virtual void setSorIterations (int val) = 0;
186
+
187
+ /* * @brief Relaxation factor in SOR
188
+ @see setOmega */
189
+ CV_WRAP virtual float getOmega () const = 0;
190
+ /* * @copybrief getOmega @see getOmega */
191
+ CV_WRAP virtual void setOmega (float val) = 0;
192
+
193
+ /* * @brief Weight of the smoothness term
194
+ @see setAlpha */
195
+ CV_WRAP virtual float getAlpha () const = 0;
196
+ /* * @copybrief getAlpha @see getAlpha */
197
+ CV_WRAP virtual void setAlpha (float val) = 0;
198
+
199
+ /* * @brief Weight of the color constancy term
200
+ @see setDelta */
201
+ CV_WRAP virtual float getDelta () const = 0;
202
+ /* * @copybrief getDelta @see getDelta */
203
+ CV_WRAP virtual void setDelta (float val) = 0;
204
+
205
+ /* * @brief Weight of the gradient constancy term
206
+ @see setGamma */
207
+ CV_WRAP virtual float getGamma () const = 0;
208
+ /* * @copybrief getGamma @see getGamma */
209
+ CV_WRAP virtual void setGamma (float val) = 0;
210
+ };
211
+
212
+ /* * @brief Creates an instance of VariationalRefinement
213
+ */
214
+ CV_EXPORTS_W Ptr<VariationalRefinement> createVariationalFlowRefinement ();
157
215
158
216
/* * @brief DeepFlow optical flow algorithm implementation.
159
217
@@ -194,40 +252,80 @@ CV_EXPORTS_W Ptr<DenseOpticalFlow> createOptFlow_SparseToDense();
194
252
/* * @brief DIS optical flow algorithm.
195
253
196
254
This class implements the Dense Inverse Search (DIS) optical flow algorithm. More
197
- details about the algorithm can be found at @cite Kroeger2016 .
255
+ details about the algorithm can be found at @cite Kroeger2016 . Includes three presets with preselected
256
+ parameters to provide reasonable trade-off between speed and quality. However, even the slowest preset is
257
+ still relatively fast, use DeepFlow if you need better quality and don't care about speed.
198
258
*/
199
259
class CV_EXPORTS_W DISOpticalFlow : public DenseOpticalFlow
200
260
{
201
261
public:
202
- /* * @brief Finest level of the gaussian pyramid on which the flow is computed (zero level
203
- corresponds to the original image resolution).The final flow is obtained by bilinear upscaling.
262
+ enum
263
+ {
264
+ PRESET_ULTRAFAST = 0 ,
265
+ PRESET_FAST = 1 ,
266
+ PRESET_MEDIUM = 2
267
+ };
268
+
269
+ /* * @brief Finest level of the Gaussian pyramid on which the flow is computed (zero level
270
+ corresponds to the original image resolution). The final flow is obtained by bilinear upscaling.
204
271
@see setFinestScale */
205
- virtual int getFinestScale () const = 0;
272
+ CV_WRAP virtual int getFinestScale () const = 0;
206
273
/* * @copybrief getFinestScale @see getFinestScale */
207
- virtual void setFinestScale (int val) = 0;
274
+ CV_WRAP virtual void setFinestScale (int val) = 0;
208
275
209
- /* * @brief Size of an image patch for matching (in pixels)
276
+ /* * @brief Size of an image patch for matching (in pixels). Normally, default 8x8 patches work well
277
+ enough in most cases.
210
278
@see setPatchSize */
211
- virtual int getPatchSize () const = 0;
279
+ CV_WRAP virtual int getPatchSize () const = 0;
212
280
/* * @copybrief getPatchSize @see getPatchSize */
213
- virtual void setPatchSize (int val) = 0;
281
+ CV_WRAP virtual void setPatchSize (int val) = 0;
214
282
215
- /* * @brief Stride between neighbor patches. Must be less than patch size.
283
+ /* * @brief Stride between neighbor patches. Must be less than patch size. Lower values correspond
284
+ to higher flow quality.
216
285
@see setPatchStride */
217
- virtual int getPatchStride () const = 0;
286
+ CV_WRAP virtual int getPatchStride () const = 0;
218
287
/* * @copybrief getPatchStride @see getPatchStride */
219
- virtual void setPatchStride (int val) = 0;
288
+ CV_WRAP virtual void setPatchStride (int val) = 0;
220
289
221
- /* * @brief number of gradient descent iterations in the patch inverse search stage
290
+ /* * @brief Maximum number of gradient descent iterations in the patch inverse search stage. Higher values
291
+ may improve quality in some cases.
222
292
@see setGradientDescentIterations */
223
- virtual int getGradientDescentIterations () const = 0;
293
+ CV_WRAP virtual int getGradientDescentIterations () const = 0;
294
+ /* * @copybrief getGradientDescentIterations @see getGradientDescentIterations */
295
+ CV_WRAP virtual void setGradientDescentIterations (int val) = 0;
296
+
297
+ /* * @brief Number of fixed point iterations of variational refinement per scale. Set to zero to
298
+ disable variational refinement completely. Higher values will typically result in more smooth and
299
+ high-quality flow.
300
+ @see setGradientDescentIterations */
301
+ CV_WRAP virtual int getVariationalRefinementIterations () const = 0;
224
302
/* * @copybrief getGradientDescentIterations @see getGradientDescentIterations */
225
- virtual void setGradientDescentIterations (int val) = 0;
303
+ CV_WRAP virtual void setVariationalRefinementIterations (int val) = 0;
304
+
305
+ /* * @brief Whether to use mean-normalization of patches when computing patch distance. It is turned on
306
+ by default as it typically provides a noticeable quality boost because of increased robustness to
307
+ illumanition variations. Turn it off if you are certain that your sequence does't contain any changes
308
+ in illumination.
309
+ @see setUseMeanNormalization */
310
+ CV_WRAP virtual bool getUseMeanNormalization () const = 0;
311
+ /* * @copybrief getUseMeanNormalization @see getUseMeanNormalization */
312
+ CV_WRAP virtual void setUseMeanNormalization (bool val) = 0;
313
+
314
+ /* * @brief Whether to use spatial propagation of good optical flow vectors. This option is turned on by
315
+ default, as it tends to work better on average and can sometimes help recover from major errors
316
+ introduced by the coarse-to-fine scheme employed by the DIS optical flow algorithm. Turning this
317
+ option off can make the output flow field a bit smoother, however.
318
+ @see setUseSpatialPropagation */
319
+ CV_WRAP virtual bool getUseSpatialPropagation () const = 0;
320
+ /* * @copybrief getUseSpatialPropagation @see getUseSpatialPropagation */
321
+ CV_WRAP virtual void setUseSpatialPropagation (bool val) = 0;
226
322
};
227
323
228
324
/* * @brief Creates an instance of DISOpticalFlow
325
+
326
+ @param preset one of PRESET_ULTRAFAST, PRESET_FAST and PRESET_MEDIUM
229
327
*/
230
- CV_EXPORTS_W Ptr<DISOpticalFlow> createOptFlow_DIS ();
328
+ CV_EXPORTS_W Ptr<DISOpticalFlow> createOptFlow_DIS (int preset = DISOpticalFlow::PRESET_FAST );
231
329
232
330
// ! @}
233
331
0 commit comments