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