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