added draft version of MultiGpuMgr (it isn't tested on multi GPU machine yet)
[profile/ivi/opencv.git] / modules / gpu / include / opencv2 / gpu / gpu.hpp
1 /*M///////////////////////////////////////////////////////////////////////////////////////\r
2 //\r
3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.\r
4 //\r
5 //  By downloading, copying, installing or using the software you agree to this license.\r
6 //  If you do not agree to this license, do not download, install,\r
7 //  copy or use the software.\r
8 //\r
9 //\r
10 //                           License Agreement\r
11 //                For Open Source Computer Vision Library\r
12 //\r
13 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.\r
14 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.\r
15 // Third party copyrights are property of their respective owners.\r
16 //\r
17 // Redistribution and use in source and binary forms, with or without modification,\r
18 // are permitted provided that the following conditions are met:\r
19 //\r
20 //   * Redistribution's of source code must retain the above copyright notice,\r
21 //     this list of conditions and the following disclaimer.\r
22 //\r
23 //   * Redistribution's in binary form must reproduce the above copyright notice,\r
24 //     this list of conditions and the following disclaimer in the documentation\r
25 //     and/or other GpuMaterials provided with the distribution.\r
26 //\r
27 //   * The name of the copyright holders may not be used to endorse or promote products\r
28 //     derived from this software without specific prior written permission.\r
29 //\r
30 // This software is provided by the copyright holders and contributors "as is" and\r
31 // any express or implied warranties, including, but not limited to, the implied\r
32 // warranties of merchantability and fitness for a particular purpose are disclaimed.\r
33 // In no event shall the Intel Corporation or contributors be liable for any direct,\r
34 // indirect, incidental, special, exemplary, or consequential damages\r
35 // (including, but not limited to, procurement of substitute goods or services;\r
36 // loss of use, data, or profits; or business interruption) however caused\r
37 // and on any theory of liability, whether in contract, strict liability,\r
38 // or tort (including negligence or otherwise) arising in any way out of\r
39 // the use of this software, even if advised of the possibility of such damage.\r
40 //\r
41 //M*/\r
42 \r
43 #ifndef __OPENCV_GPU_HPP__\r
44 #define __OPENCV_GPU_HPP__\r
45 \r
46 #include <vector>\r
47 #include "opencv2/core/core.hpp"\r
48 #include "opencv2/imgproc/imgproc.hpp"\r
49 #include "opencv2/objdetect/objdetect.hpp"\r
50 #include "opencv2/gpu/devmem2d.hpp"\r
51 #include "opencv2/features2d/features2d.hpp"\r
52 \r
53 namespace cv\r
54 {\r
55     namespace gpu\r
56     {\r
57         //////////////////////////////// Initialization & Info ////////////////////////\r
58 \r
59         //! This is the only function that do not throw exceptions if the library is compiled without Cuda.\r
60         CV_EXPORTS int getCudaEnabledDeviceCount();\r
61 \r
62         //! Functions below throw cv::Expception if the library is compiled without Cuda.\r
63 \r
64         CV_EXPORTS void setDevice(int device);\r
65         CV_EXPORTS int getDevice();\r
66 \r
67         enum GpuFeature\r
68         {\r
69             COMPUTE_10 = 10,\r
70             COMPUTE_11 = 11,\r
71             COMPUTE_12 = 12,\r
72             COMPUTE_13 = 13,\r
73             COMPUTE_20 = 20,\r
74             COMPUTE_21 = 21,\r
75             ATOMICS = COMPUTE_11,\r
76             NATIVE_DOUBLE = COMPUTE_13\r
77         };\r
78 \r
79         class CV_EXPORTS TargetArchs\r
80         {\r
81         public:\r
82             static bool builtWith(GpuFeature feature);\r
83             static bool has(int major, int minor);\r
84             static bool hasPtx(int major, int minor);\r
85             static bool hasBin(int major, int minor);\r
86             static bool hasEqualOrLessPtx(int major, int minor);\r
87             static bool hasEqualOrGreater(int major, int minor);\r
88             static bool hasEqualOrGreaterPtx(int major, int minor);\r
89             static bool hasEqualOrGreaterBin(int major, int minor);\r
90         private:\r
91             TargetArchs();\r
92         };\r
93 \r
94         class CV_EXPORTS DeviceInfo\r
95         {\r
96         public:\r
97             // Creates DeviceInfo object for the current GPU\r
98             DeviceInfo() : device_id_(getDevice()) { query(); }\r
99 \r
100             // Creates DeviceInfo object for the given GPU\r
101             DeviceInfo(int device_id) : device_id_(device_id) { query(); }\r
102 \r
103             string name() const { return name_; }\r
104 \r
105             // Return compute capability versions\r
106             int majorVersion() const { return majorVersion_; }\r
107             int minorVersion() const { return minorVersion_; }\r
108 \r
109             int multiProcessorCount() const { return multi_processor_count_; }\r
110 \r
111             size_t freeMemory() const;\r
112             size_t totalMemory() const;\r
113 \r
114             // Checks whether device supports the given feature\r
115             bool supports(GpuFeature feature) const;\r
116 \r
117             // Checks whether the GPU module can be run on the given device\r
118             bool isCompatible() const;\r
119 \r
120         private:\r
121             void query();\r
122             void queryMemory(size_t& free_memory, size_t& total_memory) const;\r
123 \r
124             int device_id_;\r
125 \r
126             string name_;\r
127             int multi_processor_count_;\r
128             int majorVersion_;\r
129             int minorVersion_;\r
130         };\r
131 \r
132         /////////////////////////// Multi GPU Manager //////////////////////////////\r
133 \r
134         // Provides functionality for working with many GPUs. Object of this\r
135         // class must be created before any OpenCV GPU call and no call must\r
136         // be done after its destruction.\r
137         class CV_EXPORTS MultiGpuMgr\r
138         {\r
139         public:\r
140             MultiGpuMgr();\r
141 \r
142             // Returns the current GPU id (or BAD_GPU_ID if no GPU is active)\r
143             int currentGpuId() const;\r
144 \r
145             // Makes the given GPU active\r
146             void gpuOn(int gpu_id);\r
147 \r
148             // Finishes the piece of work with the current GPU\r
149             void gpuOff();\r
150 \r
151             static const int BAD_GPU_ID = -1;\r
152 \r
153         private:\r
154             class Impl;\r
155 \r
156             Ptr<Impl> impl_;\r
157         };\r
158 \r
159         //////////////////////////////// Error handling ////////////////////////\r
160 \r
161         CV_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func);\r
162         CV_EXPORTS void nppError( int err, const char *file, const int line, const char *func);\r
163 \r
164         //////////////////////////////// GpuMat ////////////////////////////////\r
165         class Stream;\r
166         class CudaMem;\r
167 \r
168         //! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat.\r
169         class CV_EXPORTS GpuMat\r
170         {\r
171         public:\r
172             //! default constructor\r
173             GpuMat();\r
174             //! constructs GpuMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)\r
175             GpuMat(int rows, int cols, int type);\r
176             GpuMat(Size size, int type);\r
177             //! constucts GpuMatrix and fills it with the specified value _s.\r
178             GpuMat(int rows, int cols, int type, const Scalar& s);\r
179             GpuMat(Size size, int type, const Scalar& s);\r
180             //! copy constructor\r
181             GpuMat(const GpuMat& m);\r
182 \r
183             //! constructor for GpuMatrix headers pointing to user-allocated data\r
184             GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);\r
185             GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);\r
186 \r
187             //! creates a matrix header for a part of the bigger matrix\r
188             GpuMat(const GpuMat& m, const Range& rowRange, const Range& colRange);\r
189             GpuMat(const GpuMat& m, const Rect& roi);\r
190 \r
191             //! builds GpuMat from Mat. Perfom blocking upload to device.\r
192             explicit GpuMat (const Mat& m);\r
193 \r
194             //! destructor - calls release()\r
195             ~GpuMat();\r
196 \r
197             //! assignment operators\r
198             GpuMat& operator = (const GpuMat& m);\r
199             //! assignment operator. Perfom blocking upload to device.\r
200             GpuMat& operator = (const Mat& m);\r
201 \r
202             //! returns lightweight DevMem2D_ structure for passing to nvcc-compiled code.\r
203             // Contains just image size, data ptr and step.\r
204             template <class T> operator DevMem2D_<T>() const;\r
205             template <class T> operator PtrStep_<T>() const;\r
206 \r
207             //! pefroms blocking upload data to GpuMat.\r
208             void upload(const cv::Mat& m);\r
209 \r
210             //! upload async\r
211             void upload(const CudaMem& m, Stream& stream);\r
212 \r
213             //! downloads data from device to host memory. Blocking calls.\r
214             operator Mat() const;\r
215             void download(cv::Mat& m) const;\r
216 \r
217             //! download async\r
218             void download(CudaMem& m, Stream& stream) const;\r
219 \r
220             //! returns a new GpuMatrix header for the specified row\r
221             GpuMat row(int y) const;\r
222             //! returns a new GpuMatrix header for the specified column\r
223             GpuMat col(int x) const;\r
224             //! ... for the specified row span\r
225             GpuMat rowRange(int startrow, int endrow) const;\r
226             GpuMat rowRange(const Range& r) const;\r
227             //! ... for the specified column span\r
228             GpuMat colRange(int startcol, int endcol) const;\r
229             GpuMat colRange(const Range& r) const;\r
230 \r
231             //! returns deep copy of the GpuMatrix, i.e. the data is copied\r
232             GpuMat clone() const;\r
233             //! copies the GpuMatrix content to "m".\r
234             // It calls m.create(this->size(), this->type()).\r
235             void copyTo( GpuMat& m ) const;\r
236             //! copies those GpuMatrix elements to "m" that are marked with non-zero mask elements.\r
237             void copyTo( GpuMat& m, const GpuMat& mask ) const;\r
238             //! converts GpuMatrix to another datatype with optional scalng. See cvConvertScale.\r
239             void convertTo( GpuMat& m, int rtype, double alpha=1, double beta=0 ) const;\r
240 \r
241             void assignTo( GpuMat& m, int type=-1 ) const;\r
242 \r
243             //! sets every GpuMatrix element to s\r
244             GpuMat& operator = (const Scalar& s);\r
245             //! sets some of the GpuMatrix elements to s, according to the mask\r
246             GpuMat& setTo(const Scalar& s, const GpuMat& mask = GpuMat());\r
247             //! creates alternative GpuMatrix header for the same data, with different\r
248             // number of channels and/or different number of rows. see cvReshape.\r
249             GpuMat reshape(int cn, int rows = 0) const;\r
250 \r
251             //! allocates new GpuMatrix data unless the GpuMatrix already has specified size and type.\r
252             // previous data is unreferenced if needed.\r
253             void create(int rows, int cols, int type);\r
254             void create(Size size, int type);\r
255             //! decreases reference counter;\r
256             // deallocate the data when reference counter reaches 0.\r
257             void release();\r
258 \r
259             //! swaps with other smart pointer\r
260             void swap(GpuMat& mat);\r
261 \r
262             //! locates GpuMatrix header within a parent GpuMatrix. See below\r
263             void locateROI( Size& wholeSize, Point& ofs ) const;\r
264             //! moves/resizes the current GpuMatrix ROI inside the parent GpuMatrix.\r
265             GpuMat& adjustROI( int dtop, int dbottom, int dleft, int dright );\r
266             //! extracts a rectangular sub-GpuMatrix\r
267             // (this is a generalized form of row, rowRange etc.)\r
268             GpuMat operator()( Range rowRange, Range colRange ) const;\r
269             GpuMat operator()( const Rect& roi ) const;\r
270 \r
271             //! returns true iff the GpuMatrix data is continuous\r
272             // (i.e. when there are no gaps between successive rows).\r
273             // similar to CV_IS_GpuMat_CONT(cvGpuMat->type)\r
274             bool isContinuous() const;\r
275             //! returns element size in bytes,\r
276             // similar to CV_ELEM_SIZE(cvMat->type)\r
277             size_t elemSize() const;\r
278             //! returns the size of element channel in bytes.\r
279             size_t elemSize1() const;\r
280             //! returns element type, similar to CV_MAT_TYPE(cvMat->type)\r
281             int type() const;\r
282             //! returns element type, similar to CV_MAT_DEPTH(cvMat->type)\r
283             int depth() const;\r
284             //! returns element type, similar to CV_MAT_CN(cvMat->type)\r
285             int channels() const;\r
286             //! returns step/elemSize1()\r
287             size_t step1() const;\r
288             //! returns GpuMatrix size:\r
289             // width == number of columns, height == number of rows\r
290             Size size() const;\r
291             //! returns true if GpuMatrix data is NULL\r
292             bool empty() const;\r
293 \r
294             //! returns pointer to y-th row\r
295             uchar* ptr(int y = 0);\r
296             const uchar* ptr(int y = 0) const;\r
297 \r
298             //! template version of the above method\r
299             template<typename _Tp> _Tp* ptr(int y = 0);\r
300             template<typename _Tp> const _Tp* ptr(int y = 0) const;\r
301 \r
302             //! matrix transposition\r
303             GpuMat t() const;\r
304 \r
305             /*! includes several bit-fields:\r
306             - the magic signature\r
307             - continuity flag\r
308             - depth\r
309             - number of channels\r
310             */\r
311             int flags;\r
312             //! the number of rows and columns\r
313             int rows, cols;\r
314             //! a distance between successive rows in bytes; includes the gap if any\r
315             size_t step;\r
316             //! pointer to the data\r
317             uchar* data;\r
318 \r
319             //! pointer to the reference counter;\r
320             // when GpuMatrix points to user-allocated data, the pointer is NULL\r
321             int* refcount;\r
322 \r
323             //! helper fields used in locateROI and adjustROI\r
324             uchar* datastart;\r
325             uchar* dataend;\r
326         };\r
327 \r
328 //#define TemplatedGpuMat // experimental now, deprecated to use\r
329 #ifdef TemplatedGpuMat\r
330     #include "GpuMat_BetaDeprecated.hpp"\r
331 #endif\r
332 \r
333         //! Creates continuous GPU matrix\r
334         CV_EXPORTS void createContinuous(int rows, int cols, int type, GpuMat& m);\r
335 \r
336         //! Ensures that size of the given matrix is not less than (rows, cols) size\r
337         //! and matrix type is match specified one too\r
338         CV_EXPORTS void ensureSizeIsEnough(int rows, int cols, int type, GpuMat& m);\r
339 \r
340         //////////////////////////////// CudaMem ////////////////////////////////\r
341         // CudaMem is limited cv::Mat with page locked memory allocation.\r
342         // Page locked memory is only needed for async and faster coping to GPU.\r
343         // It is convertable to cv::Mat header without reference counting\r
344         // so you can use it with other opencv functions.\r
345 \r
346         class CV_EXPORTS CudaMem\r
347         {\r
348         public:\r
349             enum  { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2, ALLOC_WRITE_COMBINED = 4 };\r
350 \r
351             CudaMem();\r
352             CudaMem(const CudaMem& m);\r
353 \r
354             CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED);\r
355             CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);\r
356 \r
357 \r
358             //! creates from cv::Mat with coping data\r
359             explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);\r
360 \r
361             ~CudaMem();\r
362 \r
363             CudaMem& operator = (const CudaMem& m);\r
364 \r
365             //! returns deep copy of the matrix, i.e. the data is copied\r
366             CudaMem clone() const;\r
367 \r
368             //! allocates new matrix data unless the matrix already has specified size and type.\r
369             void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED);\r
370             void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);\r
371 \r
372             //! decrements reference counter and released memory if needed.\r
373             void release();\r
374 \r
375             //! returns matrix header with disabled reference counting for CudaMem data.\r
376             Mat createMatHeader() const;\r
377             operator Mat() const;\r
378 \r
379             //! maps host memory into device address space and returns GpuMat header for it. Throws exception if not supported by hardware.\r
380             GpuMat createGpuMatHeader() const;\r
381             operator GpuMat() const;\r
382 \r
383             //returns if host memory can be mapperd to gpu address space;\r
384             static bool canMapHostMemory();\r
385 \r
386             // Please see cv::Mat for descriptions\r
387             bool isContinuous() const;\r
388             size_t elemSize() const;\r
389             size_t elemSize1() const;\r
390             int type() const;\r
391             int depth() const;\r
392             int channels() const;\r
393             size_t step1() const;\r
394             Size size() const;\r
395             bool empty() const;\r
396 \r
397 \r
398             // Please see cv::Mat for descriptions\r
399             int flags;\r
400             int rows, cols;\r
401             size_t step;\r
402 \r
403             uchar* data;\r
404             int* refcount;\r
405 \r
406             uchar* datastart;\r
407             uchar* dataend;\r
408 \r
409             int alloc_type;\r
410         };\r
411 \r
412         //////////////////////////////// CudaStream ////////////////////////////////\r
413         // Encapculates Cuda Stream. Provides interface for async coping.\r
414         // Passed to each function that supports async kernel execution.\r
415         // Reference counting is enabled\r
416 \r
417         class CV_EXPORTS Stream\r
418         {\r
419         public:\r
420             Stream();\r
421             ~Stream();\r
422 \r
423             Stream(const Stream&);\r
424             Stream& operator=(const Stream&);\r
425 \r
426             bool queryIfComplete();\r
427             void waitForCompletion();\r
428 \r
429             //! downloads asynchronously.\r
430             // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its subMat)\r
431             void enqueueDownload(const GpuMat& src, CudaMem& dst);\r
432             void enqueueDownload(const GpuMat& src, Mat& dst);\r
433 \r
434             //! uploads asynchronously.\r
435             // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI)\r
436             void enqueueUpload(const CudaMem& src, GpuMat& dst);\r
437             void enqueueUpload(const Mat& src, GpuMat& dst);\r
438 \r
439             void enqueueCopy(const GpuMat& src, GpuMat& dst);\r
440 \r
441             void enqueueMemSet(const GpuMat& src, Scalar val);\r
442             void enqueueMemSet(const GpuMat& src, Scalar val, const GpuMat& mask);\r
443 \r
444             // converts matrix type, ex from float to uchar depending on type\r
445             void enqueueConvert(const GpuMat& src, GpuMat& dst, int type, double a = 1, double b = 0);\r
446         private:\r
447             void create();\r
448             void release();\r
449             struct Impl;\r
450             Impl *impl;\r
451             friend struct StreamAccessor;\r
452         };\r
453 \r
454 \r
455         ////////////////////////////// Arithmetics ///////////////////////////////////\r
456 \r
457         //! transposes the matrix\r
458         //! supports matrix with element size = 1, 4 and 8 bytes (CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, etc)\r
459         CV_EXPORTS void transpose(const GpuMat& src1, GpuMat& dst);\r
460 \r
461         //! reverses the order of the rows, columns or both in a matrix\r
462         //! supports CV_8UC1, CV_8UC4 types\r
463         CV_EXPORTS void flip(const GpuMat& a, GpuMat& b, int flipCode);\r
464 \r
465         //! transforms 8-bit unsigned integers using lookup table: dst(i)=lut(src(i))\r
466         //! destination array will have the depth type as lut and the same channels number as source\r
467         //! supports CV_8UC1, CV_8UC3 types\r
468         CV_EXPORTS void LUT(const GpuMat& src, const Mat& lut, GpuMat& dst);\r
469 \r
470         //! makes multi-channel array out of several single-channel arrays\r
471         CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst);\r
472 \r
473         //! makes multi-channel array out of several single-channel arrays\r
474         CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst);\r
475 \r
476         //! makes multi-channel array out of several single-channel arrays (async version)\r
477         CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, const Stream& stream);\r
478 \r
479         //! makes multi-channel array out of several single-channel arrays (async version)\r
480         CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, const Stream& stream);\r
481 \r
482         //! copies each plane of a multi-channel array to a dedicated array\r
483         CV_EXPORTS void split(const GpuMat& src, GpuMat* dst);\r
484 \r
485         //! copies each plane of a multi-channel array to a dedicated array\r
486         CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst);\r
487 \r
488         //! copies each plane of a multi-channel array to a dedicated array (async version)\r
489         CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, const Stream& stream);\r
490 \r
491         //! copies each plane of a multi-channel array to a dedicated array (async version)\r
492         CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, const Stream& stream);\r
493 \r
494         //! computes magnitude of complex (x(i).re, x(i).im) vector\r
495         //! supports only CV_32FC2 type\r
496         CV_EXPORTS void magnitude(const GpuMat& x, GpuMat& magnitude);\r
497 \r
498         //! computes squared magnitude of complex (x(i).re, x(i).im) vector\r
499         //! supports only CV_32FC2 type\r
500         CV_EXPORTS void magnitudeSqr(const GpuMat& x, GpuMat& magnitude);\r
501 \r
502         //! computes magnitude of each (x(i), y(i)) vector\r
503         //! supports only floating-point source\r
504         CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);\r
505         //! async version\r
506         CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);\r
507 \r
508         //! computes squared magnitude of each (x(i), y(i)) vector\r
509         //! supports only floating-point source\r
510         CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);\r
511         //! async version\r
512         CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);\r
513 \r
514         //! computes angle (angle(i)) of each (x(i), y(i)) vector\r
515         //! supports only floating-point source\r
516         CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false);\r
517         //! async version\r
518         CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, const Stream& stream);\r
519 \r
520         //! converts Cartesian coordinates to polar\r
521         //! supports only floating-point source\r
522         CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false);\r
523         //! async version\r
524         CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees, const Stream& stream);\r
525 \r
526         //! converts polar coordinates to Cartesian\r
527         //! supports only floating-point source\r
528         CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false);\r
529         //! async version\r
530         CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, const Stream& stream);\r
531 \r
532 \r
533         //////////////////////////// Per-element operations ////////////////////////////////////\r
534 \r
535         //! adds one matrix to another (c = a + b)\r
536         //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types\r
537         CV_EXPORTS void add(const GpuMat& a, const GpuMat& b, GpuMat& c);\r
538         //! adds scalar to a matrix (c = a + s)\r
539         //! supports CV_32FC1 and CV_32FC2 type\r
540         CV_EXPORTS void add(const GpuMat& a, const Scalar& sc, GpuMat& c);\r
541 \r
542         //! subtracts one matrix from another (c = a - b)\r
543         //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types\r
544         CV_EXPORTS void subtract(const GpuMat& a, const GpuMat& b, GpuMat& c);\r
545         //! subtracts scalar from a matrix (c = a - s)\r
546         //! supports CV_32FC1 and CV_32FC2 type\r
547         CV_EXPORTS void subtract(const GpuMat& a, const Scalar& sc, GpuMat& c);\r
548 \r
549         //! computes element-wise product of the two arrays (c = a * b)\r
550         //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types\r
551         CV_EXPORTS void multiply(const GpuMat& a, const GpuMat& b, GpuMat& c);\r
552         //! multiplies matrix to a scalar (c = a * s)\r
553         //! supports CV_32FC1 and CV_32FC2 type\r
554         CV_EXPORTS void multiply(const GpuMat& a, const Scalar& sc, GpuMat& c);\r
555 \r
556         //! computes element-wise quotient of the two arrays (c = a / b)\r
557         //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types\r
558         CV_EXPORTS void divide(const GpuMat& a, const GpuMat& b, GpuMat& c);\r
559         //! computes element-wise quotient of matrix and scalar (c = a / s)\r
560         //! supports CV_32FC1 and CV_32FC2 type\r
561         CV_EXPORTS void divide(const GpuMat& a, const Scalar& sc, GpuMat& c);\r
562 \r
563         //! computes exponent of each matrix element (b = e**a)\r
564         //! supports only CV_32FC1 type\r
565         CV_EXPORTS void exp(const GpuMat& a, GpuMat& b);\r
566 \r
567         //! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))\r
568         //! supports only CV_32FC1 type\r
569         CV_EXPORTS void log(const GpuMat& a, GpuMat& b);\r
570 \r
571         //! computes element-wise absolute difference of two arrays (c = abs(a - b))\r
572         //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types\r
573         CV_EXPORTS void absdiff(const GpuMat& a, const GpuMat& b, GpuMat& c);\r
574         //! computes element-wise absolute difference of array and scalar (c = abs(a - s))\r
575         //! supports only CV_32FC1 type\r
576         CV_EXPORTS void absdiff(const GpuMat& a, const Scalar& s, GpuMat& c);\r
577 \r
578         //! compares elements of two arrays (c = a <cmpop> b)\r
579         //! supports CV_8UC4, CV_32FC1 types\r
580         CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop);\r
581 \r
582         //! performs per-elements bit-wise inversion\r
583         CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat());\r
584         //! async version\r
585         CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask, const Stream& stream);\r
586 \r
587         //! calculates per-element bit-wise disjunction of two arrays\r
588         CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());\r
589         //! async version\r
590         CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);\r
591 \r
592         //! calculates per-element bit-wise conjunction of two arrays\r
593         CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());\r
594         //! async version\r
595         CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);\r
596 \r
597         //! calculates per-element bit-wise "exclusive or" operation\r
598         CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());\r
599         //! async version\r
600         CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);\r
601 \r
602         //! computes per-element minimum of two arrays (dst = min(src1, src2))\r
603         CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst);\r
604         //! Async version\r
605         CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream);\r
606 \r
607         //! computes per-element minimum of array and scalar (dst = min(src1, src2))\r
608         CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst);\r
609         //! Async version\r
610         CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst, const Stream& stream);\r
611 \r
612         //! computes per-element maximum of two arrays (dst = max(src1, src2))\r
613         CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst);\r
614         //! Async version\r
615         CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream);\r
616 \r
617         //! computes per-element maximum of array and scalar (dst = max(src1, src2))\r
618         CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst);\r
619         //! Async version\r
620         CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst, const Stream& stream);\r
621 \r
622 \r
623         ////////////////////////////// Image processing //////////////////////////////\r
624 \r
625         //! DST[x,y] = SRC[xmap[x,y],ymap[x,y]] with bilinear interpolation.\r
626         //! supports CV_8UC1, CV_8UC3 source types and CV_32FC1 map type\r
627         CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap);\r
628 \r
629         //! Does mean shift filtering on GPU.\r
630         CV_EXPORTS void meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr,\r
631             TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));\r
632 \r
633         //! Does mean shift procedure on GPU.\r
634         CV_EXPORTS void meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr,\r
635             TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));\r
636 \r
637         //! Does mean shift segmentation with elimination of small regions.\r
638         CV_EXPORTS void meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize,\r
639             TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));\r
640 \r
641         //! Does coloring of disparity image: [0..ndisp) -> [0..240, 1, 1] in HSV.\r
642         //! Supported types of input disparity: CV_8U, CV_16S.\r
643         //! Output disparity has CV_8UC4 type in BGRA format (alpha = 255).\r
644         CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp);\r
645         //! async version\r
646         CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, const Stream& stream);\r
647 \r
648         //! Reprojects disparity image to 3D space.\r
649         //! Supports CV_8U and CV_16S types of input disparity.\r
650         //! The output is a 4-channel floating-point (CV_32FC4) matrix.\r
651         //! Each element of this matrix will contain the 3D coordinates of the point (x,y,z,1), computed from the disparity map.\r
652         //! Q is the 4x4 perspective transformation matrix that can be obtained with cvStereoRectify.\r
653         CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q);\r
654         //! async version\r
655         CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, const Stream& stream);\r
656 \r
657         //! converts image from one color space to another\r
658         CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0);\r
659         //! async version\r
660         CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream);\r
661 \r
662         //! applies fixed threshold to the image\r
663         CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type);\r
664         //! async version\r
665         CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type, const Stream& stream);\r
666 \r
667         //! resizes the image\r
668         //! Supports INTER_NEAREST, INTER_LINEAR\r
669         //! supports CV_8UC1, CV_8UC4 types\r
670         CV_EXPORTS void resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR);\r
671 \r
672         //! warps the image using affine transformation\r
673         //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC\r
674         CV_EXPORTS void warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR);\r
675 \r
676         //! warps the image using perspective transformation\r
677         //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC\r
678         CV_EXPORTS void warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR);\r
679 \r
680         //! rotate 8bit single or four channel image\r
681         //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC\r
682         //! supports CV_8UC1, CV_8UC4 types\r
683         CV_EXPORTS void rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0, int interpolation = INTER_LINEAR);\r
684 \r
685         //! copies 2D array to a larger destination array and pads borders with user-specifiable constant\r
686         //! supports CV_8UC1, CV_8UC4, CV_32SC1 and CV_32FC1 types\r
687         CV_EXPORTS void copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, const Scalar& value = Scalar());\r
688 \r
689         //! computes the integral image\r
690         //! sum will have CV_32S type, but will contain unsigned int values\r
691         //! supports only CV_8UC1 source type\r
692         CV_EXPORTS void integral(const GpuMat& src, GpuMat& sum);\r
693 \r
694         //! buffered version\r
695         CV_EXPORTS void integralBuffered(const GpuMat& src, GpuMat& sum, GpuMat& buffer);\r
696 \r
697         //! computes the integral image and integral for the squared image\r
698         //! sum will have CV_32S type, sqsum - CV32F type\r
699         //! supports only CV_8UC1 source type\r
700         CV_EXPORTS void integral(const GpuMat& src, GpuMat& sum, GpuMat& sqsum);\r
701 \r
702         //! computes squared integral image\r
703         //! result matrix will have 64F type, but will contain 64U values\r
704         //! supports source images of 8UC1 type only\r
705         CV_EXPORTS void sqrIntegral(const GpuMat& src, GpuMat& sqsum);\r
706 \r
707         //! computes vertical sum, supports only CV_32FC1 images\r
708         CV_EXPORTS void columnSum(const GpuMat& src, GpuMat& sum);\r
709 \r
710         //! computes the standard deviation of integral images\r
711         //! supports only CV_32SC1 source type and CV_32FC1 sqr type\r
712         //! output will have CV_32FC1 type\r
713         CV_EXPORTS void rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect);\r
714 \r
715         // applies Canny edge detector and produces the edge map\r
716         // disabled until fix crash\r
717         //CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double threshold1, double threshold2, int apertureSize = 3);\r
718         //CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, GpuMat& buffer, double threshold1, double threshold2, int apertureSize = 3);\r
719         //CV_EXPORTS void Canny(const GpuMat& srcDx, const GpuMat& srcDy, GpuMat& edges, double threshold1, double threshold2, int apertureSize = 3);\r
720         //CV_EXPORTS void Canny(const GpuMat& srcDx, const GpuMat& srcDy, GpuMat& edges, GpuMat& buffer, double threshold1, double threshold2, int apertureSize = 3);\r
721 \r
722         //! computes Harris cornerness criteria at each image pixel\r
723         CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType=BORDER_REFLECT101);\r
724 \r
725         //! computes minimum eigen value of 2x2 derivative covariation matrix at each pixel - the cornerness criteria\r
726         CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101);\r
727 \r
728         //! performs per-element multiplication of two full (not packed) Fourier spectrums\r
729         //! supports 32FC2 matrixes only (interleaved format)\r
730         CV_EXPORTS void mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB=false);\r
731 \r
732         //! performs per-element multiplication of two full (not packed) Fourier spectrums\r
733         //! supports 32FC2 matrixes only (interleaved format)\r
734         CV_EXPORTS void mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, \r
735                                              float scale, bool conjB=false);\r
736 \r
737         //! Performs a forward or inverse discrete Fourier transform (1D or 2D) of floating point matrix.\r
738         //! Param dft_size is the size of DFT transform.\r
739         //! \r
740         //! If the source matrix is not continous, then additional copy will be done,\r
741         //! so to avoid copying ensure the source matrix is continous one. If you want to use\r
742         //! preallocated output ensure it is continuous too, otherwise it will be reallocated.\r
743         //!\r
744         //! Being implemented via CUFFT real-to-complex transform result contains only non-redundant values\r
745         //! in CUFFT's format. Result as full complex matrix for such kind of transform cannot be retrieved.\r
746         //!\r
747         //! For complex-to-real transform it is assumed that the source matrix is packed in CUFFT's format.\r
748         CV_EXPORTS void dft(const GpuMat& src, GpuMat& dst, Size dft_size, int flags=0);\r
749 \r
750         //! computes convolution (or cross-correlation) of two images using discrete Fourier transform\r
751         //! supports source images of 32FC1 type only\r
752         //! result matrix will have 32FC1 type\r
753         CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, \r
754                                  bool ccorr=false);\r
755 \r
756         struct CV_EXPORTS ConvolveBuf;\r
757 \r
758         //! buffered version\r
759         CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, \r
760                                  bool ccorr, ConvolveBuf& buf);\r
761 \r
762         struct CV_EXPORTS ConvolveBuf\r
763         {\r
764             ConvolveBuf() {}\r
765             ConvolveBuf(Size image_size, Size templ_size) \r
766                 { create(image_size, templ_size); }\r
767             void create(Size image_size, Size templ_size);\r
768 \r
769         private:\r
770             static Size estimateBlockSize(Size result_size, Size templ_size);\r
771             friend void convolve(const GpuMat&, const GpuMat&, GpuMat&, bool, ConvolveBuf&);\r
772 \r
773             Size result_size;\r
774             Size block_size;\r
775             Size dft_size;\r
776             int spect_len;\r
777 \r
778             GpuMat image_spect, templ_spect, result_spect;\r
779             GpuMat image_block, templ_block, result_data;\r
780         };\r
781 \r
782         //! computes the proximity map for the raster template and the image where the template is searched for\r
783         CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method);\r
784 \r
785 \r
786         ////////////////////////////// Matrix reductions //////////////////////////////\r
787 \r
788         //! computes mean value and standard deviation of all or selected array elements\r
789         //! supports only CV_8UC1 type\r
790         CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev);\r
791 \r
792         //! computes norm of array\r
793         //! supports NORM_INF, NORM_L1, NORM_L2\r
794         //! supports all matrices except 64F\r
795         CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);\r
796 \r
797         //! computes norm of array\r
798         //! supports NORM_INF, NORM_L1, NORM_L2\r
799         //! supports all matrices except 64F\r
800         CV_EXPORTS double norm(const GpuMat& src1, int normType, GpuMat& buf);\r
801 \r
802         //! computes norm of the difference between two arrays\r
803         //! supports NORM_INF, NORM_L1, NORM_L2\r
804         //! supports only CV_8UC1 type\r
805         CV_EXPORTS double norm(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2);\r
806 \r
807         //! computes sum of array elements\r
808         //! supports only single channel images\r
809         CV_EXPORTS Scalar sum(const GpuMat& src);\r
810 \r
811         //! computes sum of array elements\r
812         //! supports only single channel images\r
813         CV_EXPORTS Scalar sum(const GpuMat& src, GpuMat& buf);\r
814 \r
815         //! computes sum of array elements absolute values\r
816         //! supports only single channel images\r
817         CV_EXPORTS Scalar absSum(const GpuMat& src);\r
818 \r
819         //! computes sum of array elements absolute values\r
820         //! supports only single channel images\r
821         CV_EXPORTS Scalar absSum(const GpuMat& src, GpuMat& buf);\r
822 \r
823         //! computes squared sum of array elements\r
824         //! supports only single channel images\r
825         CV_EXPORTS Scalar sqrSum(const GpuMat& src);\r
826 \r
827         //! computes squared sum of array elements\r
828         //! supports only single channel images\r
829         CV_EXPORTS Scalar sqrSum(const GpuMat& src, GpuMat& buf);\r
830 \r
831         //! finds global minimum and maximum array elements and returns their values\r
832         CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat());\r
833 \r
834         //! finds global minimum and maximum array elements and returns their values\r
835         CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf);\r
836 \r
837         //! finds global minimum and maximum array elements and returns their values with locations\r
838         CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0,\r
839                                   const GpuMat& mask=GpuMat());\r
840 \r
841         //! finds global minimum and maximum array elements and returns their values with locations\r
842         CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,\r
843                                   const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf);\r
844 \r
845         //! counts non-zero array elements\r
846         CV_EXPORTS int countNonZero(const GpuMat& src);\r
847 \r
848         //! counts non-zero array elements\r
849         CV_EXPORTS int countNonZero(const GpuMat& src, GpuMat& buf);\r
850 \r
851 \r
852         //////////////////////////////// Filter Engine ////////////////////////////////\r
853 \r
854         /*!\r
855         The Base Class for 1D or Row-wise Filters\r
856 \r
857         This is the base class for linear or non-linear filters that process 1D data.\r
858         In particular, such filters are used for the "horizontal" filtering parts in separable filters.\r
859         */\r
860         class CV_EXPORTS BaseRowFilter_GPU\r
861         {\r
862         public:\r
863             BaseRowFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}\r
864             virtual ~BaseRowFilter_GPU() {}\r
865             virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;\r
866             int ksize, anchor;\r
867         };\r
868 \r
869         /*!\r
870         The Base Class for Column-wise Filters\r
871 \r
872         This is the base class for linear or non-linear filters that process columns of 2D arrays.\r
873         Such filters are used for the "vertical" filtering parts in separable filters.\r
874         */\r
875         class CV_EXPORTS BaseColumnFilter_GPU\r
876         {\r
877         public:\r
878             BaseColumnFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}\r
879             virtual ~BaseColumnFilter_GPU() {}\r
880             virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;\r
881             int ksize, anchor;\r
882         };\r
883 \r
884         /*!\r
885         The Base Class for Non-Separable 2D Filters.\r
886 \r
887         This is the base class for linear or non-linear 2D filters.\r
888         */\r
889         class CV_EXPORTS BaseFilter_GPU\r
890         {\r
891         public:\r
892             BaseFilter_GPU(const Size& ksize_, const Point& anchor_) : ksize(ksize_), anchor(anchor_) {}\r
893             virtual ~BaseFilter_GPU() {}\r
894             virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;\r
895             Size ksize;\r
896             Point anchor;\r
897         };\r
898 \r
899         /*!\r
900         The Base Class for Filter Engine.\r
901 \r
902         The class can be used to apply an arbitrary filtering operation to an image.\r
903         It contains all the necessary intermediate buffers.\r
904         */\r
905         class CV_EXPORTS FilterEngine_GPU\r
906         {\r
907         public:\r
908             virtual ~FilterEngine_GPU() {}\r
909 \r
910             virtual void apply(const GpuMat& src, GpuMat& dst, Rect roi = Rect(0,0,-1,-1)) = 0;\r
911         };\r
912 \r
913         //! returns the non-separable filter engine with the specified filter\r
914         CV_EXPORTS Ptr<FilterEngine_GPU> createFilter2D_GPU(const Ptr<BaseFilter_GPU>& filter2D, int srcType, int dstType);\r
915 \r
916         //! returns the separable filter engine with the specified filters\r
917         CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>& rowFilter,\r
918             const Ptr<BaseColumnFilter_GPU>& columnFilter, int srcType, int bufType, int dstType);\r
919 \r
920         //! returns horizontal 1D box filter\r
921         //! supports only CV_8UC1 source type and CV_32FC1 sum type\r
922         CV_EXPORTS Ptr<BaseRowFilter_GPU> getRowSumFilter_GPU(int srcType, int sumType, int ksize, int anchor = -1);\r
923 \r
924         //! returns vertical 1D box filter\r
925         //! supports only CV_8UC1 sum type and CV_32FC1 dst type\r
926         CV_EXPORTS Ptr<BaseColumnFilter_GPU> getColumnSumFilter_GPU(int sumType, int dstType, int ksize, int anchor = -1);\r
927 \r
928         //! returns 2D box filter\r
929         //! supports CV_8UC1 and CV_8UC4 source type, dst type must be the same as source type\r
930         CV_EXPORTS Ptr<BaseFilter_GPU> getBoxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1, -1));\r
931 \r
932         //! returns box filter engine\r
933         CV_EXPORTS Ptr<FilterEngine_GPU> createBoxFilter_GPU(int srcType, int dstType, const Size& ksize,\r
934             const Point& anchor = Point(-1,-1));\r
935 \r
936         //! returns 2D morphological filter\r
937         //! only MORPH_ERODE and MORPH_DILATE are supported\r
938         //! supports CV_8UC1 and CV_8UC4 types\r
939         //! kernel must have CV_8UC1 type, one rows and cols == ksize.width * ksize.height\r
940         CV_EXPORTS Ptr<BaseFilter_GPU> getMorphologyFilter_GPU(int op, int type, const Mat& kernel, const Size& ksize,\r
941             Point anchor=Point(-1,-1));\r
942 \r
943         //! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported.\r
944         CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat& kernel,\r
945             const Point& anchor = Point(-1,-1), int iterations = 1);\r
946 \r
947         //! returns 2D filter with the specified kernel\r
948         //! supports CV_8UC1 and CV_8UC4 types\r
949         CV_EXPORTS Ptr<BaseFilter_GPU> getLinearFilter_GPU(int srcType, int dstType, const Mat& kernel, const Size& ksize,\r
950             Point anchor = Point(-1, -1));\r
951 \r
952         //! returns the non-separable linear filter engine\r
953         CV_EXPORTS Ptr<FilterEngine_GPU> createLinearFilter_GPU(int srcType, int dstType, const Mat& kernel,\r
954             const Point& anchor = Point(-1,-1));\r
955 \r
956         //! returns the primitive row filter with the specified kernel.\r
957         //! supports only CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 source type.\r
958         //! there are two version of algorithm: NPP and OpenCV.\r
959         //! NPP calls when srcType == CV_8UC1 or srcType == CV_8UC4 and bufType == srcType,\r
960         //! otherwise calls OpenCV version.\r
961         //! NPP supports only BORDER_CONSTANT border type.\r
962         //! OpenCV version supports only CV_32F as buffer depth and\r
963         //! BORDER_REFLECT101, BORDER_REPLICATE and BORDER_CONSTANT border types.\r
964         CV_EXPORTS Ptr<BaseRowFilter_GPU> getLinearRowFilter_GPU(int srcType, int bufType, const Mat& rowKernel,\r
965             int anchor = -1, int borderType = BORDER_CONSTANT);\r
966 \r
967         //! returns the primitive column filter with the specified kernel.\r
968         //! supports only CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 dst type.\r
969         //! there are two version of algorithm: NPP and OpenCV.\r
970         //! NPP calls when dstType == CV_8UC1 or dstType == CV_8UC4 and bufType == dstType,\r
971         //! otherwise calls OpenCV version.\r
972         //! NPP supports only BORDER_CONSTANT border type.\r
973         //! OpenCV version supports only CV_32F as buffer depth and\r
974         //! BORDER_REFLECT101, BORDER_REPLICATE and BORDER_CONSTANT border types.\r
975         CV_EXPORTS Ptr<BaseColumnFilter_GPU> getLinearColumnFilter_GPU(int bufType, int dstType, const Mat& columnKernel,\r
976             int anchor = -1, int borderType = BORDER_CONSTANT);\r
977 \r
978         //! returns the separable linear filter engine\r
979         CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel,\r
980             const Mat& columnKernel, const Point& anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT,\r
981             int columnBorderType = -1);\r
982 \r
983         //! returns filter engine for the generalized Sobel operator\r
984         CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize,\r
985             int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);\r
986 \r
987         //! returns the Gaussian filter engine\r
988         CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, double sigma1, double sigma2 = 0,\r
989             int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);\r
990 \r
991         //! returns maximum filter\r
992         CV_EXPORTS Ptr<BaseFilter_GPU> getMaxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));\r
993 \r
994         //! returns minimum filter\r
995         CV_EXPORTS Ptr<BaseFilter_GPU> getMinFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));\r
996 \r
997         //! smooths the image using the normalized box filter\r
998         //! supports CV_8UC1, CV_8UC4 types\r
999         CV_EXPORTS void boxFilter(const GpuMat& src, GpuMat& dst, int ddepth, Size ksize, Point anchor = Point(-1,-1));\r
1000 \r
1001         //! a synonym for normalized box filter\r
1002         static inline void blur(const GpuMat& src, GpuMat& dst, Size ksize, Point anchor = Point(-1,-1)) { boxFilter(src, dst, -1, ksize, anchor); }\r
1003 \r
1004         //! erodes the image (applies the local minimum operator)\r
1005         CV_EXPORTS void erode( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);\r
1006 \r
1007         //! dilates the image (applies the local maximum operator)\r
1008         CV_EXPORTS void dilate( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);\r
1009 \r
1010         //! applies an advanced morphological operation to the image\r
1011         CV_EXPORTS void morphologyEx( const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);\r
1012 \r
1013         //! applies non-separable 2D linear filter to the image\r
1014         CV_EXPORTS void filter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernel, Point anchor=Point(-1,-1));\r
1015 \r
1016         //! applies separable 2D linear filter to the image\r
1017         CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY,\r
1018             Point anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);\r
1019 \r
1020         //! applies generalized Sobel operator to the image\r
1021         CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1,\r
1022             int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);\r
1023 \r
1024         //! applies the vertical or horizontal Scharr operator to the image\r
1025         CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, double scale = 1,\r
1026             int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);\r
1027 \r
1028         //! smooths the image using Gaussian filter.\r
1029         CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, double sigma1, double sigma2 = 0,\r
1030             int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);\r
1031 \r
1032         //! applies Laplacian operator to the image\r
1033         //! supports only ksize = 1 and ksize = 3\r
1034         CV_EXPORTS void Laplacian(const GpuMat& src, GpuMat& dst, int ddepth, int ksize = 1, double scale = 1);\r
1035 \r
1036         //////////////////////////////// Image Labeling ////////////////////////////////\r
1037 \r
1038         //!performs labeling via graph cuts\r
1039         CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels, GpuMat& buf);\r
1040 \r
1041         ////////////////////////////////// Histograms //////////////////////////////////\r
1042 \r
1043         //! Compute levels with even distribution. levels will have 1 row and nLevels cols and CV_32SC1 type.\r
1044         CV_EXPORTS void evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel);\r
1045         //! Calculates histogram with evenly distributed bins for signle channel source.\r
1046         //! Supports CV_8UC1, CV_16UC1 and CV_16SC1 source types.\r
1047         //! Output hist will have one row and histSize cols and CV_32SC1 type.\r
1048         CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel);\r
1049         //! Calculates histogram with evenly distributed bins for four-channel source.\r
1050         //! All channels of source are processed separately.\r
1051         //! Supports CV_8UC4, CV_16UC4 and CV_16SC4 source types.\r
1052         //! Output hist[i] will have one row and histSize[i] cols and CV_32SC1 type.\r
1053         CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4]);\r
1054         //! Calculates histogram with bins determined by levels array.\r
1055         //! levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.\r
1056         //! Supports CV_8UC1, CV_16UC1, CV_16SC1 and CV_32FC1 source types.\r
1057         //! Output hist will have one row and (levels.cols-1) cols and CV_32SC1 type.\r
1058         CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels);\r
1059         //! Calculates histogram with bins determined by levels array.\r
1060         //! All levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.\r
1061         //! All channels of source are processed separately.\r
1062         //! Supports CV_8UC4, CV_16UC4, CV_16SC4 and CV_32FC4 source types.\r
1063         //! Output hist[i] will have one row and (levels[i].cols-1) cols and CV_32SC1 type.\r
1064         CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4]);\r
1065 \r
1066         //////////////////////////////// StereoBM_GPU ////////////////////////////////\r
1067 \r
1068         class CV_EXPORTS StereoBM_GPU\r
1069         {\r
1070         public:\r
1071             enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 };\r
1072 \r
1073             enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 };\r
1074 \r
1075             //! the default constructor\r
1076             StereoBM_GPU();\r
1077             //! the full constructor taking the camera-specific preset, number of disparities and the SAD window size. ndisparities must be multiple of 8.\r
1078             StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ);\r
1079 \r
1080             //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair\r
1081             //! Output disparity has CV_8U type.\r
1082             void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity);\r
1083 \r
1084             //! async version\r
1085             void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream & stream);\r
1086 \r
1087             //! Some heuristics that tries to estmate\r
1088             // if current GPU will be faster then CPU in this algorithm.\r
1089             // It queries current active device.\r
1090             static bool checkIfGpuCallReasonable();\r
1091 \r
1092             int preset;\r
1093             int ndisp;\r
1094             int winSize;\r
1095 \r
1096             // If avergeTexThreshold  == 0 => post procesing is disabled\r
1097             // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image\r
1098             // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold\r
1099             // i.e. input left image is low textured.\r
1100             float avergeTexThreshold;\r
1101         private:\r
1102             GpuMat minSSD, leBuf, riBuf;\r
1103         };\r
1104 \r
1105         ////////////////////////// StereoBeliefPropagation ///////////////////////////\r
1106         // "Efficient Belief Propagation for Early Vision"\r
1107         // P.Felzenszwalb\r
1108 \r
1109         class CV_EXPORTS StereoBeliefPropagation\r
1110         {\r
1111         public:\r
1112             enum { DEFAULT_NDISP  = 64 };\r
1113             enum { DEFAULT_ITERS  = 5  };\r
1114             enum { DEFAULT_LEVELS = 5  };\r
1115 \r
1116             static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels);\r
1117 \r
1118             //! the default constructor\r
1119             explicit StereoBeliefPropagation(int ndisp  = DEFAULT_NDISP,\r
1120                 int iters  = DEFAULT_ITERS,\r
1121                 int levels = DEFAULT_LEVELS,\r
1122                 int msg_type = CV_32F);\r
1123 \r
1124             //! the full constructor taking the number of disparities, number of BP iterations on each level,\r
1125             //! number of levels, truncation of data cost, data weight,\r
1126             //! truncation of discontinuity cost and discontinuity single jump\r
1127             //! DataTerm = data_weight * min(fabs(I2-I1), max_data_term)\r
1128             //! DiscTerm = min(disc_single_jump * fabs(f1-f2), max_disc_term)\r
1129             //! please see paper for more details\r
1130             StereoBeliefPropagation(int ndisp, int iters, int levels,\r
1131                 float max_data_term, float data_weight,\r
1132                 float max_disc_term, float disc_single_jump,\r
1133                 int msg_type = CV_32F);\r
1134 \r
1135             //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,\r
1136             //! if disparity is empty output type will be CV_16S else output type will be disparity.type().\r
1137             void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);\r
1138 \r
1139             //! async version\r
1140             void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);\r
1141 \r
1142 \r
1143             //! version for user specified data term\r
1144             void operator()(const GpuMat& data, GpuMat& disparity);\r
1145             void operator()(const GpuMat& data, GpuMat& disparity, Stream& stream);\r
1146 \r
1147             int ndisp;\r
1148 \r
1149             int iters;\r
1150             int levels;\r
1151 \r
1152             float max_data_term;\r
1153             float data_weight;\r
1154             float max_disc_term;\r
1155             float disc_single_jump;\r
1156 \r
1157             int msg_type;\r
1158         private:\r
1159             GpuMat u, d, l, r, u2, d2, l2, r2;\r
1160             std::vector<GpuMat> datas;\r
1161             GpuMat out;\r
1162         };\r
1163 \r
1164         /////////////////////////// StereoConstantSpaceBP ///////////////////////////\r
1165         // "A Constant-Space Belief Propagation Algorithm for Stereo Matching"\r
1166         // Qingxiong Yang, Liang Wang�, Narendra Ahuja\r
1167         // http://vision.ai.uiuc.edu/~qyang6/\r
1168 \r
1169         class CV_EXPORTS StereoConstantSpaceBP\r
1170         {\r
1171         public:\r
1172             enum { DEFAULT_NDISP    = 128 };\r
1173             enum { DEFAULT_ITERS    = 8   };\r
1174             enum { DEFAULT_LEVELS   = 4   };\r
1175             enum { DEFAULT_NR_PLANE = 4   };\r
1176 \r
1177             static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane);\r
1178 \r
1179             //! the default constructor\r
1180             explicit StereoConstantSpaceBP(int ndisp    = DEFAULT_NDISP,\r
1181                 int iters    = DEFAULT_ITERS,\r
1182                 int levels   = DEFAULT_LEVELS,\r
1183                 int nr_plane = DEFAULT_NR_PLANE,\r
1184                 int msg_type = CV_32F);\r
1185 \r
1186             //! the full constructor taking the number of disparities, number of BP iterations on each level,\r
1187             //! number of levels, number of active disparity on the first level, truncation of data cost, data weight,\r
1188             //! truncation of discontinuity cost, discontinuity single jump and minimum disparity threshold\r
1189             StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,\r
1190                 float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,\r
1191                 int min_disp_th = 0,\r
1192                 int msg_type = CV_32F);\r
1193 \r
1194             //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,\r
1195             //! if disparity is empty output type will be CV_16S else output type will be disparity.type().\r
1196             void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);\r
1197 \r
1198             //! async version\r
1199             void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);\r
1200 \r
1201             int ndisp;\r
1202 \r
1203             int iters;\r
1204             int levels;\r
1205 \r
1206             int nr_plane;\r
1207 \r
1208             float max_data_term;\r
1209             float data_weight;\r
1210             float max_disc_term;\r
1211             float disc_single_jump;\r
1212 \r
1213             int min_disp_th;\r
1214 \r
1215             int msg_type;\r
1216 \r
1217             bool use_local_init_data_cost;\r
1218         private:\r
1219             GpuMat u[2], d[2], l[2], r[2];\r
1220             GpuMat disp_selected_pyr[2];\r
1221 \r
1222             GpuMat data_cost;\r
1223             GpuMat data_cost_selected;\r
1224 \r
1225             GpuMat temp;\r
1226 \r
1227             GpuMat out;\r
1228         };\r
1229 \r
1230         /////////////////////////// DisparityBilateralFilter ///////////////////////////\r
1231         // Disparity map refinement using joint bilateral filtering given a single color image.\r
1232         // Qingxiong Yang, Liang Wang�, Narendra Ahuja\r
1233         // http://vision.ai.uiuc.edu/~qyang6/\r
1234 \r
1235         class CV_EXPORTS DisparityBilateralFilter\r
1236         {\r
1237         public:\r
1238             enum { DEFAULT_NDISP  = 64 };\r
1239             enum { DEFAULT_RADIUS = 3 };\r
1240             enum { DEFAULT_ITERS  = 1 };\r
1241 \r
1242             //! the default constructor\r
1243             explicit DisparityBilateralFilter(int ndisp = DEFAULT_NDISP, int radius = DEFAULT_RADIUS, int iters = DEFAULT_ITERS);\r
1244 \r
1245             //! the full constructor taking the number of disparities, filter radius,\r
1246             //! number of iterations, truncation of data continuity, truncation of disparity continuity\r
1247             //! and filter range sigma\r
1248             DisparityBilateralFilter(int ndisp, int radius, int iters, float edge_threshold, float max_disc_threshold, float sigma_range);\r
1249 \r
1250             //! the disparity map refinement operator. Refine disparity map using joint bilateral filtering given a single color image.\r
1251             //! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type.\r
1252             void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst);\r
1253 \r
1254             //! async version\r
1255             void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream);\r
1256 \r
1257         private:\r
1258             int ndisp;\r
1259             int radius;\r
1260             int iters;\r
1261 \r
1262             float edge_threshold;\r
1263             float max_disc_threshold;\r
1264             float sigma_range;\r
1265 \r
1266             GpuMat table_color;\r
1267             GpuMat table_space;\r
1268         };\r
1269 \r
1270 \r
1271         //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////\r
1272 \r
1273         struct CV_EXPORTS HOGDescriptor\r
1274         {\r
1275             enum { DEFAULT_WIN_SIGMA = -1 };\r
1276             enum { DEFAULT_NLEVELS = 64 };\r
1277             enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };\r
1278 \r
1279             HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16),\r
1280                           Size block_stride=Size(8, 8), Size cell_size=Size(8, 8),\r
1281                           int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA,\r
1282                           double threshold_L2hys=0.2, bool gamma_correction=true,\r
1283                           int nlevels=DEFAULT_NLEVELS);\r
1284 \r
1285             size_t getDescriptorSize() const;\r
1286             size_t getBlockHistogramSize() const;\r
1287 \r
1288             void setSVMDetector(const vector<float>& detector);\r
1289 \r
1290             static vector<float> getDefaultPeopleDetector();\r
1291             static vector<float> getPeopleDetector48x96();\r
1292             static vector<float> getPeopleDetector64x128();\r
1293 \r
1294             void detect(const GpuMat& img, vector<Point>& found_locations, \r
1295                         double hit_threshold=0, Size win_stride=Size(), \r
1296                         Size padding=Size());\r
1297 \r
1298             void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,\r
1299                                   double hit_threshold=0, Size win_stride=Size(), \r
1300                                   Size padding=Size(), double scale0=1.05, \r
1301                                   int group_threshold=2);\r
1302 \r
1303             void getDescriptors(const GpuMat& img, Size win_stride, \r
1304                                 GpuMat& descriptors,\r
1305                                 int descr_format=DESCR_FORMAT_COL_BY_COL);\r
1306 \r
1307             Size win_size;\r
1308             Size block_size;\r
1309             Size block_stride;\r
1310             Size cell_size;\r
1311             int nbins;\r
1312             double win_sigma;\r
1313             double threshold_L2hys;\r
1314             bool gamma_correction;\r
1315             int nlevels;\r
1316 \r
1317         protected:\r
1318             void computeBlockHistograms(const GpuMat& img);\r
1319             void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle);\r
1320 \r
1321             double getWinSigma() const;\r
1322             bool checkDetectorSize() const;\r
1323 \r
1324             static int numPartsWithin(int size, int part_size, int stride);\r
1325             static Size numPartsWithin(Size size, Size part_size, Size stride);\r
1326 \r
1327             // Coefficients of the separating plane\r
1328             float free_coef;\r
1329             GpuMat detector;\r
1330 \r
1331             // Results of the last classification step\r
1332             GpuMat labels;\r
1333             Mat labels_host;\r
1334 \r
1335             // Results of the last histogram evaluation step\r
1336             GpuMat block_hists;\r
1337 \r
1338             // Gradients conputation results\r
1339             GpuMat grad, qangle;\r
1340         };\r
1341 \r
1342 \r
1343         ////////////////////////////////// BruteForceMatcher //////////////////////////////////\r
1344 \r
1345         class CV_EXPORTS BruteForceMatcher_GPU_base\r
1346         {\r
1347         public:\r
1348             enum DistType {L1Dist = 0, L2Dist};\r
1349 \r
1350             explicit BruteForceMatcher_GPU_base(DistType distType = L2Dist);\r
1351 \r
1352             // Add descriptors to train descriptor collection.\r
1353             void add(const std::vector<GpuMat>& descCollection);\r
1354 \r
1355             // Get train descriptors collection.\r
1356             const std::vector<GpuMat>& getTrainDescriptors() const;\r
1357 \r
1358             // Clear train descriptors collection.\r
1359             void clear();\r
1360 \r
1361             // Return true if there are not train descriptors in collection.\r
1362             bool empty() const;\r
1363 \r
1364             // Return true if the matcher supports mask in match methods.\r
1365             bool isMaskSupported() const;\r
1366 \r
1367             // Find one best match for each query descriptor.\r
1368             // trainIdx.at<int>(0, queryIdx) will contain best train index for queryIdx\r
1369             // distance.at<float>(0, queryIdx) will contain distance\r
1370             void matchSingle(const GpuMat& queryDescs, const GpuMat& trainDescs,\r
1371                 GpuMat& trainIdx, GpuMat& distance,\r
1372                 const GpuMat& mask = GpuMat());\r
1373 \r
1374             // Download trainIdx and distance to CPU vector with DMatch\r
1375             static void matchDownload(const GpuMat& trainIdx, const GpuMat& distance, std::vector<DMatch>& matches);\r
1376 \r
1377             // Find one best match for each query descriptor.\r
1378             void match(const GpuMat& queryDescs, const GpuMat& trainDescs, std::vector<DMatch>& matches,\r
1379                 const GpuMat& mask = GpuMat());\r
1380 \r
1381             // Make gpu collection of trains and masks in suitable format for matchCollection function\r
1382             void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection,\r
1383                 const vector<GpuMat>& masks = std::vector<GpuMat>());\r
1384 \r
1385             // Find one best match from train collection for each query descriptor.\r
1386             // trainIdx.at<int>(0, queryIdx) will contain best train index for queryIdx\r
1387             // imgIdx.at<int>(0, queryIdx) will contain best image index for queryIdx\r
1388             // distance.at<float>(0, queryIdx) will contain distance\r
1389             void matchCollection(const GpuMat& queryDescs, const GpuMat& trainCollection,\r
1390                 GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,\r
1391                 const GpuMat& maskCollection);\r
1392 \r
1393             // Download trainIdx, imgIdx and distance to CPU vector with DMatch\r
1394             static void matchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance,\r
1395                 std::vector<DMatch>& matches);\r
1396 \r
1397             // Find one best match from train collection for each query descriptor.\r
1398             void match(const GpuMat& queryDescs, std::vector<DMatch>& matches,\r
1399                 const std::vector<GpuMat>& masks = std::vector<GpuMat>());\r
1400 \r
1401             // Find k best matches for each query descriptor (in increasing order of distances).\r
1402             // trainIdx.at<int>(queryIdx, i) will contain index of i'th best trains (i < k).\r
1403             // distance.at<float>(queryIdx, i) will contain distance.\r
1404             // allDist is a buffer to store all distance between query descriptors and train descriptors\r
1405             // it have size (nQuery,nTrain) and CV_32F type\r
1406             // allDist.at<float>(queryIdx, trainIdx) will contain FLT_MAX, if trainIdx is one from k best,\r
1407             // otherwise it will contain distance between queryIdx and trainIdx descriptors\r
1408             void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,\r
1409                 GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k, const GpuMat& mask = GpuMat());\r
1410 \r
1411             // Download trainIdx and distance to CPU vector with DMatch\r
1412             // compactResult is used when mask is not empty. If compactResult is false matches\r
1413             // vector will have the same size as queryDescriptors rows. If compactResult is true\r
1414             // matches vector will not contain matches for fully masked out query descriptors.\r
1415             static void knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance,\r
1416                 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);\r
1417 \r
1418             // Find k best matches for each query descriptor (in increasing order of distances).\r
1419             // compactResult is used when mask is not empty. If compactResult is false matches\r
1420             // vector will have the same size as queryDescriptors rows. If compactResult is true\r
1421             // matches vector will not contain matches for fully masked out query descriptors.\r
1422             void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,\r
1423                 std::vector< std::vector<DMatch> >& matches, int k, const GpuMat& mask = GpuMat(),\r
1424                 bool compactResult = false);\r
1425 \r
1426             // Find k best matches  for each query descriptor (in increasing order of distances).\r
1427             // compactResult is used when mask is not empty. If compactResult is false matches\r
1428             // vector will have the same size as queryDescriptors rows. If compactResult is true\r
1429             // matches vector will not contain matches for fully masked out query descriptors.\r
1430             void knnMatch(const GpuMat& queryDescs, std::vector< std::vector<DMatch> >& matches, int knn,\r
1431                 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false );\r
1432 \r
1433             // Find best matches for each query descriptor which have distance less than maxDistance.\r
1434             // nMatches.at<unsigned int>(0, queruIdx) will contain matches count for queryIdx.\r
1435             // carefully nMatches can be greater than trainIdx.cols - it means that matcher didn't find all matches,\r
1436             // because it didn't have enough memory.\r
1437             // trainIdx.at<int>(queruIdx, i) will contain ith train index (i < min(nMatches.at<unsigned int>(0, queruIdx), trainIdx.cols))\r
1438             // distance.at<int>(queruIdx, i) will contain ith distance (i < min(nMatches.at<unsigned int>(0, queruIdx), trainIdx.cols))\r
1439             // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x nTrain,\r
1440             // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches\r
1441             // Matches doesn't sorted.\r
1442             void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,\r
1443                 GpuMat& trainIdx, GpuMat& nMatches, GpuMat& distance, float maxDistance,\r
1444                 const GpuMat& mask = GpuMat());\r
1445 \r
1446             // Download trainIdx, nMatches and distance to CPU vector with DMatch.\r
1447             // matches will be sorted in increasing order of distances.\r
1448             // compactResult is used when mask is not empty. If compactResult is false matches\r
1449             // vector will have the same size as queryDescriptors rows. If compactResult is true\r
1450             // matches vector will not contain matches for fully masked out query descriptors.\r
1451             static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& nMatches, const GpuMat& distance,\r
1452                 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);\r
1453 \r
1454             // Find best matches for each query descriptor which have distance less than maxDistance\r
1455             // in increasing order of distances).\r
1456             void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,\r
1457                 std::vector< std::vector<DMatch> >& matches, float maxDistance,\r
1458                 const GpuMat& mask = GpuMat(), bool compactResult = false);\r
1459 \r
1460             // Find best matches from train collection for each query descriptor which have distance less than\r
1461             // maxDistance (in increasing order of distances).\r
1462             void radiusMatch(const GpuMat& queryDescs, std::vector< std::vector<DMatch> >& matches, float maxDistance,\r
1463                 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);\r
1464 \r
1465         private:\r
1466             DistType distType;\r
1467 \r
1468             std::vector<GpuMat> trainDescCollection;\r
1469         };\r
1470 \r
1471         template <class Distance>\r
1472         class CV_EXPORTS BruteForceMatcher_GPU;\r
1473 \r
1474         template <typename T>\r
1475         class CV_EXPORTS BruteForceMatcher_GPU< L1<T> > : public BruteForceMatcher_GPU_base\r
1476         {\r
1477         public:\r
1478             explicit BruteForceMatcher_GPU() : BruteForceMatcher_GPU_base(L1Dist) {}\r
1479             explicit BruteForceMatcher_GPU(L1<T> /*d*/) : BruteForceMatcher_GPU_base(L1Dist) {}\r
1480         };\r
1481         template <typename T>\r
1482         class CV_EXPORTS BruteForceMatcher_GPU< L2<T> > : public BruteForceMatcher_GPU_base\r
1483         {\r
1484         public:\r
1485             explicit BruteForceMatcher_GPU() : BruteForceMatcher_GPU_base(L2Dist) {}\r
1486             explicit BruteForceMatcher_GPU(L2<T> /*d*/) : BruteForceMatcher_GPU_base(L2Dist) {}\r
1487         };\r
1488 \r
1489         ////////////////////////////////// CascadeClassifier_GPU //////////////////////////////////////////\r
1490         // The cascade classifier class for object detection.\r
1491         class CV_EXPORTS CascadeClassifier_GPU\r
1492         {\r
1493         public:            \r
1494             CascadeClassifier_GPU();\r
1495             CascadeClassifier_GPU(const string& filename);\r
1496             ~CascadeClassifier_GPU();\r
1497 \r
1498             bool empty() const;\r
1499             bool load(const string& filename);\r
1500             void release();\r
1501             \r
1502             /* returns number of detected objects */\r
1503             int detectMultiScale( const GpuMat& image, GpuMat& objectsBuf, double scaleFactor=1.2, int minNeighbors=4, Size minSize=Size());\r
1504                                     \r
1505             bool findLargestObject;\r
1506             bool visualizeInPlace;\r
1507 \r
1508             Size getClassifierSize() const;\r
1509         private:\r
1510             \r
1511             struct CascadeClassifierImpl;                        \r
1512             CascadeClassifierImpl* impl;            \r
1513         };\r
1514         \r
1515         ////////////////////////////////// SURF //////////////////////////////////////////\r
1516         \r
1517         struct CV_EXPORTS SURFParams_GPU \r
1518         {\r
1519             SURFParams_GPU() : threshold(0.1f), nOctaves(4), nIntervals(4), initialScale(2.f), \r
1520                 l1(3.f/1.5f), l2(5.f/1.5f), l3(3.f/1.5f), l4(1.f/1.5f),\r
1521                 edgeScale(0.81f), initialStep(1), extended(true), featuresRatio(0.01f) {}\r
1522 \r
1523             //! The interest operator threshold\r
1524             float threshold;\r
1525             //! The number of octaves to process\r
1526             int nOctaves;\r
1527             //! The number of intervals in each octave\r
1528             int nIntervals;\r
1529             //! The scale associated with the first interval of the first octave\r
1530             float initialScale;\r
1531 \r
1532             //! mask parameter l_1\r
1533             float l1;\r
1534             //! mask parameter l_2 \r
1535             float l2;\r
1536             //! mask parameter l_3\r
1537             float l3;\r
1538             //! mask parameter l_4\r
1539             float l4;\r
1540             //! The amount to scale the edge rejection mask\r
1541             float edgeScale;\r
1542             //! The initial sampling step in pixels.\r
1543             int initialStep;\r
1544 \r
1545             //! True, if generate 128-len descriptors, false - 64-len descriptors\r
1546             bool extended;\r
1547 \r
1548             //! max features = featuresRatio * img.size().srea()\r
1549             float featuresRatio;\r
1550         };\r
1551 \r
1552         class CV_EXPORTS SURF_GPU : public SURFParams_GPU\r
1553         {\r
1554         public:\r
1555             //! returns the descriptor size in float's (64 or 128)\r
1556             int descriptorSize() const;\r
1557 \r
1558             //! upload host keypoints to device memory\r
1559             static void uploadKeypoints(const vector<KeyPoint>& keypoints, GpuMat& keypointsGPU);\r
1560             //! download keypoints from device to host memory\r
1561             static void downloadKeypoints(const GpuMat& keypointsGPU, vector<KeyPoint>& keypoints);\r
1562 \r
1563             //! download descriptors from device to host memory\r
1564             static void downloadDescriptors(const GpuMat& descriptorsGPU, vector<float>& descriptors);\r
1565             \r
1566             //! finds the keypoints using fast hessian detector used in SURF\r
1567             //! supports CV_8UC1 images\r
1568             //! keypoints will have 1 row and type CV_32FC(6)\r
1569             //! keypoints.at<float[6]>(1, i) contains i'th keypoint\r
1570             //! format: (x, y, size, response, angle, octave)\r
1571             void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints);\r
1572             //! finds the keypoints and computes their descriptors. \r
1573             //! Optionally it can compute descriptors for the user-provided keypoints and recompute keypoints direction\r
1574             void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors, \r
1575                 bool useProvidedKeypoints = false, bool calcOrientation = true);\r
1576         \r
1577             void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints);\r
1578             void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors, \r
1579                 bool useProvidedKeypoints = false, bool calcOrientation = true);\r
1580             \r
1581             void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, std::vector<float>& descriptors, \r
1582                 bool useProvidedKeypoints = false, bool calcOrientation = true);\r
1583 \r
1584             GpuMat sum;\r
1585             GpuMat sumf;\r
1586 \r
1587             GpuMat mask1;\r
1588             GpuMat maskSum;\r
1589 \r
1590             GpuMat hessianBuffer;\r
1591             GpuMat maxPosBuffer;\r
1592             GpuMat featuresBuffer;\r
1593         };\r
1594 \r
1595     }\r
1596 \r
1597     //! Speckle filtering - filters small connected components on diparity image.\r
1598     //! It sets pixel (x,y) to newVal if it coresponds to small CC with size < maxSpeckleSize.\r
1599     //! Threshold for border between CC is diffThreshold;\r
1600     CV_EXPORTS void filterSpeckles( Mat& img, uchar newVal, int maxSpeckleSize, uchar diffThreshold, Mat& buf);\r
1601 \r
1602 }\r
1603 #include "opencv2/gpu/matrix_operations.hpp"\r
1604 \r
1605 #endif /* __OPENCV_GPU_HPP__ */\r