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