1 /*M///////////////////////////////////////////////////////////////////////////////////////
\r
3 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
\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
10 // License Agreement
\r
11 // For Open Source Computer Vision Library
\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
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
20 // * Redistribution's of source code must retain the above copyright notice,
\r
21 // this list of conditions and the following disclaimer.
\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
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
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
43 #ifndef __OPENCV_GPU_HPP__
\r
44 #define __OPENCV_GPU_HPP__
\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
57 //////////////////////////////// Initialization & Info ////////////////////////
\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
62 //! Functions below throw cv::Expception if the library is compiled without Cuda.
\r
63 CV_EXPORTS string getDeviceName(int device);
\r
64 CV_EXPORTS void setDevice(int device);
\r
65 CV_EXPORTS int getDevice();
\r
67 CV_EXPORTS void getComputeCapability(int device, int& major, int& minor);
\r
68 CV_EXPORTS int getNumberOfSMs(int device);
\r
70 CV_EXPORTS void getGpuMemInfo(size_t& free, size_t& total);
\r
72 CV_EXPORTS bool hasNativeDoubleSupport(int device);
\r
73 CV_EXPORTS bool hasAtomicsSupport(int device);
\r
75 //////////////////////////////// Error handling ////////////////////////
\r
77 CV_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func);
\r
78 CV_EXPORTS void nppError( int err, const char *file, const int line, const char *func);
\r
80 //////////////////////////////// GpuMat ////////////////////////////////
\r
84 //! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat.
\r
85 class CV_EXPORTS GpuMat
\r
88 //! default constructor
\r
90 //! constructs GpuMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
\r
91 GpuMat(int rows, int cols, int type);
\r
92 GpuMat(Size size, int type);
\r
93 //! constucts GpuMatrix and fills it with the specified value _s.
\r
94 GpuMat(int rows, int cols, int type, const Scalar& s);
\r
95 GpuMat(Size size, int type, const Scalar& s);
\r
96 //! copy constructor
\r
97 GpuMat(const GpuMat& m);
\r
99 //! constructor for GpuMatrix headers pointing to user-allocated data
\r
100 GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);
\r
101 GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);
\r
103 //! creates a matrix header for a part of the bigger matrix
\r
104 GpuMat(const GpuMat& m, const Range& rowRange, const Range& colRange);
\r
105 GpuMat(const GpuMat& m, const Rect& roi);
\r
107 //! builds GpuMat from Mat. Perfom blocking upload to device.
\r
108 explicit GpuMat (const Mat& m);
\r
110 //! destructor - calls release()
\r
113 //! assignment operators
\r
114 GpuMat& operator = (const GpuMat& m);
\r
115 //! assignment operator. Perfom blocking upload to device.
\r
116 GpuMat& operator = (const Mat& m);
\r
118 //! returns lightweight DevMem2D_ structure for passing to nvcc-compiled code.
\r
119 // Contains just image size, data ptr and step.
\r
120 template <class T> operator DevMem2D_<T>() const;
\r
121 template <class T> operator PtrStep_<T>() const;
\r
123 //! pefroms blocking upload data to GpuMat.
\r
124 void upload(const cv::Mat& m);
\r
127 void upload(const CudaMem& m, Stream& stream);
\r
129 //! downloads data from device to host memory. Blocking calls.
\r
130 operator Mat() const;
\r
131 void download(cv::Mat& m) const;
\r
134 void download(CudaMem& m, Stream& stream) const;
\r
136 //! returns a new GpuMatrix header for the specified row
\r
137 GpuMat row(int y) const;
\r
138 //! returns a new GpuMatrix header for the specified column
\r
139 GpuMat col(int x) const;
\r
140 //! ... for the specified row span
\r
141 GpuMat rowRange(int startrow, int endrow) const;
\r
142 GpuMat rowRange(const Range& r) const;
\r
143 //! ... for the specified column span
\r
144 GpuMat colRange(int startcol, int endcol) const;
\r
145 GpuMat colRange(const Range& r) const;
\r
147 //! returns deep copy of the GpuMatrix, i.e. the data is copied
\r
148 GpuMat clone() const;
\r
149 //! copies the GpuMatrix content to "m".
\r
150 // It calls m.create(this->size(), this->type()).
\r
151 void copyTo( GpuMat& m ) const;
\r
152 //! copies those GpuMatrix elements to "m" that are marked with non-zero mask elements.
\r
153 void copyTo( GpuMat& m, const GpuMat& mask ) const;
\r
154 //! converts GpuMatrix to another datatype with optional scalng. See cvConvertScale.
\r
155 void convertTo( GpuMat& m, int rtype, double alpha=1, double beta=0 ) const;
\r
157 void assignTo( GpuMat& m, int type=-1 ) const;
\r
159 //! sets every GpuMatrix element to s
\r
160 GpuMat& operator = (const Scalar& s);
\r
161 //! sets some of the GpuMatrix elements to s, according to the mask
\r
162 GpuMat& setTo(const Scalar& s, const GpuMat& mask = GpuMat());
\r
163 //! creates alternative GpuMatrix header for the same data, with different
\r
164 // number of channels and/or different number of rows. see cvReshape.
\r
165 GpuMat reshape(int cn, int rows = 0) const;
\r
167 //! allocates new GpuMatrix data unless the GpuMatrix already has specified size and type.
\r
168 // previous data is unreferenced if needed.
\r
169 void create(int rows, int cols, int type);
\r
170 void create(Size size, int type);
\r
171 //! decreases reference counter;
\r
172 // deallocate the data when reference counter reaches 0.
\r
175 //! swaps with other smart pointer
\r
176 void swap(GpuMat& mat);
\r
178 //! locates GpuMatrix header within a parent GpuMatrix. See below
\r
179 void locateROI( Size& wholeSize, Point& ofs ) const;
\r
180 //! moves/resizes the current GpuMatrix ROI inside the parent GpuMatrix.
\r
181 GpuMat& adjustROI( int dtop, int dbottom, int dleft, int dright );
\r
182 //! extracts a rectangular sub-GpuMatrix
\r
183 // (this is a generalized form of row, rowRange etc.)
\r
184 GpuMat operator()( Range rowRange, Range colRange ) const;
\r
185 GpuMat operator()( const Rect& roi ) const;
\r
187 //! returns true iff the GpuMatrix data is continuous
\r
188 // (i.e. when there are no gaps between successive rows).
\r
189 // similar to CV_IS_GpuMat_CONT(cvGpuMat->type)
\r
190 bool isContinuous() const;
\r
191 //! returns element size in bytes,
\r
192 // similar to CV_ELEM_SIZE(cvMat->type)
\r
193 size_t elemSize() const;
\r
194 //! returns the size of element channel in bytes.
\r
195 size_t elemSize1() const;
\r
196 //! returns element type, similar to CV_MAT_TYPE(cvMat->type)
\r
198 //! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
\r
200 //! returns element type, similar to CV_MAT_CN(cvMat->type)
\r
201 int channels() const;
\r
202 //! returns step/elemSize1()
\r
203 size_t step1() const;
\r
204 //! returns GpuMatrix size:
\r
205 // width == number of columns, height == number of rows
\r
207 //! returns true if GpuMatrix data is NULL
\r
208 bool empty() const;
\r
210 //! returns pointer to y-th row
\r
211 uchar* ptr(int y = 0);
\r
212 const uchar* ptr(int y = 0) const;
\r
214 //! template version of the above method
\r
215 template<typename _Tp> _Tp* ptr(int y = 0);
\r
216 template<typename _Tp> const _Tp* ptr(int y = 0) const;
\r
218 //! matrix transposition
\r
221 /*! includes several bit-fields:
\r
222 - the magic signature
\r
225 - number of channels
\r
228 //! the number of rows and columns
\r
230 //! a distance between successive rows in bytes; includes the gap if any
\r
232 //! pointer to the data
\r
235 //! pointer to the reference counter;
\r
236 // when GpuMatrix points to user-allocated data, the pointer is NULL
\r
239 //! helper fields used in locateROI and adjustROI
\r
244 //#define TemplatedGpuMat // experimental now, deprecated to use
\r
245 #ifdef TemplatedGpuMat
\r
246 #include "GpuMat_BetaDeprecated.hpp"
\r
249 //////////////////////////////// CudaMem ////////////////////////////////
\r
250 // CudaMem is limited cv::Mat with page locked memory allocation.
\r
251 // Page locked memory is only needed for async and faster coping to GPU.
\r
252 // It is convertable to cv::Mat header without reference counting
\r
253 // so you can use it with other opencv functions.
\r
255 class CV_EXPORTS CudaMem
\r
258 enum { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2, ALLOC_WRITE_COMBINED = 4 };
\r
261 CudaMem(const CudaMem& m);
\r
263 CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED);
\r
264 CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
267 //! creates from cv::Mat with coping data
\r
268 explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);
\r
272 CudaMem& operator = (const CudaMem& m);
\r
274 //! returns deep copy of the matrix, i.e. the data is copied
\r
275 CudaMem clone() const;
\r
277 //! allocates new matrix data unless the matrix already has specified size and type.
\r
278 void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
279 void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
281 //! decrements reference counter and released memory if needed.
\r
284 //! returns matrix header with disabled reference counting for CudaMem data.
\r
285 Mat createMatHeader() const;
\r
286 operator Mat() const;
\r
288 //! maps host memory into device address space and returns GpuMat header for it. Throws exception if not supported by hardware.
\r
289 GpuMat createGpuMatHeader() const;
\r
290 operator GpuMat() const;
\r
292 //returns if host memory can be mapperd to gpu address space;
\r
293 static bool canMapHostMemory();
\r
295 // Please see cv::Mat for descriptions
\r
296 bool isContinuous() const;
\r
297 size_t elemSize() const;
\r
298 size_t elemSize1() const;
\r
301 int channels() const;
\r
302 size_t step1() const;
\r
304 bool empty() const;
\r
307 // Please see cv::Mat for descriptions
\r
321 //////////////////////////////// CudaStream ////////////////////////////////
\r
322 // Encapculates Cuda Stream. Provides interface for async coping.
\r
323 // Passed to each function that supports async kernel execution.
\r
324 // Reference counting is enabled
\r
326 class CV_EXPORTS Stream
\r
332 Stream(const Stream&);
\r
333 Stream& operator=(const Stream&);
\r
335 bool queryIfComplete();
\r
336 void waitForCompletion();
\r
338 //! downloads asynchronously.
\r
339 // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its subMat)
\r
340 void enqueueDownload(const GpuMat& src, CudaMem& dst);
\r
341 void enqueueDownload(const GpuMat& src, Mat& dst);
\r
343 //! uploads asynchronously.
\r
344 // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI)
\r
345 void enqueueUpload(const CudaMem& src, GpuMat& dst);
\r
346 void enqueueUpload(const Mat& src, GpuMat& dst);
\r
348 void enqueueCopy(const GpuMat& src, GpuMat& dst);
\r
350 void enqueueMemSet(const GpuMat& src, Scalar val);
\r
351 void enqueueMemSet(const GpuMat& src, Scalar val, const GpuMat& mask);
\r
353 // converts matrix type, ex from float to uchar depending on type
\r
354 void enqueueConvert(const GpuMat& src, GpuMat& dst, int type, double a = 1, double b = 0);
\r
360 friend struct StreamAccessor;
\r
363 ////////////////////////////// Arithmetics ///////////////////////////////////
\r
365 //! adds one matrix to another (c = a + b)
\r
366 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
367 CV_EXPORTS void add(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
368 //! adds scalar to a matrix (c = a + s)
\r
369 //! supports CV_32FC1 and CV_32FC2 type
\r
370 CV_EXPORTS void add(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
371 //! subtracts one matrix from another (c = a - b)
\r
372 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
373 CV_EXPORTS void subtract(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
374 //! subtracts scalar from a matrix (c = a - s)
\r
375 //! supports CV_32FC1 and CV_32FC2 type
\r
376 CV_EXPORTS void subtract(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
377 //! computes element-wise product of the two arrays (c = a * b)
\r
378 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
379 CV_EXPORTS void multiply(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
380 //! multiplies matrix to a scalar (c = a * s)
\r
381 //! supports CV_32FC1 and CV_32FC2 type
\r
382 CV_EXPORTS void multiply(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
383 //! computes element-wise quotient of the two arrays (c = a / b)
\r
384 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
385 CV_EXPORTS void divide(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
386 //! computes element-wise quotient of matrix and scalar (c = a / s)
\r
387 //! supports CV_32FC1 and CV_32FC2 type
\r
388 CV_EXPORTS void divide(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
390 //! transposes the matrix
\r
391 //! supports only CV_8UC1 type
\r
392 CV_EXPORTS void transpose(const GpuMat& src1, GpuMat& dst);
\r
394 //! computes element-wise absolute difference of two arrays (c = abs(a - b))
\r
395 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
396 CV_EXPORTS void absdiff(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
397 //! computes element-wise absolute difference of array and scalar (c = abs(a - s))
\r
398 //! supports only CV_32FC1 type
\r
399 CV_EXPORTS void absdiff(const GpuMat& a, const Scalar& s, GpuMat& c);
\r
401 //! compares elements of two arrays (c = a <cmpop> b)
\r
402 //! supports CV_8UC4, CV_32FC1 types
\r
403 CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop);
\r
405 //! computes mean value and standard deviation of all or selected array elements
\r
406 //! supports only CV_8UC1 type
\r
407 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev);
\r
409 //! computes norm of array
\r
410 //! supports NORM_INF, NORM_L1, NORM_L2
\r
411 //! supports only CV_8UC1 type
\r
412 CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);
\r
414 //! computes norm of the difference between two arrays
\r
415 //! supports NORM_INF, NORM_L1, NORM_L2
\r
416 //! supports only CV_8UC1 type
\r
417 CV_EXPORTS double norm(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2);
\r
419 //! reverses the order of the rows, columns or both in a matrix
\r
420 //! supports CV_8UC1, CV_8UC4 types
\r
421 CV_EXPORTS void flip(const GpuMat& a, GpuMat& b, int flipCode);
\r
423 //! computes sum of array elements
\r
424 //! supports CV_8UC1, CV_8UC4 types
\r
425 //! disabled until fix crash
\r
426 CV_EXPORTS Scalar sum(const GpuMat& m);
\r
428 //! finds global minimum and maximum array elements and returns their values
\r
429 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat());
\r
431 //! finds global minimum and maximum array elements and returns their values
\r
432 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf);
\r
434 //! finds global minimum and maximum array elements and returns their values with locations
\r
435 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0,
\r
436 const GpuMat& mask=GpuMat());
\r
438 //! finds global minimum and maximum array elements and returns their values with locations
\r
439 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
\r
440 const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf);
\r
442 //! counts non-zero array elements
\r
443 CV_EXPORTS int countNonZero(const GpuMat& src);
\r
445 //! counts non-zero array elements
\r
446 CV_EXPORTS int countNonZero(const GpuMat& src, GpuMat& buf);
\r
448 //! transforms 8-bit unsigned integers using lookup table: dst(i)=lut(src(i))
\r
449 //! destination array will have the depth type as lut and the same channels number as source
\r
450 //! supports CV_8UC1, CV_8UC3 types
\r
451 CV_EXPORTS void LUT(const GpuMat& src, const Mat& lut, GpuMat& dst);
\r
453 //! makes multi-channel array out of several single-channel arrays
\r
454 CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst);
\r
456 //! makes multi-channel array out of several single-channel arrays
\r
457 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst);
\r
459 //! makes multi-channel array out of several single-channel arrays (async version)
\r
460 CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, const Stream& stream);
\r
462 //! makes multi-channel array out of several single-channel arrays (async version)
\r
463 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, const Stream& stream);
\r
465 //! copies each plane of a multi-channel array to a dedicated array
\r
466 CV_EXPORTS void split(const GpuMat& src, GpuMat* dst);
\r
468 //! copies each plane of a multi-channel array to a dedicated array
\r
469 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst);
\r
471 //! copies each plane of a multi-channel array to a dedicated array (async version)
\r
472 CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, const Stream& stream);
\r
474 //! copies each plane of a multi-channel array to a dedicated array (async version)
\r
475 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, const Stream& stream);
\r
477 //! computes exponent of each matrix element (b = e**a)
\r
478 //! supports only CV_32FC1 type
\r
479 CV_EXPORTS void exp(const GpuMat& a, GpuMat& b);
\r
481 //! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))
\r
482 //! supports only CV_32FC1 type
\r
483 CV_EXPORTS void log(const GpuMat& a, GpuMat& b);
\r
485 //! computes magnitude of complex (x(i).re, x(i).im) vector
\r
486 //! supports only CV_32FC2 type
\r
487 CV_EXPORTS void magnitude(const GpuMat& x, GpuMat& magnitude);
\r
489 //! computes squared magnitude of complex (x(i).re, x(i).im) vector
\r
490 //! supports only CV_32FC2 type
\r
491 CV_EXPORTS void magnitudeSqr(const GpuMat& x, GpuMat& magnitude);
\r
493 //! computes magnitude of each (x(i), y(i)) vector
\r
494 //! supports only floating-point source
\r
495 CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);
\r
497 CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);
\r
499 //! computes squared magnitude of each (x(i), y(i)) vector
\r
500 //! supports only floating-point source
\r
501 CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);
\r
503 CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);
\r
505 //! computes angle (angle(i)) of each (x(i), y(i)) vector
\r
506 //! supports only floating-point source
\r
507 CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false);
\r
509 CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, const Stream& stream);
\r
511 //! converts Cartesian coordinates to polar
\r
512 //! supports only floating-point source
\r
513 CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false);
\r
515 CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees, const Stream& stream);
\r
517 //! converts polar coordinates to Cartesian
\r
518 //! supports only floating-point source
\r
519 CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false);
\r
521 CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, const Stream& stream);
\r
524 //! perfroms per-elements bit-wise inversion
\r
525 CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
527 CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
529 //! calculates per-element bit-wise disjunction of two arrays
\r
530 CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
532 CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
534 //! calculates per-element bit-wise conjunction of two arrays
\r
535 CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
537 CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
539 //! calculates per-element bit-wise "exclusive or" operation
\r
540 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
542 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
544 //! Logical operators
\r
545 CV_EXPORTS GpuMat operator ~ (const GpuMat& src);
\r
546 CV_EXPORTS GpuMat operator | (const GpuMat& src1, const GpuMat& src2);
\r
547 CV_EXPORTS GpuMat operator & (const GpuMat& src1, const GpuMat& src2);
\r
548 CV_EXPORTS GpuMat operator ^ (const GpuMat& src1, const GpuMat& src2);
\r
550 //! computes per-element minimum of two arrays (dst = min(src1, src2))
\r
551 CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst);
\r
553 CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream);
\r
555 //! computes per-element minimum of array and scalar (dst = min(src1, src2))
\r
556 CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst);
\r
558 CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst, const Stream& stream);
\r
560 //! computes per-element maximum of two arrays (dst = max(src1, src2))
\r
561 CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst);
\r
563 CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream);
\r
565 //! computes per-element maximum of array and scalar (dst = max(src1, src2))
\r
566 CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst);
\r
568 CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst, const Stream& stream);
\r
571 ////////////////////////////// Image processing //////////////////////////////
\r
573 //! DST[x,y] = SRC[xmap[x,y],ymap[x,y]] with bilinear interpolation.
\r
574 //! supports CV_8UC1, CV_8UC3 source types and CV_32FC1 map type
\r
575 CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap);
\r
577 //! Does mean shift filtering on GPU.
\r
578 CV_EXPORTS void meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr,
\r
579 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
\r
581 //! Does mean shift procedure on GPU.
\r
582 CV_EXPORTS void meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr,
\r
583 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
\r
585 //! Does mean shift segmentation with elimiation of small regions.
\r
586 CV_EXPORTS void meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize,
\r
587 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
\r
589 //! Does coloring of disparity image: [0..ndisp) -> [0..240, 1, 1] in HSV.
\r
590 //! Supported types of input disparity: CV_8U, CV_16S.
\r
591 //! Output disparity has CV_8UC4 type in BGRA format (alpha = 255).
\r
592 CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp);
\r
594 CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, const Stream& stream);
\r
596 //! Reprojects disparity image to 3D space.
\r
597 //! Supports CV_8U and CV_16S types of input disparity.
\r
598 //! The output is a 4-channel floating-point (CV_32FC4) matrix.
\r
599 //! Each element of this matrix will contain the 3D coordinates of the point (x,y,z,1), computed from the disparity map.
\r
600 //! Q is the 4x4 perspective transformation matrix that can be obtained with cvStereoRectify.
\r
601 CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q);
\r
603 CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, const Stream& stream);
\r
605 //! converts image from one color space to another
\r
606 CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0);
\r
608 CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream);
\r
610 //! applies fixed threshold to the image.
\r
611 //! Now supports only THRESH_TRUNC threshold type and one channels float source.
\r
612 CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh);
\r
614 //! resizes the image
\r
615 //! Supports INTER_NEAREST, INTER_LINEAR
\r
616 //! supports CV_8UC1, CV_8UC4 types
\r
617 CV_EXPORTS void resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR);
\r
619 //! warps the image using affine transformation
\r
620 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
621 CV_EXPORTS void warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR);
\r
623 //! warps the image using perspective transformation
\r
624 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
625 CV_EXPORTS void warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR);
\r
627 //! rotate 8bit single or four channel image
\r
628 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
629 //! supports CV_8UC1, CV_8UC4 types
\r
630 CV_EXPORTS void rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0, int interpolation = INTER_LINEAR);
\r
632 //! copies 2D array to a larger destination array and pads borders with user-specifiable constant
\r
633 //! supports CV_8UC1, CV_8UC4, CV_32SC1 types
\r
634 CV_EXPORTS void copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, const Scalar& value = Scalar());
\r
636 //! computes the integral image and integral for the squared image
\r
637 //! sum will have CV_32S type, sqsum - CV32F type
\r
638 //! supports only CV_8UC1 source type
\r
639 CV_EXPORTS void integral(GpuMat& src, GpuMat& sum, GpuMat& sqsum);
\r
641 //! computes the standard deviation of integral images
\r
642 //! supports only CV_32SC1 source type and CV_32FC1 sqr type
\r
643 //! output will have CV_32FC1 type
\r
644 CV_EXPORTS void rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect);
\r
646 //! applies Canny edge detector and produces the edge map
\r
647 //! supprots only CV_8UC1 source type
\r
648 //! disabled until fix crash
\r
649 CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double threshold1, double threshold2, int apertureSize = 3);
\r
651 //! computes Harris cornerness criteria at each image pixel
\r
652 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType=BORDER_REFLECT101);
\r
655 //! computes minimum eigen value of 2x2 derivative covariation matrix at each pixel - the cornerness criteria
\r
656 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
\r
659 //////////////////////////////// Filter Engine ////////////////////////////////
\r
662 The Base Class for 1D or Row-wise Filters
\r
664 This is the base class for linear or non-linear filters that process 1D data.
\r
665 In particular, such filters are used for the "horizontal" filtering parts in separable filters.
\r
667 class CV_EXPORTS BaseRowFilter_GPU
\r
670 BaseRowFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
671 virtual ~BaseRowFilter_GPU() {}
\r
672 virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;
\r
677 The Base Class for Column-wise Filters
\r
679 This is the base class for linear or non-linear filters that process columns of 2D arrays.
\r
680 Such filters are used for the "vertical" filtering parts in separable filters.
\r
682 class CV_EXPORTS BaseColumnFilter_GPU
\r
685 BaseColumnFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
686 virtual ~BaseColumnFilter_GPU() {}
\r
687 virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;
\r
692 The Base Class for Non-Separable 2D Filters.
\r
694 This is the base class for linear or non-linear 2D filters.
\r
696 class CV_EXPORTS BaseFilter_GPU
\r
699 BaseFilter_GPU(const Size& ksize_, const Point& anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
700 virtual ~BaseFilter_GPU() {}
\r
701 virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;
\r
707 The Base Class for Filter Engine.
\r
709 The class can be used to apply an arbitrary filtering operation to an image.
\r
710 It contains all the necessary intermediate buffers.
\r
712 class CV_EXPORTS FilterEngine_GPU
\r
715 virtual ~FilterEngine_GPU() {}
\r
717 virtual void apply(const GpuMat& src, GpuMat& dst, Rect roi = Rect(0,0,-1,-1)) = 0;
\r
720 //! returns the non-separable filter engine with the specified filter
\r
721 CV_EXPORTS Ptr<FilterEngine_GPU> createFilter2D_GPU(const Ptr<BaseFilter_GPU> filter2D);
\r
723 //! returns the separable filter engine with the specified filters
\r
724 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>& rowFilter,
\r
725 const Ptr<BaseColumnFilter_GPU>& columnFilter);
\r
727 //! returns horizontal 1D box filter
\r
728 //! supports only CV_8UC1 source type and CV_32FC1 sum type
\r
729 CV_EXPORTS Ptr<BaseRowFilter_GPU> getRowSumFilter_GPU(int srcType, int sumType, int ksize, int anchor = -1);
\r
731 //! returns vertical 1D box filter
\r
732 //! supports only CV_8UC1 sum type and CV_32FC1 dst type
\r
733 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getColumnSumFilter_GPU(int sumType, int dstType, int ksize, int anchor = -1);
\r
735 //! returns 2D box filter
\r
736 //! supports CV_8UC1 and CV_8UC4 source type, dst type must be the same as source type
\r
737 CV_EXPORTS Ptr<BaseFilter_GPU> getBoxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1, -1));
\r
739 //! returns box filter engine
\r
740 CV_EXPORTS Ptr<FilterEngine_GPU> createBoxFilter_GPU(int srcType, int dstType, const Size& ksize,
\r
741 const Point& anchor = Point(-1,-1));
\r
743 //! returns 2D morphological filter
\r
744 //! only MORPH_ERODE and MORPH_DILATE are supported
\r
745 //! supports CV_8UC1 and CV_8UC4 types
\r
746 //! kernel must have CV_8UC1 type, one rows and cols == ksize.width * ksize.height
\r
747 CV_EXPORTS Ptr<BaseFilter_GPU> getMorphologyFilter_GPU(int op, int type, const Mat& kernel, const Size& ksize,
\r
748 Point anchor=Point(-1,-1));
\r
750 //! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported.
\r
751 CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat& kernel,
\r
752 const Point& anchor = Point(-1,-1), int iterations = 1);
\r
754 //! returns 2D filter with the specified kernel
\r
755 //! supports CV_8UC1 and CV_8UC4 types
\r
756 CV_EXPORTS Ptr<BaseFilter_GPU> getLinearFilter_GPU(int srcType, int dstType, const Mat& kernel, const Size& ksize,
\r
757 Point anchor = Point(-1, -1));
\r
759 //! returns the non-separable linear filter engine
\r
760 CV_EXPORTS Ptr<FilterEngine_GPU> createLinearFilter_GPU(int srcType, int dstType, const Mat& kernel,
\r
761 const Point& anchor = Point(-1,-1));
\r
763 //! returns the primitive row filter with the specified kernel
\r
764 CV_EXPORTS Ptr<BaseRowFilter_GPU> getLinearRowFilter_GPU(int srcType, int bufType, const Mat& rowKernel,
\r
767 //! returns the primitive column filter with the specified kernel
\r
768 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getLinearColumnFilter_GPU(int bufType, int dstType, const Mat& columnKernel,
\r
771 //! returns the separable linear filter engine
\r
772 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel,
\r
773 const Mat& columnKernel, const Point& anchor = Point(-1,-1));
\r
775 //! returns filter engine for the generalized Sobel operator
\r
776 CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize);
\r
778 //! returns the Gaussian filter engine
\r
779 CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, double sigma1, double sigma2 = 0);
\r
781 //! returns maximum filter
\r
782 CV_EXPORTS Ptr<BaseFilter_GPU> getMaxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
\r
784 //! returns minimum filter
\r
785 CV_EXPORTS Ptr<BaseFilter_GPU> getMinFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
\r
787 //! smooths the image using the normalized box filter
\r
788 //! supports CV_8UC1, CV_8UC4 types
\r
789 CV_EXPORTS void boxFilter(const GpuMat& src, GpuMat& dst, int ddepth, Size ksize, Point anchor = Point(-1,-1));
\r
791 //! a synonym for normalized box filter
\r
792 static inline void blur(const GpuMat& src, GpuMat& dst, Size ksize, Point anchor = Point(-1,-1)) { boxFilter(src, dst, -1, ksize, anchor); }
\r
794 //! erodes the image (applies the local minimum operator)
\r
795 CV_EXPORTS void erode( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
797 //! dilates the image (applies the local maximum operator)
\r
798 CV_EXPORTS void dilate( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
800 //! applies an advanced morphological operation to the image
\r
801 CV_EXPORTS void morphologyEx( const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
803 //! applies non-separable 2D linear filter to the image
\r
804 CV_EXPORTS void filter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernel, Point anchor=Point(-1,-1));
\r
806 //! applies separable 2D linear filter to the image
\r
807 CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY,
\r
808 Point anchor = Point(-1,-1));
\r
810 //! applies generalized Sobel operator to the image
\r
811 CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1);
\r
813 //! applies the vertical or horizontal Scharr operator to the image
\r
814 CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, double scale = 1);
\r
816 //! smooths the image using Gaussian filter.
\r
817 CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, double sigma1, double sigma2 = 0);
\r
819 //! applies Laplacian operator to the image
\r
820 //! supports only ksize = 1 and ksize = 3
\r
821 CV_EXPORTS void Laplacian(const GpuMat& src, GpuMat& dst, int ddepth, int ksize = 1, double scale = 1);
\r
823 //////////////////////////////// Image Labeling ////////////////////////////////
\r
825 //!performs labeling via graph cuts
\r
826 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels, GpuMat& buf);
\r
828 ////////////////////////////////// Histograms //////////////////////////////////
\r
830 //! Compute levels with even distribution. levels will have 1 row and nLevels cols and CV_32SC1 type.
\r
831 CV_EXPORTS void evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel);
\r
832 //! Calculates histogram with evenly distributed bins for signle channel source.
\r
833 //! Supports CV_8UC1, CV_16UC1 and CV_16SC1 source types.
\r
834 //! Output hist will have one row and histSize cols and CV_32SC1 type.
\r
835 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel);
\r
836 //! Calculates histogram with evenly distributed bins for four-channel source.
\r
837 //! All channels of source are processed separately.
\r
838 //! Supports CV_8UC4, CV_16UC4 and CV_16SC4 source types.
\r
839 //! Output hist[i] will have one row and histSize[i] cols and CV_32SC1 type.
\r
840 CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4]);
\r
841 //! Calculates histogram with bins determined by levels array.
\r
842 //! levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
843 //! Supports CV_8UC1, CV_16UC1, CV_16SC1 and CV_32FC1 source types.
\r
844 //! Output hist will have one row and (levels.cols-1) cols and CV_32SC1 type.
\r
845 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels);
\r
846 //! Calculates histogram with bins determined by levels array.
\r
847 //! All levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
848 //! All channels of source are processed separately.
\r
849 //! Supports CV_8UC4, CV_16UC4, CV_16SC4 and CV_32FC4 source types.
\r
850 //! Output hist[i] will have one row and (levels[i].cols-1) cols and CV_32SC1 type.
\r
851 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4]);
\r
853 //////////////////////////////// StereoBM_GPU ////////////////////////////////
\r
855 class CV_EXPORTS StereoBM_GPU
\r
858 enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 };
\r
860 enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 };
\r
862 //! the default constructor
\r
864 //! the full constructor taking the camera-specific preset, number of disparities and the SAD window size. ndisparities must be multiple of 8.
\r
865 StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ);
\r
867 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair
\r
868 //! Output disparity has CV_8U type.
\r
869 void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity);
\r
872 void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream & stream);
\r
874 //! Some heuristics that tries to estmate
\r
875 // if current GPU will be faster then CPU in this algorithm.
\r
876 // It queries current active device.
\r
877 static bool checkIfGpuCallReasonable();
\r
883 // If avergeTexThreshold == 0 => post procesing is disabled
\r
884 // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image
\r
885 // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold
\r
886 // i.e. input left image is low textured.
\r
887 float avergeTexThreshold;
\r
889 GpuMat minSSD, leBuf, riBuf;
\r
892 ////////////////////////// StereoBeliefPropagation ///////////////////////////
\r
893 // "Efficient Belief Propagation for Early Vision"
\r
896 class CV_EXPORTS StereoBeliefPropagation
\r
899 enum { DEFAULT_NDISP = 64 };
\r
900 enum { DEFAULT_ITERS = 5 };
\r
901 enum { DEFAULT_LEVELS = 5 };
\r
903 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels);
\r
905 //! the default constructor
\r
906 explicit StereoBeliefPropagation(int ndisp = DEFAULT_NDISP,
\r
907 int iters = DEFAULT_ITERS,
\r
908 int levels = DEFAULT_LEVELS,
\r
909 int msg_type = CV_32F);
\r
911 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
912 //! number of levels, truncation of data cost, data weight,
\r
913 //! truncation of discontinuity cost and discontinuity single jump
\r
914 //! DataTerm = data_weight * min(fabs(I2-I1), max_data_term)
\r
915 //! DiscTerm = min(disc_single_jump * fabs(f1-f2), max_disc_term)
\r
916 //! please see paper for more details
\r
917 StereoBeliefPropagation(int ndisp, int iters, int levels,
\r
918 float max_data_term, float data_weight,
\r
919 float max_disc_term, float disc_single_jump,
\r
920 int msg_type = CV_32F);
\r
922 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
923 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
924 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);
\r
927 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);
\r
930 //! version for user specified data term
\r
931 void operator()(const GpuMat& data, GpuMat& disparity);
\r
932 void operator()(const GpuMat& data, GpuMat& disparity, Stream& stream);
\r
939 float max_data_term;
\r
941 float max_disc_term;
\r
942 float disc_single_jump;
\r
946 GpuMat u, d, l, r, u2, d2, l2, r2;
\r
947 std::vector<GpuMat> datas;
\r
951 /////////////////////////// StereoConstantSpaceBP ///////////////////////////
\r
952 // "A Constant-Space Belief Propagation Algorithm for Stereo Matching"
\r
953 // Qingxiong Yang, Liang Wang
\86, Narendra Ahuja
\r
954 // http://vision.ai.uiuc.edu/~qyang6/
\r
956 class CV_EXPORTS StereoConstantSpaceBP
\r
959 enum { DEFAULT_NDISP = 128 };
\r
960 enum { DEFAULT_ITERS = 8 };
\r
961 enum { DEFAULT_LEVELS = 4 };
\r
962 enum { DEFAULT_NR_PLANE = 4 };
\r
964 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane);
\r
966 //! the default constructor
\r
967 explicit StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP,
\r
968 int iters = DEFAULT_ITERS,
\r
969 int levels = DEFAULT_LEVELS,
\r
970 int nr_plane = DEFAULT_NR_PLANE,
\r
971 int msg_type = CV_32F);
\r
973 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
974 //! number of levels, number of active disparity on the first level, truncation of data cost, data weight,
\r
975 //! truncation of discontinuity cost, discontinuity single jump and minimum disparity threshold
\r
976 StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,
\r
977 float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,
\r
978 int min_disp_th = 0,
\r
979 int msg_type = CV_32F);
\r
981 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
982 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
983 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);
\r
986 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);
\r
995 float max_data_term;
\r
997 float max_disc_term;
\r
998 float disc_single_jump;
\r
1004 bool use_local_init_data_cost;
\r
1006 GpuMat u[2], d[2], l[2], r[2];
\r
1007 GpuMat disp_selected_pyr[2];
\r
1010 GpuMat data_cost_selected;
\r
1017 /////////////////////////// DisparityBilateralFilter ///////////////////////////
\r
1018 // Disparity map refinement using joint bilateral filtering given a single color image.
\r
1019 // Qingxiong Yang, Liang Wang
\86, Narendra Ahuja
\r
1020 // http://vision.ai.uiuc.edu/~qyang6/
\r
1022 class CV_EXPORTS DisparityBilateralFilter
\r
1025 enum { DEFAULT_NDISP = 64 };
\r
1026 enum { DEFAULT_RADIUS = 3 };
\r
1027 enum { DEFAULT_ITERS = 1 };
\r
1029 //! the default constructor
\r
1030 explicit DisparityBilateralFilter(int ndisp = DEFAULT_NDISP, int radius = DEFAULT_RADIUS, int iters = DEFAULT_ITERS);
\r
1032 //! the full constructor taking the number of disparities, filter radius,
\r
1033 //! number of iterations, truncation of data continuity, truncation of disparity continuity
\r
1034 //! and filter range sigma
\r
1035 DisparityBilateralFilter(int ndisp, int radius, int iters, float edge_threshold, float max_disc_threshold, float sigma_range);
\r
1037 //! the disparity map refinement operator. Refine disparity map using joint bilateral filtering given a single color image.
\r
1038 //! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type.
\r
1039 void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst);
\r
1042 void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream);
\r
1049 float edge_threshold;
\r
1050 float max_disc_threshold;
\r
1051 float sigma_range;
\r
1053 GpuMat table_color;
\r
1054 GpuMat table_space;
\r
1058 //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
\r
1060 struct CV_EXPORTS HOGDescriptor
\r
1063 enum { DEFAULT_WIN_SIGMA = -1 };
\r
1064 enum { DEFAULT_NLEVELS = 64 };
\r
1065 enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
\r
1067 HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16),
\r
1068 Size block_stride=Size(8, 8), Size cell_size=Size(8, 8),
\r
1069 int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA,
\r
1070 double threshold_L2hys=0.2, bool gamma_correction=true,
\r
1071 int nlevels=DEFAULT_NLEVELS);
\r
1073 size_t getDescriptorSize() const;
\r
1074 size_t getBlockHistogramSize() const;
\r
1075 double getWinSigma() const;
\r
1077 static vector<float> getDefaultPeopleDetector();
\r
1078 static vector<float> getPeopleDetector_48x96();
\r
1079 static vector<float> getPeopleDetector_64x128();
\r
1080 void setSVMDetector(const vector<float>& detector);
\r
1081 bool checkDetectorSize() const;
\r
1083 void detect(const GpuMat& img, vector<Point>& found_locations, double hit_threshold=0,
\r
1084 Size win_stride=Size(), Size padding=Size());
\r
1085 void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
\r
1086 double hit_threshold=0, Size win_stride=Size(), Size padding=Size(),
\r
1087 double scale0=1.05, int group_threshold=2);
\r
1089 void getDescriptors(const GpuMat& img, Size win_stride, GpuMat& descriptors,
\r
1090 int descr_format=DESCR_FORMAT_COL_BY_COL);
\r
1094 Size block_stride;
\r
1098 double threshold_L2hys;
\r
1100 bool gamma_correction;
\r
1103 void computeBlockHistograms(const GpuMat& img);
\r
1104 void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle);
\r
1106 static int numPartsWithin(int size, int part_size, int stride);
\r
1107 static Size numPartsWithin(Size size, Size part_size, Size stride);
\r
1109 // Coefficients of the separating plane
\r
1113 // Results of the last classification step
\r
1117 // Results of the last histogram evaluation step
\r
1118 GpuMat block_hists;
\r
1120 // Gradients conputation results
\r
1121 GpuMat grad, qangle;
\r
1125 ////////////////////////////////// BruteForceMatcher //////////////////////////////////
\r
1127 class CV_EXPORTS BruteForceMatcher_GPU_base
\r
1130 enum DistType {L1Dist = 0, L2Dist};
\r
1132 explicit BruteForceMatcher_GPU_base(DistType distType = L2Dist);
\r
1134 // Add descriptors to train descriptor collection.
\r
1135 void add(const std::vector<GpuMat>& descCollection);
\r
1137 // Get train descriptors collection.
\r
1138 const std::vector<GpuMat>& getTrainDescriptors() const;
\r
1140 // Clear train descriptors collection.
\r
1143 // Return true if there are not train descriptors in collection.
\r
1144 bool empty() const;
\r
1146 // Return true if the matcher supports mask in match methods.
\r
1147 bool isMaskSupported() const;
\r
1149 // Find one best match for each query descriptor.
\r
1150 // trainIdx.at<int>(0, queryIdx) will contain best train index for queryIdx
\r
1151 // distance.at<float>(0, queryIdx) will contain distance
\r
1152 void matchSingle(const GpuMat& queryDescs, const GpuMat& trainDescs,
\r
1153 GpuMat& trainIdx, GpuMat& distance,
\r
1154 const GpuMat& mask = GpuMat());
\r
1156 // Download trainIdx and distance to CPU vector with DMatch
\r
1157 static void matchDownload(const GpuMat& trainIdx, const GpuMat& distance, std::vector<DMatch>& matches);
\r
1159 // Find one best match for each query descriptor.
\r
1160 void match(const GpuMat& queryDescs, const GpuMat& trainDescs, std::vector<DMatch>& matches,
\r
1161 const GpuMat& mask = GpuMat());
\r
1163 // Make gpu collection of trains and masks in suitable format for matchCollection function
\r
1164 void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection,
\r
1165 const vector<GpuMat>& masks = std::vector<GpuMat>());
\r
1167 // Find one best match from train collection for each query descriptor.
\r
1168 // trainIdx.at<int>(0, queryIdx) will contain best train index for queryIdx
\r
1169 // imgIdx.at<int>(0, queryIdx) will contain best image index for queryIdx
\r
1170 // distance.at<float>(0, queryIdx) will contain distance
\r
1171 void matchCollection(const GpuMat& queryDescs, const GpuMat& trainCollection,
\r
1172 GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
\r
1173 const GpuMat& maskCollection);
\r
1175 // Download trainIdx, imgIdx and distance to CPU vector with DMatch
\r
1176 static void matchDownload(const GpuMat& trainIdx, GpuMat& imgIdx, const GpuMat& distance,
\r
1177 std::vector<DMatch>& matches);
\r
1179 // Find one best match from train collection for each query descriptor.
\r
1180 void match(const GpuMat& queryDescs, std::vector<DMatch>& matches,
\r
1181 const std::vector<GpuMat>& masks = std::vector<GpuMat>());
\r
1183 // Find k best matches for each query descriptor (in increasing order of distances).
\r
1184 // trainIdx.at<int>(queryIdx, i) will contain index of i'th best trains (i < k).
\r
1185 // distance.at<float>(queryIdx, i) will contain distance.
\r
1186 // allDist is a buffer to store all distance between query descriptors and train descriptors
\r
1187 // it have size (nQuery,nTrain) and CV_32F type
\r
1188 // allDist.at<float>(queryIdx, trainIdx) will contain FLT_MAX, if trainIdx is one from k best,
\r
1189 // otherwise it will contain distance between queryIdx and trainIdx descriptors
\r
1190 void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
\r
1191 GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k, const GpuMat& mask = GpuMat());
\r
1193 // Download trainIdx and distance to CPU vector with DMatch
\r
1194 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1195 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1196 // matches vector will not contain matches for fully masked out query descriptors.
\r
1197 static void knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance,
\r
1198 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1200 // Find k best matches for each query descriptor (in increasing order of distances).
\r
1201 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1202 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1203 // matches vector will not contain matches for fully masked out query descriptors.
\r
1204 void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
\r
1205 std::vector< std::vector<DMatch> >& matches, int k, const GpuMat& mask = GpuMat(),
\r
1206 bool compactResult = false);
\r
1208 // Find k best matches for each query descriptor (in increasing order of distances).
\r
1209 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1210 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1211 // matches vector will not contain matches for fully masked out query descriptors.
\r
1212 void knnMatch(const GpuMat& queryDescs, std::vector< std::vector<DMatch> >& matches, int knn,
\r
1213 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false );
\r
1215 // Find best matches for each query descriptor which have distance less than maxDistance.
\r
1216 // nMatches.at<unsigned int>(0, queruIdx) will contain matches count for queryIdx.
\r
1217 // carefully nMatches can be greater than trainIdx.cols - it means that matcher didn't find all matches,
\r
1218 // because it didn't have enough memory.
\r
1219 // trainIdx.at<int>(queruIdx, i) will contain ith train index (i < min(nMatches.at<unsigned int>(0, queruIdx), trainIdx.cols))
\r
1220 // distance.at<int>(queruIdx, i) will contain ith distance (i < min(nMatches.at<unsigned int>(0, queruIdx), trainIdx.cols))
\r
1221 // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x nTrain,
\r
1222 // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
\r
1223 // Matches doesn't sorted.
\r
1224 void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
\r
1225 GpuMat& trainIdx, GpuMat& nMatches, GpuMat& distance, float maxDistance,
\r
1226 const GpuMat& mask = GpuMat());
\r
1228 // Download trainIdx, nMatches and distance to CPU vector with DMatch.
\r
1229 // matches will be sorted in increasing order of distances.
\r
1230 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1231 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1232 // matches vector will not contain matches for fully masked out query descriptors.
\r
1233 static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& nMatches, const GpuMat& distance,
\r
1234 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1236 // Find best matches for each query descriptor which have distance less than maxDistance
\r
1237 // in increasing order of distances).
\r
1238 void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs,
\r
1239 std::vector< std::vector<DMatch> >& matches, float maxDistance,
\r
1240 const GpuMat& mask = GpuMat(), bool compactResult = false);
\r
1242 // Find best matches from train collection for each query descriptor which have distance less than
\r
1243 // maxDistance (in increasing order of distances).
\r
1244 void radiusMatch(const GpuMat& queryDescs, std::vector< std::vector<DMatch> >& matches, float maxDistance,
\r
1245 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
\r
1248 DistType distType;
\r
1250 std::vector<GpuMat> trainDescCollection;
\r
1253 template <class Distance>
\r
1254 class CV_EXPORTS BruteForceMatcher_GPU;
\r
1256 template <typename T>
\r
1257 class CV_EXPORTS BruteForceMatcher_GPU< L1<T> > : public BruteForceMatcher_GPU_base
\r
1260 explicit BruteForceMatcher_GPU(L1<T> d = L1<T>()) : BruteForceMatcher_GPU_base(L1Dist) {}
\r
1262 template <typename T>
\r
1263 class CV_EXPORTS BruteForceMatcher_GPU< L2<T> > : public BruteForceMatcher_GPU_base
\r
1266 explicit BruteForceMatcher_GPU(L2<T> d = L2<T>()) : BruteForceMatcher_GPU_base(L2Dist) {}
\r
1271 //! Speckle filtering - filters small connected components on diparity image.
\r
1272 //! It sets pixel (x,y) to newVal if it coresponds to small CC with size < maxSpeckleSize.
\r
1273 //! Threshold for border between CC is diffThreshold;
\r
1274 CV_EXPORTS void filterSpeckles( Mat& img, uchar newVal, int maxSpeckleSize, uchar diffThreshold, Mat& buf);
\r
1277 #include "opencv2/gpu/matrix_operations.hpp"
\r
1279 #endif /* __OPENCV_GPU_HPP__ */
\r