1 /*M///////////////////////////////////////////////////////////////////////////////////////
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
5 // By downloading, copying, installing or using the software you agree to this license.
6 // If you do not agree to this license, do not download, install,
7 // copy or use the software.
11 // For Open Source Computer Vision Library
13 // Copyright (C) 2010-2012, Institute Of Software Chinese Academy Of Science, all rights reserved.
14 // Copyright (C) 2010-2012, Advanced Micro Devices, Inc., all rights reserved.
15 // Copyright (C) 2010-2012, Multicoreware, Inc., all rights reserved.
16 // Third party copyrights are property of their respective owners.
18 // Redistribution and use in source and binary forms, with or without modification,
19 // are permitted provided that the following conditions are met:
21 // * Redistribution's of source code must retain the above copyright notice,
22 // this list of conditions and the following disclaimer.
24 // * Redistribution's in binary form must reproduce the above copyright notice,
25 // this list of conditions and the following disclaimer in the documentation
26 // and/or other oclMaterials provided with the distribution.
28 // * The name of the copyright holders may not be used to endorse or promote products
29 // derived from this software without specific prior written permission.
31 // This software is provided by the copyright holders and contributors "as is" and
32 // any express or implied warranties, including, but not limited to, the implied
33 // warranties of merchantability and fitness for a particular purpose are disclaimed.
34 // In no event shall the Intel Corporation or contributors be liable for any direct,
35 // indirect, incidental, special, exemplary, or consequential damages
36 // (including, but not limited to, procurement of substitute goods or services;
37 // loss of use, data, or profits; or business interruption) however caused
38 // and on any theory of liability, whether in contract, strict liability,
39 // or tort (including negligence or otherwise) arising in any way out of
40 // the use of this software, even if advised of the possibility of such damage.
44 #ifndef __OPENCV_OCL_HPP__
45 #define __OPENCV_OCL_HPP__
50 #include "opencv2/core/core.hpp"
51 #include "opencv2/imgproc/imgproc.hpp"
52 #include "opencv2/objdetect/objdetect.hpp"
53 #include "opencv2/features2d/features2d.hpp"
62 CVCL_DEVICE_TYPE_DEFAULT = (1 << 0),
63 CVCL_DEVICE_TYPE_CPU = (1 << 1),
64 CVCL_DEVICE_TYPE_GPU = (1 << 2),
65 CVCL_DEVICE_TYPE_ACCELERATOR = (1 << 3),
66 //CVCL_DEVICE_TYPE_CUSTOM = (1 << 4)
67 CVCL_DEVICE_TYPE_ALL = 0xFFFFFFFF
79 DEVICE_MEM_DEFAULT = 0,
80 DEVICE_MEM_AHP, //alloc host pointer
81 DEVICE_MEM_UHP, //use host pointer
82 DEVICE_MEM_CHP, //copy host pointer
83 DEVICE_MEM_PM //persistent memory
86 //Get the global device memory and read/write type
87 //return 1 if unified memory system supported, otherwise return 0
88 CV_EXPORTS int getDevMemType(DevMemRW& rw_type, DevMemType& mem_type);
90 //Set the global device memory and read/write type,
91 //the newly generated oclMat will all use this type
92 //return -1 if the target type is unsupported, otherwise return 0
93 CV_EXPORTS int setDevMemType(DevMemRW rw_type = DEVICE_MEM_R_W, DevMemType mem_type = DEVICE_MEM_DEFAULT);
95 //this class contains ocl runtime information
106 Info &operator = (const Info &m);
107 std::vector<string> DeviceName;
109 //////////////////////////////// Initialization & Info ////////////////////////
110 //this function may be obsoleted
111 //CV_EXPORTS cl_device_id getDevice();
112 //the function must be called before any other cv::ocl::functions, it initialize ocl runtime
113 //each Info relates to an OpenCL platform
114 //there is one or more devices in each platform, each one has a separate name
115 CV_EXPORTS int getDevice(std::vector<Info> &oclinfo, int devicetype = CVCL_DEVICE_TYPE_GPU);
117 //set device you want to use, optional function after getDevice be called
118 //the devnum is the index of the selected device in DeviceName vector of INfo
119 CV_EXPORTS void setDevice(Info &oclinfo, int devnum = 0);
121 //The two functions below enable other opencl program to use ocl module's cl_context and cl_command_queue
122 //returns cl_context *
123 CV_EXPORTS void* getoclContext();
124 //returns cl_command_queue *
125 CV_EXPORTS void* getoclCommandQueue();
127 //explicit call clFinish. The global command queue will be used.
128 CV_EXPORTS void finish();
130 //this function enable ocl module to use customized cl_context and cl_command_queue
131 //getDevice also need to be called before this function
132 CV_EXPORTS void setDeviceEx(Info &oclinfo, void *ctx, void *qu, int devnum = 0);
134 //returns true when global OpenCL context is initialized
135 CV_EXPORTS bool initialized();
137 //////////////////////////////// Error handling ////////////////////////
138 CV_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func);
140 //////////////////////////////// OpenCL context ////////////////////////
141 //This is a global singleton class used to represent a OpenCL context.
142 class CV_EXPORTS Context
146 friend class auto_ptr<Context>;
147 friend bool initialized();
149 static auto_ptr<Context> clCxt;
156 static Context* getContext();
157 static void setContext(Info &oclinfo);
159 enum {CL_DOUBLE, CL_UNIFIED_MEM, CL_VER_1_2};
160 bool supportsFeature(int ftype);
161 size_t computeUnits();
163 void* oclCommandQueue();
166 //! Calls a kernel, by string. Pass globalThreads = NULL, and cleanUp = true, to finally clean-up without executing.
167 CV_EXPORTS double openCLExecuteKernelInterop(Context *clCxt ,
168 const char **source, string kernelName,
169 size_t globalThreads[3], size_t localThreads[3],
170 std::vector< std::pair<size_t, const void *> > &args,
171 int channels, int depth, const char *build_options,
172 bool finish = true, bool measureKernelTime = false,
173 bool cleanUp = true);
175 //! Calls a kernel, by file. Pass globalThreads = NULL, and cleanUp = true, to finally clean-up without executing.
176 CV_EXPORTS double openCLExecuteKernelInterop(Context *clCxt ,
177 const char **fileName, const int numFiles, string kernelName,
178 size_t globalThreads[3], size_t localThreads[3],
179 std::vector< std::pair<size_t, const void *> > &args,
180 int channels, int depth, const char *build_options,
181 bool finish = true, bool measureKernelTime = false,
182 bool cleanUp = true);
184 //! Enable or disable OpenCL program binary caching onto local disk
185 // After a program (*.cl files in opencl/ folder) is built at runtime, we allow the
186 // compiled OpenCL program to be cached to the path automatically as "path/*.clb"
187 // binary file, which will be reused when the OpenCV executable is started again.
189 // Caching mode is controlled by the following enums
191 // 1. the feature is by default enabled when OpenCV is built in release mode.
192 // 2. the CACHE_DEBUG / CACHE_RELEASE flags only effectively work with MSVC compiler;
193 // for GNU compilers, the function always treats the build as release mode (enabled by default).
196 CACHE_NONE = 0, // do not cache OpenCL binary
197 CACHE_DEBUG = 0x1 << 0, // cache OpenCL binary when built in debug mode (only work with MSVC)
198 CACHE_RELEASE = 0x1 << 1, // default behavior, only cache when built in release mode (only work with MSVC)
199 CACHE_ALL = CACHE_DEBUG | CACHE_RELEASE, // always cache opencl binary
200 CACHE_UPDATE = 0x1 << 2 // if the binary cache file with the same name is already on the disk, it will be updated.
202 CV_EXPORTS void setBinaryDiskCache(int mode = CACHE_RELEASE, cv::String path = "./");
204 //! set where binary cache to be saved to
205 CV_EXPORTS void setBinpath(const char *path);
207 class CV_EXPORTS oclMatExpr;
208 //////////////////////////////// oclMat ////////////////////////////////
209 class CV_EXPORTS oclMat
212 //! default constructor
214 //! constructs oclMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
215 oclMat(int rows, int cols, int type);
216 oclMat(Size size, int type);
217 //! constucts oclMatrix and fills it with the specified value _s.
218 oclMat(int rows, int cols, int type, const Scalar &s);
219 oclMat(Size size, int type, const Scalar &s);
221 oclMat(const oclMat &m);
223 //! constructor for oclMatrix headers pointing to user-allocated data
224 oclMat(int rows, int cols, int type, void *data, size_t step = Mat::AUTO_STEP);
225 oclMat(Size size, int type, void *data, size_t step = Mat::AUTO_STEP);
227 //! creates a matrix header for a part of the bigger matrix
228 oclMat(const oclMat &m, const Range &rowRange, const Range &colRange);
229 oclMat(const oclMat &m, const Rect &roi);
231 //! builds oclMat from Mat. Perfom blocking upload to device.
232 explicit oclMat (const Mat &m);
234 //! destructor - calls release()
237 //! assignment operators
238 oclMat &operator = (const oclMat &m);
239 //! assignment operator. Perfom blocking upload to device.
240 oclMat &operator = (const Mat &m);
241 oclMat &operator = (const oclMatExpr& expr);
243 //! pefroms blocking upload data to oclMat.
244 void upload(const cv::Mat &m);
247 //! downloads data from device to host memory. Blocking calls.
248 operator Mat() const;
249 void download(cv::Mat &m) const;
251 //! convert to _InputArray
252 operator _InputArray();
254 //! convert to _OutputArray
255 operator _OutputArray();
257 //! returns a new oclMatrix header for the specified row
258 oclMat row(int y) const;
259 //! returns a new oclMatrix header for the specified column
260 oclMat col(int x) const;
261 //! ... for the specified row span
262 oclMat rowRange(int startrow, int endrow) const;
263 oclMat rowRange(const Range &r) const;
264 //! ... for the specified column span
265 oclMat colRange(int startcol, int endcol) const;
266 oclMat colRange(const Range &r) const;
268 //! returns deep copy of the oclMatrix, i.e. the data is copied
269 oclMat clone() const;
270 //! copies the oclMatrix content to "m".
271 // It calls m.create(this->size(), this->type()).
272 // It supports any data type
273 void copyTo( oclMat &m ) const;
274 //! copies those oclMatrix elements to "m" that are marked with non-zero mask elements.
275 //It supports 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4
276 void copyTo( oclMat &m, const oclMat &mask ) const;
277 //! converts oclMatrix to another datatype with optional scalng. See cvConvertScale.
278 //It supports 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4
279 void convertTo( oclMat &m, int rtype, double alpha = 1, double beta = 0 ) const;
281 void assignTo( oclMat &m, int type = -1 ) const;
283 //! sets every oclMatrix element to s
284 //It supports 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4
285 oclMat& operator = (const Scalar &s);
286 //! sets some of the oclMatrix elements to s, according to the mask
287 //It supports 8UC1 8UC4 32SC1 32SC4 32FC1 32FC4
288 oclMat& setTo(const Scalar &s, const oclMat &mask = oclMat());
289 //! creates alternative oclMatrix header for the same data, with different
290 // number of channels and/or different number of rows. see cvReshape.
291 oclMat reshape(int cn, int rows = 0) const;
293 //! allocates new oclMatrix data unless the oclMatrix already has specified size and type.
294 // previous data is unreferenced if needed.
295 void create(int rows, int cols, int type);
296 void create(Size size, int type);
298 //! allocates new oclMatrix with specified device memory type.
299 void createEx(int rows, int cols, int type, DevMemRW rw_type, DevMemType mem_type);
300 void createEx(Size size, int type, DevMemRW rw_type, DevMemType mem_type);
302 //! decreases reference counter;
303 // deallocate the data when reference counter reaches 0.
306 //! swaps with other smart pointer
307 void swap(oclMat &mat);
309 //! locates oclMatrix header within a parent oclMatrix. See below
310 void locateROI( Size &wholeSize, Point &ofs ) const;
311 //! moves/resizes the current oclMatrix ROI inside the parent oclMatrix.
312 oclMat& adjustROI( int dtop, int dbottom, int dleft, int dright );
313 //! extracts a rectangular sub-oclMatrix
314 // (this is a generalized form of row, rowRange etc.)
315 oclMat operator()( Range rowRange, Range colRange ) const;
316 oclMat operator()( const Rect &roi ) const;
318 oclMat& operator+=( const oclMat& m );
319 oclMat& operator-=( const oclMat& m );
320 oclMat& operator*=( const oclMat& m );
321 oclMat& operator/=( const oclMat& m );
323 //! returns true if the oclMatrix data is continuous
324 // (i.e. when there are no gaps between successive rows).
325 // similar to CV_IS_oclMat_CONT(cvoclMat->type)
326 bool isContinuous() const;
327 //! returns element size in bytes,
328 // similar to CV_ELEM_SIZE(cvMat->type)
329 size_t elemSize() const;
330 //! returns the size of element channel in bytes.
331 size_t elemSize1() const;
332 //! returns element type, similar to CV_MAT_TYPE(cvMat->type)
334 //! returns element type, i.e. 8UC3 returns 8UC4 because in ocl
335 //! 3 channels element actually use 4 channel space
337 //! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
339 //! returns element type, similar to CV_MAT_CN(cvMat->type)
340 int channels() const;
341 //! returns element type, return 4 for 3 channels element,
342 //!becuase 3 channels element actually use 4 channel space
343 int oclchannels() const;
344 //! returns step/elemSize1()
345 size_t step1() const;
346 //! returns oclMatrix size:
347 // width == number of columns, height == number of rows
349 //! returns true if oclMatrix data is NULL
352 //! returns pointer to y-th row
353 uchar* ptr(int y = 0);
354 const uchar *ptr(int y = 0) const;
356 //! template version of the above method
357 template<typename _Tp> _Tp *ptr(int y = 0);
358 template<typename _Tp> const _Tp *ptr(int y = 0) const;
360 //! matrix transposition
363 /*! includes several bit-fields:
364 - the magic signature
370 //! the number of rows and columns
372 //! a distance between successive rows in bytes; includes the gap if any
374 //! pointer to the data(OCL memory object)
377 //! pointer to the reference counter;
378 // when oclMatrix points to user-allocated data, the pointer is NULL
381 //! helper fields used in locateROI and adjustROI
382 //datastart and dataend are not used in current version
386 //! OpenCL context associated with the oclMat object.
388 //add offset for handle ROI, calculated in byte
390 //add wholerows and wholecols for the whole matrix, datastart and dataend are no longer used
395 // convert InputArray/OutputArray to oclMat references
396 CV_EXPORTS oclMat& getOclMatRef(InputArray src);
397 CV_EXPORTS oclMat& getOclMatRef(OutputArray src);
399 ///////////////////// mat split and merge /////////////////////////////////
400 //! Compose a multi-channel array from several single-channel arrays
402 CV_EXPORTS void merge(const oclMat *src, size_t n, oclMat &dst);
403 CV_EXPORTS void merge(const vector<oclMat> &src, oclMat &dst);
405 //! Divides multi-channel array into several single-channel arrays
407 CV_EXPORTS void split(const oclMat &src, oclMat *dst);
408 CV_EXPORTS void split(const oclMat &src, vector<oclMat> &dst);
410 ////////////////////////////// Arithmetics ///////////////////////////////////
411 //#if defined DOUBLE_SUPPORT
416 // CV_EXPORTS void addWeighted(const oclMat& a,F alpha, const oclMat& b,F beta,F gama, oclMat& c);
417 CV_EXPORTS void addWeighted(const oclMat &a, double alpha, const oclMat &b, double beta, double gama, oclMat &c);
418 //! adds one matrix to another (c = a + b)
419 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
420 CV_EXPORTS void add(const oclMat &a, const oclMat &b, oclMat &c);
421 //! adds one matrix to another (c = a + b)
422 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
423 CV_EXPORTS void add(const oclMat &a, const oclMat &b, oclMat &c, const oclMat &mask);
424 //! adds scalar to a matrix (c = a + s)
425 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
426 CV_EXPORTS void add(const oclMat &a, const Scalar &sc, oclMat &c, const oclMat &mask = oclMat());
427 //! subtracts one matrix from another (c = a - b)
428 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
429 CV_EXPORTS void subtract(const oclMat &a, const oclMat &b, oclMat &c);
430 //! subtracts one matrix from another (c = a - b)
431 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
432 CV_EXPORTS void subtract(const oclMat &a, const oclMat &b, oclMat &c, const oclMat &mask);
433 //! subtracts scalar from a matrix (c = a - s)
434 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
435 CV_EXPORTS void subtract(const oclMat &a, const Scalar &sc, oclMat &c, const oclMat &mask = oclMat());
436 //! subtracts scalar from a matrix (c = a - s)
437 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
438 CV_EXPORTS void subtract(const Scalar &sc, const oclMat &a, oclMat &c, const oclMat &mask = oclMat());
439 //! computes element-wise product of the two arrays (c = a * b)
440 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
441 CV_EXPORTS void multiply(const oclMat &a, const oclMat &b, oclMat &c, double scale = 1);
442 //! multiplies matrix to a number (dst = scalar * src)
443 // supports CV_32FC1 only
444 CV_EXPORTS void multiply(double scalar, const oclMat &src, oclMat &dst);
445 //! computes element-wise quotient of the two arrays (c = a / b)
446 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
447 CV_EXPORTS void divide(const oclMat &a, const oclMat &b, oclMat &c, double scale = 1);
448 //! computes element-wise quotient of the two arrays (c = a / b)
449 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
450 CV_EXPORTS void divide(double scale, const oclMat &b, oclMat &c);
452 //! compares elements of two arrays (c = a <cmpop> b)
453 // supports except CV_8SC1,CV_8SC2,CV8SC3,CV_8SC4 types
454 CV_EXPORTS void compare(const oclMat &a, const oclMat &b, oclMat &c, int cmpop);
456 //! transposes the matrix
457 // supports CV_8UC1, 8UC4, 8SC4, 16UC2, 16SC2, 32SC1 and 32FC1.(the same as cuda)
458 CV_EXPORTS void transpose(const oclMat &src, oclMat &dst);
460 //! computes element-wise absolute difference of two arrays (c = abs(a - b))
461 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
462 CV_EXPORTS void absdiff(const oclMat &a, const oclMat &b, oclMat &c);
463 //! computes element-wise absolute difference of array and scalar (c = abs(a - s))
464 // supports all types except CV_8SC1,CV_8SC2,CV8SC3 and CV_8SC4
465 CV_EXPORTS void absdiff(const oclMat &a, const Scalar &s, oclMat &c);
467 //! computes mean value and standard deviation of all or selected array elements
468 // supports except CV_32F,CV_64F
469 CV_EXPORTS void meanStdDev(const oclMat &mtx, Scalar &mean, Scalar &stddev);
471 //! computes norm of array
472 // supports NORM_INF, NORM_L1, NORM_L2
473 // supports only CV_8UC1 type
474 CV_EXPORTS double norm(const oclMat &src1, int normType = NORM_L2);
476 //! computes norm of the difference between two arrays
477 // supports NORM_INF, NORM_L1, NORM_L2
478 // supports only CV_8UC1 type
479 CV_EXPORTS double norm(const oclMat &src1, const oclMat &src2, int normType = NORM_L2);
481 //! reverses the order of the rows, columns or both in a matrix
482 // supports all types
483 CV_EXPORTS void flip(const oclMat &a, oclMat &b, int flipCode);
485 //! computes sum of array elements
486 // disabled until fix crash
488 CV_EXPORTS Scalar sum(const oclMat &m);
489 CV_EXPORTS Scalar absSum(const oclMat &m);
490 CV_EXPORTS Scalar sqrSum(const oclMat &m);
492 //! finds global minimum and maximum array elements and returns their values
493 // support all C1 types
495 CV_EXPORTS void minMax(const oclMat &src, double *minVal, double *maxVal = 0, const oclMat &mask = oclMat());
496 CV_EXPORTS void minMax_buf(const oclMat &src, double *minVal, double *maxVal, const oclMat &mask, oclMat& buf);
498 //! finds global minimum and maximum array elements and returns their values with locations
499 // support all C1 types
501 CV_EXPORTS void minMaxLoc(const oclMat &src, double *minVal, double *maxVal = 0, Point *minLoc = 0, Point *maxLoc = 0,
502 const oclMat &mask = oclMat());
504 //! counts non-zero array elements
506 CV_EXPORTS int countNonZero(const oclMat &src);
508 //! transforms 8-bit unsigned integers using lookup table: dst(i)=lut(src(i))
509 // destination array will have the depth type as lut and the same channels number as source
510 //It supports 8UC1 8UC4 only
511 CV_EXPORTS void LUT(const oclMat &src, const oclMat &lut, oclMat &dst);
513 //! only 8UC1 and 256 bins is supported now
514 CV_EXPORTS void calcHist(const oclMat &mat_src, oclMat &mat_hist);
515 //! only 8UC1 and 256 bins is supported now
516 CV_EXPORTS void equalizeHist(const oclMat &mat_src, oclMat &mat_dst);
518 //! only 8UC1 is supported now
519 CV_EXPORTS Ptr<cv::CLAHE> createCLAHE(double clipLimit = 40.0, Size tileGridSize = Size(8, 8));
522 // supports 8UC1 8UC4
523 CV_EXPORTS void bilateralFilter(const oclMat& src, oclMat& dst, int d, double sigmaColor, double sigmaSpave, int borderType=BORDER_DEFAULT);
524 //! computes exponent of each matrix element (b = e**a)
525 // supports only CV_32FC1 type
526 CV_EXPORTS void exp(const oclMat &a, oclMat &b);
528 //! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))
529 // supports only CV_32FC1 type
530 CV_EXPORTS void log(const oclMat &a, oclMat &b);
532 //! computes magnitude of each (x(i), y(i)) vector
533 // supports only CV_32F CV_64F type
534 CV_EXPORTS void magnitude(const oclMat &x, const oclMat &y, oclMat &magnitude);
535 CV_EXPORTS void magnitudeSqr(const oclMat &x, const oclMat &y, oclMat &magnitude);
537 CV_EXPORTS void magnitudeSqr(const oclMat &x, oclMat &magnitude);
539 //! computes angle (angle(i)) of each (x(i), y(i)) vector
540 // supports only CV_32F CV_64F type
541 CV_EXPORTS void phase(const oclMat &x, const oclMat &y, oclMat &angle, bool angleInDegrees = false);
543 //! the function raises every element of tne input array to p
544 //! support only CV_32F CV_64F type
545 CV_EXPORTS void pow(const oclMat &x, double p, oclMat &y);
547 //! converts Cartesian coordinates to polar
548 // supports only CV_32F CV_64F type
549 CV_EXPORTS void cartToPolar(const oclMat &x, const oclMat &y, oclMat &magnitude, oclMat &angle, bool angleInDegrees = false);
551 //! converts polar coordinates to Cartesian
552 // supports only CV_32F CV_64F type
553 CV_EXPORTS void polarToCart(const oclMat &magnitude, const oclMat &angle, oclMat &x, oclMat &y, bool angleInDegrees = false);
555 //! perfroms per-elements bit-wise inversion
556 // supports all types
557 CV_EXPORTS void bitwise_not(const oclMat &src, oclMat &dst);
558 //! calculates per-element bit-wise disjunction of two arrays
559 // supports all types
560 CV_EXPORTS void bitwise_or(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask = oclMat());
561 CV_EXPORTS void bitwise_or(const oclMat &src1, const Scalar &s, oclMat &dst, const oclMat &mask = oclMat());
562 //! calculates per-element bit-wise conjunction of two arrays
563 // supports all types
564 CV_EXPORTS void bitwise_and(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask = oclMat());
565 CV_EXPORTS void bitwise_and(const oclMat &src1, const Scalar &s, oclMat &dst, const oclMat &mask = oclMat());
566 //! calculates per-element bit-wise "exclusive or" operation
567 // supports all types
568 CV_EXPORTS void bitwise_xor(const oclMat &src1, const oclMat &src2, oclMat &dst, const oclMat &mask = oclMat());
569 CV_EXPORTS void bitwise_xor(const oclMat &src1, const Scalar &s, oclMat &dst, const oclMat &mask = oclMat());
571 //! Logical operators
572 CV_EXPORTS oclMat operator ~ (const oclMat &);
573 CV_EXPORTS oclMat operator | (const oclMat &, const oclMat &);
574 CV_EXPORTS oclMat operator & (const oclMat &, const oclMat &);
575 CV_EXPORTS oclMat operator ^ (const oclMat &, const oclMat &);
578 //! Mathematics operators
579 CV_EXPORTS oclMatExpr operator + (const oclMat &src1, const oclMat &src2);
580 CV_EXPORTS oclMatExpr operator - (const oclMat &src1, const oclMat &src2);
581 CV_EXPORTS oclMatExpr operator * (const oclMat &src1, const oclMat &src2);
582 CV_EXPORTS oclMatExpr operator / (const oclMat &src1, const oclMat &src2);
584 //! computes convolution of two images
585 //! support only CV_32FC1 type
586 CV_EXPORTS void convolve(const oclMat &image, const oclMat &temp1, oclMat &result);
588 CV_EXPORTS void cvtColor(const oclMat &src, oclMat &dst, int code , int dcn = 0);
590 //////////////////////////////// Filter Engine ////////////////////////////////
593 The Base Class for 1D or Row-wise Filters
595 This is the base class for linear or non-linear filters that process 1D data.
596 In particular, such filters are used for the "horizontal" filtering parts in separable filters.
598 class CV_EXPORTS BaseRowFilter_GPU
601 BaseRowFilter_GPU(int ksize_, int anchor_, int bordertype_) : ksize(ksize_), anchor(anchor_), bordertype(bordertype_) {}
602 virtual ~BaseRowFilter_GPU() {}
603 virtual void operator()(const oclMat &src, oclMat &dst) = 0;
604 int ksize, anchor, bordertype;
608 The Base Class for Column-wise Filters
610 This is the base class for linear or non-linear filters that process columns of 2D arrays.
611 Such filters are used for the "vertical" filtering parts in separable filters.
613 class CV_EXPORTS BaseColumnFilter_GPU
616 BaseColumnFilter_GPU(int ksize_, int anchor_, int bordertype_) : ksize(ksize_), anchor(anchor_), bordertype(bordertype_) {}
617 virtual ~BaseColumnFilter_GPU() {}
618 virtual void operator()(const oclMat &src, oclMat &dst) = 0;
619 int ksize, anchor, bordertype;
623 The Base Class for Non-Separable 2D Filters.
625 This is the base class for linear or non-linear 2D filters.
627 class CV_EXPORTS BaseFilter_GPU
630 BaseFilter_GPU(const Size &ksize_, const Point &anchor_, const int &borderType_)
631 : ksize(ksize_), anchor(anchor_), borderType(borderType_) {}
632 virtual ~BaseFilter_GPU() {}
633 virtual void operator()(const oclMat &src, oclMat &dst) = 0;
640 The Base Class for Filter Engine.
642 The class can be used to apply an arbitrary filtering operation to an image.
643 It contains all the necessary intermediate buffers.
645 class CV_EXPORTS FilterEngine_GPU
648 virtual ~FilterEngine_GPU() {}
650 virtual void apply(const oclMat &src, oclMat &dst, Rect roi = Rect(0, 0, -1, -1)) = 0;
653 //! returns the non-separable filter engine with the specified filter
654 CV_EXPORTS Ptr<FilterEngine_GPU> createFilter2D_GPU(const Ptr<BaseFilter_GPU> filter2D);
656 //! returns the primitive row filter with the specified kernel
657 CV_EXPORTS Ptr<BaseRowFilter_GPU> getLinearRowFilter_GPU(int srcType, int bufType, const Mat &rowKernel,
658 int anchor = -1, int bordertype = BORDER_DEFAULT);
660 //! returns the primitive column filter with the specified kernel
661 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getLinearColumnFilter_GPU(int bufType, int dstType, const Mat &columnKernel,
662 int anchor = -1, int bordertype = BORDER_DEFAULT, double delta = 0.0);
664 //! returns the separable linear filter engine
665 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat &rowKernel,
666 const Mat &columnKernel, const Point &anchor = Point(-1, -1), double delta = 0.0, int bordertype = BORDER_DEFAULT);
668 //! returns the separable filter engine with the specified filters
669 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU> &rowFilter,
670 const Ptr<BaseColumnFilter_GPU> &columnFilter);
672 //! returns the Gaussian filter engine
673 CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, double sigma1, double sigma2 = 0, int bordertype = BORDER_DEFAULT);
675 //! returns filter engine for the generalized Sobel operator
676 CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU( int srcType, int dstType, int dx, int dy, int ksize, int borderType = BORDER_DEFAULT );
678 //! applies Laplacian operator to the image
679 // supports only ksize = 1 and ksize = 3 8UC1 8UC4 32FC1 32FC4 data type
680 CV_EXPORTS void Laplacian(const oclMat &src, oclMat &dst, int ddepth, int ksize = 1, double scale = 1);
682 //! returns 2D box filter
683 // supports CV_8UC1 and CV_8UC4 source type, dst type must be the same as source type
684 CV_EXPORTS Ptr<BaseFilter_GPU> getBoxFilter_GPU(int srcType, int dstType,
685 const Size &ksize, Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
687 //! returns box filter engine
688 CV_EXPORTS Ptr<FilterEngine_GPU> createBoxFilter_GPU(int srcType, int dstType, const Size &ksize,
689 const Point &anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
691 //! returns 2D filter with the specified kernel
692 // supports CV_8UC1 and CV_8UC4 types
693 CV_EXPORTS Ptr<BaseFilter_GPU> getLinearFilter_GPU(int srcType, int dstType, const Mat &kernel, const Size &ksize,
694 Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
696 //! returns the non-separable linear filter engine
697 CV_EXPORTS Ptr<FilterEngine_GPU> createLinearFilter_GPU(int srcType, int dstType, const Mat &kernel,
698 const Point &anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
700 //! smooths the image using the normalized box filter
701 // supports data type: CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4
702 // supports border type: BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT,BORDER_REFLECT_101,BORDER_WRAP
703 CV_EXPORTS void boxFilter(const oclMat &src, oclMat &dst, int ddepth, Size ksize,
704 Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
706 //! returns 2D morphological filter
707 //! only MORPH_ERODE and MORPH_DILATE are supported
708 // supports CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4 types
709 // kernel must have CV_8UC1 type, one rows and cols == ksize.width * ksize.height
710 CV_EXPORTS Ptr<BaseFilter_GPU> getMorphologyFilter_GPU(int op, int type, const Mat &kernel, const Size &ksize,
711 Point anchor = Point(-1, -1));
713 //! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported.
714 CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat &kernel,
715 const Point &anchor = Point(-1, -1), int iterations = 1);
717 //! a synonym for normalized box filter
718 // supports data type: CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4
719 // supports border type: BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT,BORDER_REFLECT_101
720 static inline void blur(const oclMat &src, oclMat &dst, Size ksize, Point anchor = Point(-1, -1),
721 int borderType = BORDER_CONSTANT)
723 boxFilter(src, dst, -1, ksize, anchor, borderType);
726 //! applies non-separable 2D linear filter to the image
727 // Note, at the moment this function only works when anchor point is in the kernel center
728 // and kernel size supported is either 3x3 or 5x5; otherwise the function will fail to output valid result
729 CV_EXPORTS void filter2D(const oclMat &src, oclMat &dst, int ddepth, const Mat &kernel,
730 Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
732 //! applies separable 2D linear filter to the image
733 CV_EXPORTS void sepFilter2D(const oclMat &src, oclMat &dst, int ddepth, const Mat &kernelX, const Mat &kernelY,
734 Point anchor = Point(-1, -1), double delta = 0.0, int bordertype = BORDER_DEFAULT);
736 //! applies generalized Sobel operator to the image
737 // dst.type must equalize src.type
738 // supports data type: CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4
739 // supports border type: BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT,BORDER_REFLECT_101
740 CV_EXPORTS void Sobel(const oclMat &src, oclMat &dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1, double delta = 0.0, int bordertype = BORDER_DEFAULT);
742 //! applies the vertical or horizontal Scharr operator to the image
743 // dst.type must equalize src.type
744 // supports data type: CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4
745 // supports border type: BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT,BORDER_REFLECT_101
746 CV_EXPORTS void Scharr(const oclMat &src, oclMat &dst, int ddepth, int dx, int dy, double scale = 1, double delta = 0.0, int bordertype = BORDER_DEFAULT);
748 //! smooths the image using Gaussian filter.
749 // dst.type must equalize src.type
750 // supports data type: CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4
751 // supports border type: BORDER_CONSTANT, BORDER_REPLICATE, BORDER_REFLECT,BORDER_REFLECT_101
752 CV_EXPORTS void GaussianBlur(const oclMat &src, oclMat &dst, Size ksize, double sigma1, double sigma2 = 0, int bordertype = BORDER_DEFAULT);
754 //! erodes the image (applies the local minimum operator)
755 // supports data type: CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4
756 CV_EXPORTS void erode( const oclMat &src, oclMat &dst, const Mat &kernel, Point anchor = Point(-1, -1), int iterations = 1,
758 int borderType = BORDER_CONSTANT, const Scalar &borderValue = morphologyDefaultBorderValue());
761 //! dilates the image (applies the local maximum operator)
762 // supports data type: CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4
763 CV_EXPORTS void dilate( const oclMat &src, oclMat &dst, const Mat &kernel, Point anchor = Point(-1, -1), int iterations = 1,
765 int borderType = BORDER_CONSTANT, const Scalar &borderValue = morphologyDefaultBorderValue());
768 //! applies an advanced morphological operation to the image
769 CV_EXPORTS void morphologyEx( const oclMat &src, oclMat &dst, int op, const Mat &kernel, Point anchor = Point(-1, -1), int iterations = 1,
771 int borderType = BORDER_CONSTANT, const Scalar &borderValue = morphologyDefaultBorderValue());
774 ////////////////////////////// Image processing //////////////////////////////
775 //! Does mean shift filtering on GPU.
776 CV_EXPORTS void meanShiftFiltering(const oclMat &src, oclMat &dst, int sp, int sr,
777 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
779 //! Does mean shift procedure on GPU.
780 CV_EXPORTS void meanShiftProc(const oclMat &src, oclMat &dstr, oclMat &dstsp, int sp, int sr,
781 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
783 //! Does mean shift segmentation with elimiation of small regions.
784 CV_EXPORTS void meanShiftSegmentation(const oclMat &src, Mat &dst, int sp, int sr, int minsize,
785 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
787 //! applies fixed threshold to the image.
788 // supports CV_8UC1 and CV_32FC1 data type
789 // supports threshold type: THRESH_BINARY, THRESH_BINARY_INV, THRESH_TRUNC, THRESH_TOZERO, THRESH_TOZERO_INV
790 CV_EXPORTS double threshold(const oclMat &src, oclMat &dst, double thresh, double maxVal, int type = THRESH_TRUNC);
792 //! resizes the image
793 // Supports INTER_NEAREST, INTER_LINEAR
794 // supports CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4 types
795 CV_EXPORTS void resize(const oclMat &src, oclMat &dst, Size dsize, double fx = 0, double fy = 0, int interpolation = INTER_LINEAR);
797 //! Applies a generic geometrical transformation to an image.
799 // Supports INTER_NEAREST, INTER_LINEAR.
801 // Map1 supports CV_16SC2, CV_32FC2 types.
803 // Src supports CV_8UC1, CV_8UC2, CV_8UC4.
805 CV_EXPORTS void remap(const oclMat &src, oclMat &dst, oclMat &map1, oclMat &map2, int interpolation, int bordertype, const Scalar &value = Scalar());
807 //! copies 2D array to a larger destination array and pads borders with user-specifiable constant
808 // supports CV_8UC1, CV_8UC4, CV_32SC1 types
809 CV_EXPORTS void copyMakeBorder(const oclMat &src, oclMat &dst, int top, int bottom, int left, int right, int boardtype, const Scalar &value = Scalar());
811 //! Smoothes image using median filter
812 // The source 1- or 4-channel image. When m is 3 or 5, the image depth should be CV 8U or CV 32F.
813 CV_EXPORTS void medianFilter(const oclMat &src, oclMat &dst, int m);
815 //! warps the image using affine transformation
816 // Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
817 // supports CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4 types
818 CV_EXPORTS void warpAffine(const oclMat &src, oclMat &dst, const Mat &M, Size dsize, int flags = INTER_LINEAR);
820 //! warps the image using perspective transformation
821 // Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
822 // supports CV_8UC1, CV_8UC4, CV_32FC1 and CV_32FC4 types
823 CV_EXPORTS void warpPerspective(const oclMat &src, oclMat &dst, const Mat &M, Size dsize, int flags = INTER_LINEAR);
825 //! computes the integral image and integral for the squared image
826 // sum will have CV_32S type, sqsum - CV32F type
827 // supports only CV_8UC1 source type
828 CV_EXPORTS void integral(const oclMat &src, oclMat &sum, oclMat &sqsum);
829 CV_EXPORTS void integral(const oclMat &src, oclMat &sum);
830 CV_EXPORTS void cornerHarris(const oclMat &src, oclMat &dst, int blockSize, int ksize, double k, int bordertype = cv::BORDER_DEFAULT);
831 CV_EXPORTS void cornerHarris_dxdy(const oclMat &src, oclMat &dst, oclMat &Dx, oclMat &Dy,
832 int blockSize, int ksize, double k, int bordertype = cv::BORDER_DEFAULT);
833 CV_EXPORTS void cornerMinEigenVal(const oclMat &src, oclMat &dst, int blockSize, int ksize, int bordertype = cv::BORDER_DEFAULT);
834 CV_EXPORTS void cornerMinEigenVal_dxdy(const oclMat &src, oclMat &dst, oclMat &Dx, oclMat &Dy,
835 int blockSize, int ksize, int bordertype = cv::BORDER_DEFAULT);
837 /////////////////////////////////// ML ///////////////////////////////////////////
839 //! Compute closest centers for each lines in source and lable it after center's index
840 // supports CV_32FC1/CV_32FC2/CV_32FC4 data type
841 CV_EXPORTS void distanceToCenters(oclMat &dists, oclMat &labels, const oclMat &src, const oclMat ¢ers);
843 //!Does k-means procedure on GPU
844 // supports CV_32FC1/CV_32FC2/CV_32FC4 data type
845 CV_EXPORTS double kmeans(const oclMat &src, int K, oclMat &bestLabels,
846 TermCriteria criteria, int attemps, int flags, oclMat ¢ers);
849 ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
850 ///////////////////////////////////////////CascadeClassifier//////////////////////////////////////////////////////////////////
851 ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
853 class CV_EXPORTS_W OclCascadeClassifier : public cv::CascadeClassifier
856 OclCascadeClassifier() {};
857 ~OclCascadeClassifier() {};
859 CvSeq* oclHaarDetectObjects(oclMat &gimg, CvMemStorage *storage, double scaleFactor,
860 int minNeighbors, int flags, CvSize minSize = cvSize(0, 0), CvSize maxSize = cvSize(0, 0));
863 class CV_EXPORTS OclCascadeClassifierBuf : public cv::CascadeClassifier
866 OclCascadeClassifierBuf() :
867 m_flags(0), initialized(false), m_scaleFactor(0), buffers(NULL) {}
869 ~OclCascadeClassifierBuf() { release(); }
871 void detectMultiScale(oclMat &image, CV_OUT std::vector<cv::Rect>& faces,
872 double scaleFactor = 1.1, int minNeighbors = 3, int flags = 0,
873 Size minSize = Size(), Size maxSize = Size());
877 void Init(const int rows, const int cols, double scaleFactor, int flags,
878 const int outputsz, const size_t localThreads[],
879 CvSize minSize, CvSize maxSize);
880 void CreateBaseBufs(const int datasize, const int totalclassifier, const int flags, const int outputsz);
881 void CreateFactorRelatedBufs(const int rows, const int cols, const int flags,
882 const double scaleFactor, const size_t localThreads[],
883 CvSize minSize, CvSize maxSize);
884 void GenResult(CV_OUT std::vector<cv::Rect>& faces, const std::vector<cv::Rect> &rectList, const std::vector<int> &rweights);
891 bool findBiggestObject;
893 double m_scaleFactor;
896 vector<CvSize> sizev;
897 vector<float> scalev;
898 oclMat gimg1, gsum, gsqsum;
903 /////////////////////////////// Pyramid /////////////////////////////////////
904 CV_EXPORTS void pyrDown(const oclMat &src, oclMat &dst);
906 //! upsamples the source image and then smoothes it
907 CV_EXPORTS void pyrUp(const oclMat &src, oclMat &dst);
909 //! performs linear blending of two images
910 //! to avoid accuracy errors sum of weigths shouldn't be very close to zero
911 // supports only CV_8UC1 source type
912 CV_EXPORTS void blendLinear(const oclMat &img1, const oclMat &img2, const oclMat &weights1, const oclMat &weights2, oclMat &result);
914 //! computes vertical sum, supports only CV_32FC1 images
915 CV_EXPORTS void columnSum(const oclMat &src, oclMat &sum);
917 ///////////////////////////////////////// match_template /////////////////////////////////////////////////////////////
918 struct CV_EXPORTS MatchTemplateBuf
920 Size user_block_size;
921 oclMat imagef, templf;
922 std::vector<oclMat> images;
923 std::vector<oclMat> image_sums;
924 std::vector<oclMat> image_sqsums;
927 //! computes the proximity map for the raster template and the image where the template is searched for
928 // Supports TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED for type 8UC1 and 8UC4
929 // Supports TM_SQDIFF, TM_CCORR for type 32FC1 and 32FC4
930 CV_EXPORTS void matchTemplate(const oclMat &image, const oclMat &templ, oclMat &result, int method);
932 //! computes the proximity map for the raster template and the image where the template is searched for
933 // Supports TM_SQDIFF, TM_SQDIFF_NORMED, TM_CCORR, TM_CCORR_NORMED, TM_CCOEFF, TM_CCOEFF_NORMED for type 8UC1 and 8UC4
934 // Supports TM_SQDIFF, TM_CCORR for type 32FC1 and 32FC4
935 CV_EXPORTS void matchTemplate(const oclMat &image, const oclMat &templ, oclMat &result, int method, MatchTemplateBuf &buf);
937 ///////////////////////////////////////////// Canny /////////////////////////////////////////////
938 struct CV_EXPORTS CannyBuf;
939 //! compute edges of the input image using Canny operator
940 // Support CV_8UC1 only
941 CV_EXPORTS void Canny(const oclMat &image, oclMat &edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
942 CV_EXPORTS void Canny(const oclMat &image, CannyBuf &buf, oclMat &edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
943 CV_EXPORTS void Canny(const oclMat &dx, const oclMat &dy, oclMat &edges, double low_thresh, double high_thresh, bool L2gradient = false);
944 CV_EXPORTS void Canny(const oclMat &dx, const oclMat &dy, CannyBuf &buf, oclMat &edges, double low_thresh, double high_thresh, bool L2gradient = false);
946 struct CV_EXPORTS CannyBuf
948 CannyBuf() : counter(NULL) {}
953 explicit CannyBuf(const Size &image_size, int apperture_size = 3) : counter(NULL)
955 create(image_size, apperture_size);
957 CannyBuf(const oclMat &dx_, const oclMat &dy_);
959 void create(const Size &image_size, int apperture_size = 3);
962 oclMat dx_buf, dy_buf;
964 oclMat trackBuf1, trackBuf2;
966 Ptr<FilterEngine_GPU> filterDX, filterDY;
969 ///////////////////////////////////////// clAmdFft related /////////////////////////////////////////
970 //! Performs a forward or inverse discrete Fourier transform (1D or 2D) of floating point matrix.
971 //! Param dft_size is the size of DFT transform.
973 //! For complex-to-real transform it is assumed that the source matrix is packed in CLFFT's format.
974 // support src type of CV32FC1, CV32FC2
975 // support flags: DFT_INVERSE, DFT_REAL_OUTPUT, DFT_COMPLEX_OUTPUT, DFT_ROWS
976 // dft_size is the size of original input, which is used for transformation from complex to real.
977 // dft_size must be powers of 2, 3 and 5
978 // real to complex dft requires at least v1.8 clAmdFft
979 // real to complex dft output is not the same with cpu version
980 // real to complex and complex to real does not support DFT_ROWS
981 CV_EXPORTS void dft(const oclMat &src, oclMat &dst, Size dft_size = Size(0, 0), int flags = 0);
983 //! implements generalized matrix product algorithm GEMM from BLAS
984 // The functionality requires clAmdBlas library
985 // only support type CV_32FC1
986 // flag GEMM_3_T is not supported
987 CV_EXPORTS void gemm(const oclMat &src1, const oclMat &src2, double alpha,
988 const oclMat &src3, double beta, oclMat &dst, int flags = 0);
990 //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
991 struct CV_EXPORTS HOGDescriptor
993 enum { DEFAULT_WIN_SIGMA = -1 };
994 enum { DEFAULT_NLEVELS = 64 };
995 enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
996 HOGDescriptor(Size win_size = Size(64, 128), Size block_size = Size(16, 16),
997 Size block_stride = Size(8, 8), Size cell_size = Size(8, 8),
998 int nbins = 9, double win_sigma = DEFAULT_WIN_SIGMA,
999 double threshold_L2hys = 0.2, bool gamma_correction = true,
1000 int nlevels = DEFAULT_NLEVELS);
1002 size_t getDescriptorSize() const;
1003 size_t getBlockHistogramSize() const;
1004 void setSVMDetector(const vector<float> &detector);
1005 static vector<float> getDefaultPeopleDetector();
1006 static vector<float> getPeopleDetector48x96();
1007 static vector<float> getPeopleDetector64x128();
1008 void detect(const oclMat &img, vector<Point> &found_locations,
1009 double hit_threshold = 0, Size win_stride = Size(),
1010 Size padding = Size());
1011 void detectMultiScale(const oclMat &img, vector<Rect> &found_locations,
1012 double hit_threshold = 0, Size win_stride = Size(),
1013 Size padding = Size(), double scale0 = 1.05,
1014 int group_threshold = 2);
1015 void getDescriptors(const oclMat &img, Size win_stride,
1016 oclMat &descriptors,
1017 int descr_format = DESCR_FORMAT_COL_BY_COL);
1025 double threshold_L2hys;
1026 bool gamma_correction;
1030 // initialize buffers; only need to do once in case of multiscale detection
1031 void init_buffer(const oclMat &img, Size win_stride);
1032 void computeBlockHistograms(const oclMat &img);
1033 void computeGradient(const oclMat &img, oclMat &grad, oclMat &qangle);
1034 double getWinSigma() const;
1035 bool checkDetectorSize() const;
1037 static int numPartsWithin(int size, int part_size, int stride);
1038 static Size numPartsWithin(Size size, Size part_size, Size stride);
1040 // Coefficients of the separating plane
1043 // Results of the last classification step
1046 // Results of the last histogram evaluation step
1048 // Gradients conputation results
1049 oclMat grad, qangle;
1052 // effect size of input image (might be different from original size after scaling)
1057 ////////////////////////feature2d_ocl/////////////////
1058 /****************************************************************************************\
1060 \****************************************************************************************/
1061 template<typename T>
1062 struct CV_EXPORTS Accumulator
1066 template<> struct Accumulator<unsigned char>
1070 template<> struct Accumulator<unsigned short>
1074 template<> struct Accumulator<char>
1078 template<> struct Accumulator<short>
1084 * Manhattan distance (city block distance) functor
1087 struct CV_EXPORTS L1
1089 enum { normType = NORM_L1 };
1090 typedef T ValueType;
1091 typedef typename Accumulator<T>::Type ResultType;
1093 ResultType operator()( const T *a, const T *b, int size ) const
1095 return normL1<ValueType, ResultType>(a, b, size);
1100 * Euclidean distance functor
1103 struct CV_EXPORTS L2
1105 enum { normType = NORM_L2 };
1106 typedef T ValueType;
1107 typedef typename Accumulator<T>::Type ResultType;
1109 ResultType operator()( const T *a, const T *b, int size ) const
1111 return (ResultType)sqrt((double)normL2Sqr<ValueType, ResultType>(a, b, size));
1116 * Hamming distance functor - counts the bit differences between two strings - useful for the Brief descriptor
1117 * bit count of A exclusive XOR'ed with B
1119 struct CV_EXPORTS Hamming
1121 enum { normType = NORM_HAMMING };
1122 typedef unsigned char ValueType;
1123 typedef int ResultType;
1125 /** this will count the bits in a ^ b
1127 ResultType operator()( const unsigned char *a, const unsigned char *b, int size ) const
1129 return normHamming(a, b, size);
1133 ////////////////////////////////// BruteForceMatcher //////////////////////////////////
1135 class CV_EXPORTS BruteForceMatcher_OCL_base
1138 enum DistType {L1Dist = 0, L2Dist, HammingDist};
1139 explicit BruteForceMatcher_OCL_base(DistType distType = L2Dist);
1140 // Add descriptors to train descriptor collection
1141 void add(const std::vector<oclMat> &descCollection);
1142 // Get train descriptors collection
1143 const std::vector<oclMat> &getTrainDescriptors() const;
1144 // Clear train descriptors collection
1146 // Return true if there are not train descriptors in collection
1149 // Return true if the matcher supports mask in match methods
1150 bool isMaskSupported() const;
1152 // Find one best match for each query descriptor
1153 void matchSingle(const oclMat &query, const oclMat &train,
1154 oclMat &trainIdx, oclMat &distance,
1155 const oclMat &mask = oclMat());
1157 // Download trainIdx and distance and convert it to CPU vector with DMatch
1158 static void matchDownload(const oclMat &trainIdx, const oclMat &distance, std::vector<DMatch> &matches);
1159 // Convert trainIdx and distance to vector with DMatch
1160 static void matchConvert(const Mat &trainIdx, const Mat &distance, std::vector<DMatch> &matches);
1162 // Find one best match for each query descriptor
1163 void match(const oclMat &query, const oclMat &train, std::vector<DMatch> &matches, const oclMat &mask = oclMat());
1165 // Make gpu collection of trains and masks in suitable format for matchCollection function
1166 void makeGpuCollection(oclMat &trainCollection, oclMat &maskCollection, const std::vector<oclMat> &masks = std::vector<oclMat>());
1169 // Find one best match from train collection for each query descriptor
1170 void matchCollection(const oclMat &query, const oclMat &trainCollection,
1171 oclMat &trainIdx, oclMat &imgIdx, oclMat &distance,
1172 const oclMat &masks = oclMat());
1174 // Download trainIdx, imgIdx and distance and convert it to vector with DMatch
1175 static void matchDownload(const oclMat &trainIdx, const oclMat &imgIdx, const oclMat &distance, std::vector<DMatch> &matches);
1176 // Convert trainIdx, imgIdx and distance to vector with DMatch
1177 static void matchConvert(const Mat &trainIdx, const Mat &imgIdx, const Mat &distance, std::vector<DMatch> &matches);
1179 // Find one best match from train collection for each query descriptor.
1180 void match(const oclMat &query, std::vector<DMatch> &matches, const std::vector<oclMat> &masks = std::vector<oclMat>());
1182 // Find k best matches for each query descriptor (in increasing order of distances)
1183 void knnMatchSingle(const oclMat &query, const oclMat &train,
1184 oclMat &trainIdx, oclMat &distance, oclMat &allDist, int k,
1185 const oclMat &mask = oclMat());
1187 // Download trainIdx and distance and convert it to vector with DMatch
1188 // compactResult is used when mask is not empty. If compactResult is false matches
1189 // vector will have the same size as queryDescriptors rows. If compactResult is true
1190 // matches vector will not contain matches for fully masked out query descriptors.
1191 static void knnMatchDownload(const oclMat &trainIdx, const oclMat &distance,
1192 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1194 // Convert trainIdx and distance to vector with DMatch
1195 static void knnMatchConvert(const Mat &trainIdx, const Mat &distance,
1196 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1198 // Find k best matches for each query descriptor (in increasing order of distances).
1199 // compactResult is used when mask is not empty. If compactResult is false matches
1200 // vector will have the same size as queryDescriptors rows. If compactResult is true
1201 // matches vector will not contain matches for fully masked out query descriptors.
1202 void knnMatch(const oclMat &query, const oclMat &train,
1203 std::vector< std::vector<DMatch> > &matches, int k, const oclMat &mask = oclMat(),
1204 bool compactResult = false);
1206 // Find k best matches from train collection for each query descriptor (in increasing order of distances)
1207 void knnMatch2Collection(const oclMat &query, const oclMat &trainCollection,
1208 oclMat &trainIdx, oclMat &imgIdx, oclMat &distance,
1209 const oclMat &maskCollection = oclMat());
1211 // Download trainIdx and distance and convert it to vector with DMatch
1212 // compactResult is used when mask is not empty. If compactResult is false matches
1213 // vector will have the same size as queryDescriptors rows. If compactResult is true
1214 // matches vector will not contain matches for fully masked out query descriptors.
1215 static void knnMatch2Download(const oclMat &trainIdx, const oclMat &imgIdx, const oclMat &distance,
1216 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1218 // Convert trainIdx and distance to vector with DMatch
1219 static void knnMatch2Convert(const Mat &trainIdx, const Mat &imgIdx, const Mat &distance,
1220 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1222 // Find k best matches for each query descriptor (in increasing order of distances).
1223 // compactResult is used when mask is not empty. If compactResult is false matches
1224 // vector will have the same size as queryDescriptors rows. If compactResult is true
1225 // matches vector will not contain matches for fully masked out query descriptors.
1226 void knnMatch(const oclMat &query, std::vector< std::vector<DMatch> > &matches, int k,
1227 const std::vector<oclMat> &masks = std::vector<oclMat>(), bool compactResult = false);
1229 // Find best matches for each query descriptor which have distance less than maxDistance.
1230 // nMatches.at<int>(0, queryIdx) will contain matches count for queryIdx.
1231 // carefully nMatches can be greater than trainIdx.cols - it means that matcher didn't find all matches,
1232 // because it didn't have enough memory.
1233 // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nTrain / 100), 10),
1234 // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
1235 // Matches doesn't sorted.
1236 void radiusMatchSingle(const oclMat &query, const oclMat &train,
1237 oclMat &trainIdx, oclMat &distance, oclMat &nMatches, float maxDistance,
1238 const oclMat &mask = oclMat());
1240 // Download trainIdx, nMatches and distance and convert it to vector with DMatch.
1241 // matches will be sorted in increasing order of distances.
1242 // compactResult is used when mask is not empty. If compactResult is false matches
1243 // vector will have the same size as queryDescriptors rows. If compactResult is true
1244 // matches vector will not contain matches for fully masked out query descriptors.
1245 static void radiusMatchDownload(const oclMat &trainIdx, const oclMat &distance, const oclMat &nMatches,
1246 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1247 // Convert trainIdx, nMatches and distance to vector with DMatch.
1248 static void radiusMatchConvert(const Mat &trainIdx, const Mat &distance, const Mat &nMatches,
1249 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1250 // Find best matches for each query descriptor which have distance less than maxDistance
1251 // in increasing order of distances).
1252 void radiusMatch(const oclMat &query, const oclMat &train,
1253 std::vector< std::vector<DMatch> > &matches, float maxDistance,
1254 const oclMat &mask = oclMat(), bool compactResult = false);
1255 // Find best matches for each query descriptor which have distance less than maxDistance.
1256 // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nQuery / 100), 10),
1257 // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
1258 // Matches doesn't sorted.
1259 void radiusMatchCollection(const oclMat &query, oclMat &trainIdx, oclMat &imgIdx, oclMat &distance, oclMat &nMatches, float maxDistance,
1260 const std::vector<oclMat> &masks = std::vector<oclMat>());
1261 // Download trainIdx, imgIdx, nMatches and distance and convert it to vector with DMatch.
1262 // matches will be sorted in increasing order of distances.
1263 // compactResult is used when mask is not empty. If compactResult is false matches
1264 // vector will have the same size as queryDescriptors rows. If compactResult is true
1265 // matches vector will not contain matches for fully masked out query descriptors.
1266 static void radiusMatchDownload(const oclMat &trainIdx, const oclMat &imgIdx, const oclMat &distance, const oclMat &nMatches,
1267 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1268 // Convert trainIdx, nMatches and distance to vector with DMatch.
1269 static void radiusMatchConvert(const Mat &trainIdx, const Mat &imgIdx, const Mat &distance, const Mat &nMatches,
1270 std::vector< std::vector<DMatch> > &matches, bool compactResult = false);
1271 // Find best matches from train collection for each query descriptor which have distance less than
1272 // maxDistance (in increasing order of distances).
1273 void radiusMatch(const oclMat &query, std::vector< std::vector<DMatch> > &matches, float maxDistance,
1274 const std::vector<oclMat> &masks = std::vector<oclMat>(), bool compactResult = false);
1277 std::vector<oclMat> trainDescCollection;
1280 template <class Distance>
1281 class CV_EXPORTS BruteForceMatcher_OCL;
1283 template <typename T>
1284 class CV_EXPORTS BruteForceMatcher_OCL< L1<T> > : public BruteForceMatcher_OCL_base
1287 explicit BruteForceMatcher_OCL() : BruteForceMatcher_OCL_base(L1Dist) {}
1288 explicit BruteForceMatcher_OCL(L1<T> /*d*/) : BruteForceMatcher_OCL_base(L1Dist) {}
1291 template <typename T>
1292 class CV_EXPORTS BruteForceMatcher_OCL< L2<T> > : public BruteForceMatcher_OCL_base
1295 explicit BruteForceMatcher_OCL() : BruteForceMatcher_OCL_base(L2Dist) {}
1296 explicit BruteForceMatcher_OCL(L2<T> /*d*/) : BruteForceMatcher_OCL_base(L2Dist) {}
1299 template <> class CV_EXPORTS BruteForceMatcher_OCL< Hamming > : public BruteForceMatcher_OCL_base
1302 explicit BruteForceMatcher_OCL() : BruteForceMatcher_OCL_base(HammingDist) {}
1303 explicit BruteForceMatcher_OCL(Hamming /*d*/) : BruteForceMatcher_OCL_base(HammingDist) {}
1306 class CV_EXPORTS BFMatcher_OCL : public BruteForceMatcher_OCL_base
1309 explicit BFMatcher_OCL(int norm = NORM_L2) : BruteForceMatcher_OCL_base(norm == NORM_L1 ? L1Dist : norm == NORM_L2 ? L2Dist : HammingDist) {}
1312 class CV_EXPORTS GoodFeaturesToTrackDetector_OCL
1315 explicit GoodFeaturesToTrackDetector_OCL(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0,
1316 int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04);
1318 //! return 1 rows matrix with CV_32FC2 type
1319 void operator ()(const oclMat& image, oclMat& corners, const oclMat& mask = oclMat());
1320 //! download points of type Point2f to a vector. the vector's content will be erased
1321 void downloadPoints(const oclMat &points, vector<Point2f> &points_v);
1324 double qualityLevel;
1328 bool useHarrisDetector;
1330 void releaseMemory()
1335 minMaxbuf_.release();
1336 tmpCorners_.release();
1346 inline GoodFeaturesToTrackDetector_OCL::GoodFeaturesToTrackDetector_OCL(int maxCorners_, double qualityLevel_, double minDistance_,
1347 int blockSize_, bool useHarrisDetector_, double harrisK_)
1349 maxCorners = maxCorners_;
1350 qualityLevel = qualityLevel_;
1351 minDistance = minDistance_;
1352 blockSize = blockSize_;
1353 useHarrisDetector = useHarrisDetector_;
1357 /////////////////////////////// PyrLKOpticalFlow /////////////////////////////////////
1358 class CV_EXPORTS PyrLKOpticalFlow
1363 winSize = Size(21, 21);
1367 useInitialFlow = false;
1368 minEigThreshold = 1e-4f;
1369 getMinEigenVals = false;
1370 isDeviceArch11_ = false;
1373 void sparse(const oclMat &prevImg, const oclMat &nextImg, const oclMat &prevPts, oclMat &nextPts,
1374 oclMat &status, oclMat *err = 0);
1375 void dense(const oclMat &prevImg, const oclMat &nextImg, oclMat &u, oclMat &v, oclMat *err = 0);
1380 bool useInitialFlow;
1381 float minEigThreshold;
1382 bool getMinEigenVals;
1383 void releaseMemory()
1385 dx_calcBuf_.release();
1386 dy_calcBuf_.release();
1395 void calcSharrDeriv(const oclMat &src, oclMat &dx, oclMat &dy);
1396 void buildImagePyramid(const oclMat &img0, vector<oclMat> &pyr, bool withBorder);
1401 vector<oclMat> prevPyr_;
1402 vector<oclMat> nextPyr_;
1408 bool isDeviceArch11_;
1411 class CV_EXPORTS FarnebackOpticalFlow
1414 FarnebackOpticalFlow();
1425 void operator ()(const oclMat &frame0, const oclMat &frame1, oclMat &flowx, oclMat &flowy);
1427 void releaseMemory();
1430 void prepareGaussian(
1431 int n, double sigma, float *g, float *xg, float *xxg,
1432 double &ig11, double &ig03, double &ig33, double &ig55);
1434 void setPolynomialExpansionConsts(int n, double sigma);
1436 void updateFlow_boxFilter(
1437 const oclMat& R0, const oclMat& R1, oclMat& flowx, oclMat &flowy,
1438 oclMat& M, oclMat &bufM, int blockSize, bool updateMatrices);
1440 void updateFlow_gaussianBlur(
1441 const oclMat& R0, const oclMat& R1, oclMat& flowx, oclMat& flowy,
1442 oclMat& M, oclMat &bufM, int blockSize, bool updateMatrices);
1445 oclMat pyrLevel_[2], M_, bufM_, R_[2], blurredFrame_[2];
1446 std::vector<oclMat> pyramid0_, pyramid1_;
1449 //////////////// build warping maps ////////////////////
1450 //! builds plane warping maps
1451 CV_EXPORTS void buildWarpPlaneMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat &R, const Mat &T, float scale, oclMat &map_x, oclMat &map_y);
1452 //! builds cylindrical warping maps
1453 CV_EXPORTS void buildWarpCylindricalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat &R, float scale, oclMat &map_x, oclMat &map_y);
1454 //! builds spherical warping maps
1455 CV_EXPORTS void buildWarpSphericalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat &R, float scale, oclMat &map_x, oclMat &map_y);
1456 //! builds Affine warping maps
1457 CV_EXPORTS void buildWarpAffineMaps(const Mat &M, bool inverse, Size dsize, oclMat &xmap, oclMat &ymap);
1459 //! builds Perspective warping maps
1460 CV_EXPORTS void buildWarpPerspectiveMaps(const Mat &M, bool inverse, Size dsize, oclMat &xmap, oclMat &ymap);
1462 ///////////////////////////////////// interpolate frames //////////////////////////////////////////////
1463 //! Interpolate frames (images) using provided optical flow (displacement field).
1464 //! frame0 - frame 0 (32-bit floating point images, single channel)
1465 //! frame1 - frame 1 (the same type and size)
1466 //! fu - forward horizontal displacement
1467 //! fv - forward vertical displacement
1468 //! bu - backward horizontal displacement
1469 //! bv - backward vertical displacement
1470 //! pos - new frame position
1471 //! newFrame - new frame
1472 //! buf - temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 oclMat;
1473 //! occlusion masks 0, occlusion masks 1,
1474 //! interpolated forward flow 0, interpolated forward flow 1,
1475 //! interpolated backward flow 0, interpolated backward flow 1
1477 CV_EXPORTS void interpolateFrames(const oclMat &frame0, const oclMat &frame1,
1478 const oclMat &fu, const oclMat &fv,
1479 const oclMat &bu, const oclMat &bv,
1480 float pos, oclMat &newFrame, oclMat &buf);
1482 //! computes moments of the rasterized shape or a vector of points
1483 CV_EXPORTS Moments ocl_moments(InputArray _array, bool binaryImage);
1485 class CV_EXPORTS StereoBM_OCL
1488 enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 };
1490 enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 };
1492 //! the default constructor
1494 //! the full constructor taking the camera-specific preset, number of disparities and the SAD window size. ndisparities must be multiple of 8.
1495 StereoBM_OCL(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ);
1497 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair
1498 //! Output disparity has CV_8U type.
1499 void operator() ( const oclMat &left, const oclMat &right, oclMat &disparity);
1501 //! Some heuristics that tries to estmate
1502 // if current GPU will be faster then CPU in this algorithm.
1503 // It queries current active device.
1504 static bool checkIfGpuCallReasonable();
1510 // If avergeTexThreshold == 0 => post procesing is disabled
1511 // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image
1512 // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold
1513 // i.e. input left image is low textured.
1514 float avergeTexThreshold;
1516 oclMat minSSD, leBuf, riBuf;
1519 class CV_EXPORTS StereoBeliefPropagation
1522 enum { DEFAULT_NDISP = 64 };
1523 enum { DEFAULT_ITERS = 5 };
1524 enum { DEFAULT_LEVELS = 5 };
1525 static void estimateRecommendedParams(int width, int height, int &ndisp, int &iters, int &levels);
1526 explicit StereoBeliefPropagation(int ndisp = DEFAULT_NDISP,
1527 int iters = DEFAULT_ITERS,
1528 int levels = DEFAULT_LEVELS,
1529 int msg_type = CV_16S);
1530 StereoBeliefPropagation(int ndisp, int iters, int levels,
1531 float max_data_term, float data_weight,
1532 float max_disc_term, float disc_single_jump,
1533 int msg_type = CV_32F);
1534 void operator()(const oclMat &left, const oclMat &right, oclMat &disparity);
1535 void operator()(const oclMat &data, oclMat &disparity);
1539 float max_data_term;
1541 float max_disc_term;
1542 float disc_single_jump;
1545 oclMat u, d, l, r, u2, d2, l2, r2;
1546 std::vector<oclMat> datas;
1550 class CV_EXPORTS StereoConstantSpaceBP
1553 enum { DEFAULT_NDISP = 128 };
1554 enum { DEFAULT_ITERS = 8 };
1555 enum { DEFAULT_LEVELS = 4 };
1556 enum { DEFAULT_NR_PLANE = 4 };
1557 static void estimateRecommendedParams(int width, int height, int &ndisp, int &iters, int &levels, int &nr_plane);
1558 explicit StereoConstantSpaceBP(
1559 int ndisp = DEFAULT_NDISP,
1560 int iters = DEFAULT_ITERS,
1561 int levels = DEFAULT_LEVELS,
1562 int nr_plane = DEFAULT_NR_PLANE,
1563 int msg_type = CV_32F);
1564 StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,
1565 float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,
1566 int min_disp_th = 0,
1567 int msg_type = CV_32F);
1568 void operator()(const oclMat &left, const oclMat &right, oclMat &disparity);
1573 float max_data_term;
1575 float max_disc_term;
1576 float disc_single_jump;
1579 bool use_local_init_data_cost;
1581 oclMat u[2], d[2], l[2], r[2];
1582 oclMat disp_selected_pyr[2];
1584 oclMat data_cost_selected;
1589 // Implementation of the Zach, Pock and Bischof Dual TV-L1 Optical Flow method
1592 // [1] C. Zach, T. Pock and H. Bischof, "A Duality Based Approach for Realtime TV-L1 Optical Flow".
1593 // [2] Javier Sanchez, Enric Meinhardt-Llopis and Gabriele Facciolo. "TV-L1 Optical Flow Estimation".
1594 class CV_EXPORTS OpticalFlowDual_TVL1_OCL
1597 OpticalFlowDual_TVL1_OCL();
1599 void operator ()(const oclMat& I0, const oclMat& I1, oclMat& flowx, oclMat& flowy);
1601 void collectGarbage();
1604 * Time step of the numerical scheme.
1609 * Weight parameter for the data term, attachment parameter.
1610 * This is the most relevant parameter, which determines the smoothness of the output.
1611 * The smaller this parameter is, the smoother the solutions we obtain.
1612 * It depends on the range of motions of the images, so its value should be adapted to each image sequence.
1617 * Weight parameter for (u - v)^2, tightness parameter.
1618 * It serves as a link between the attachment and the regularization terms.
1619 * In theory, it should have a small value in order to maintain both parts in correspondence.
1620 * The method is stable for a large range of values of this parameter.
1625 * Number of scales used to create the pyramid of images.
1630 * Number of warpings per scale.
1631 * Represents the number of times that I1(x+u0) and grad( I1(x+u0) ) are computed per scale.
1632 * This is a parameter that assures the stability of the method.
1633 * It also affects the running time, so it is a compromise between speed and accuracy.
1638 * Stopping criterion threshold used in the numerical scheme, which is a trade-off between precision and running time.
1639 * A small value will yield more accurate solutions at the expense of a slower convergence.
1644 * Stopping criterion iterations number used in the numerical scheme.
1648 bool useInitialFlow;
1651 void procOneScale(const oclMat& I0, const oclMat& I1, oclMat& u1, oclMat& u2);
1653 std::vector<oclMat> I0s;
1654 std::vector<oclMat> I1s;
1655 std::vector<oclMat> u1s;
1656 std::vector<oclMat> u2s;
1676 // current supported sorting methods
1679 SORT_BITONIC, // only support power-of-2 buffer size
1680 SORT_SELECTION, // cannot sort duplicate keys
1682 SORT_RADIX // only support signed int/float keys(CV_32S/CV_32F)
1684 //! Returns the sorted result of all the elements in input based on equivalent keys.
1686 // The element unit in the values to be sorted is determined from the data type,
1687 // i.e., a CV_32FC2 input {a1a2, b1b2} will be considered as two elements, regardless its
1688 // matrix dimension.
1689 // both keys and values will be sorted inplace
1690 // Key needs to be single channel oclMat.
1694 // keys = {2, 3, 1} (CV_8UC1)
1695 // values = {10,5, 4,3, 6,2} (CV_8UC2)
1696 // sortByKey(keys, values, SORT_SELECTION, false);
1698 // keys = {1, 2, 3} (CV_8UC1)
1699 // values = {6,2, 10,5, 4,3} (CV_8UC2)
1700 void CV_EXPORTS sortByKey(oclMat& keys, oclMat& values, int method, bool isGreaterThan = false);
1703 #if defined _MSC_VER && _MSC_VER >= 1200
1704 # pragma warning( push)
1705 # pragma warning( disable: 4267)
1707 #include "opencv2/ocl/matrix_operations.hpp"
1708 #if defined _MSC_VER && _MSC_VER >= 1200
1709 # pragma warning( pop)
1712 #endif /* __OPENCV_GPU_HPP__ */