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
56 //////////////////////////////// Initialization & Info ////////////////////////
\r
58 //! This is the only function that do not throw exceptions if the library is compiled without Cuda.
\r
59 CV_EXPORTS int getCudaEnabledDeviceCount();
\r
61 //! Functions below throw cv::Expception if the library is compiled without Cuda.
\r
62 CV_EXPORTS string getDeviceName(int device);
\r
63 CV_EXPORTS void setDevice(int device);
\r
64 CV_EXPORTS int getDevice();
\r
66 CV_EXPORTS void getComputeCapability(int device, int& major, int& minor);
\r
67 CV_EXPORTS int getNumberOfSMs(int device);
\r
69 CV_EXPORTS void getGpuMemInfo(size_t& free, size_t& total);
\r
71 CV_EXPORTS bool hasNativeDoubleSupport(int device);
\r
72 CV_EXPORTS bool hasAtomicsSupport(int device);
\r
74 //////////////////////////////// Error handling ////////////////////////
\r
76 CV_EXPORTS void error(const char *error_string, const char *file, const int line, const char *func);
\r
77 CV_EXPORTS void nppError( int err, const char *file, const int line, const char *func);
\r
79 //////////////////////////////// GpuMat ////////////////////////////////
\r
83 //! Smart pointer for GPU memory with reference counting. Its interface is mostly similar with cv::Mat.
\r
84 class CV_EXPORTS GpuMat
\r
87 //! default constructor
\r
89 //! constructs GpuMatrix of the specified size and type (_type is CV_8UC1, CV_64FC3, CV_32SC(12) etc.)
\r
90 GpuMat(int rows, int cols, int type);
\r
91 GpuMat(Size size, int type);
\r
92 //! constucts GpuMatrix and fills it with the specified value _s.
\r
93 GpuMat(int rows, int cols, int type, const Scalar& s);
\r
94 GpuMat(Size size, int type, const Scalar& s);
\r
95 //! copy constructor
\r
96 GpuMat(const GpuMat& m);
\r
98 //! constructor for GpuMatrix headers pointing to user-allocated data
\r
99 GpuMat(int rows, int cols, int type, void* data, size_t step = Mat::AUTO_STEP);
\r
100 GpuMat(Size size, int type, void* data, size_t step = Mat::AUTO_STEP);
\r
102 //! creates a matrix header for a part of the bigger matrix
\r
103 GpuMat(const GpuMat& m, const Range& rowRange, const Range& colRange);
\r
104 GpuMat(const GpuMat& m, const Rect& roi);
\r
106 //! builds GpuMat from Mat. Perfom blocking upload to device.
\r
107 explicit GpuMat (const Mat& m);
\r
109 //! destructor - calls release()
\r
112 //! assignment operators
\r
113 GpuMat& operator = (const GpuMat& m);
\r
114 //! assignment operator. Perfom blocking upload to device.
\r
115 GpuMat& operator = (const Mat& m);
\r
117 //! returns lightweight DevMem2D_ structure for passing to nvcc-compiled code.
\r
118 // Contains just image size, data ptr and step.
\r
119 template <class T> operator DevMem2D_<T>() const;
\r
120 template <class T> operator PtrStep_<T>() const;
\r
122 //! pefroms blocking upload data to GpuMat.
\r
123 void upload(const cv::Mat& m);
\r
126 void upload(const CudaMem& m, Stream& stream);
\r
128 //! downloads data from device to host memory. Blocking calls.
\r
129 operator Mat() const;
\r
130 void download(cv::Mat& m) const;
\r
133 void download(CudaMem& m, Stream& stream) const;
\r
135 //! returns a new GpuMatrix header for the specified row
\r
136 GpuMat row(int y) const;
\r
137 //! returns a new GpuMatrix header for the specified column
\r
138 GpuMat col(int x) const;
\r
139 //! ... for the specified row span
\r
140 GpuMat rowRange(int startrow, int endrow) const;
\r
141 GpuMat rowRange(const Range& r) const;
\r
142 //! ... for the specified column span
\r
143 GpuMat colRange(int startcol, int endcol) const;
\r
144 GpuMat colRange(const Range& r) const;
\r
146 //! returns deep copy of the GpuMatrix, i.e. the data is copied
\r
147 GpuMat clone() const;
\r
148 //! copies the GpuMatrix content to "m".
\r
149 // It calls m.create(this->size(), this->type()).
\r
150 void copyTo( GpuMat& m ) const;
\r
151 //! copies those GpuMatrix elements to "m" that are marked with non-zero mask elements.
\r
152 void copyTo( GpuMat& m, const GpuMat& mask ) const;
\r
153 //! converts GpuMatrix to another datatype with optional scalng. See cvConvertScale.
\r
154 void convertTo( GpuMat& m, int rtype, double alpha=1, double beta=0 ) const;
\r
156 void assignTo( GpuMat& m, int type=-1 ) const;
\r
158 //! sets every GpuMatrix element to s
\r
159 GpuMat& operator = (const Scalar& s);
\r
160 //! sets some of the GpuMatrix elements to s, according to the mask
\r
161 GpuMat& setTo(const Scalar& s, const GpuMat& mask = GpuMat());
\r
162 //! creates alternative GpuMatrix header for the same data, with different
\r
163 // number of channels and/or different number of rows. see cvReshape.
\r
164 GpuMat reshape(int cn, int rows = 0) const;
\r
166 //! allocates new GpuMatrix data unless the GpuMatrix already has specified size and type.
\r
167 // previous data is unreferenced if needed.
\r
168 void create(int rows, int cols, int type);
\r
169 void create(Size size, int type);
\r
170 //! decreases reference counter;
\r
171 // deallocate the data when reference counter reaches 0.
\r
174 //! swaps with other smart pointer
\r
175 void swap(GpuMat& mat);
\r
177 //! locates GpuMatrix header within a parent GpuMatrix. See below
\r
178 void locateROI( Size& wholeSize, Point& ofs ) const;
\r
179 //! moves/resizes the current GpuMatrix ROI inside the parent GpuMatrix.
\r
180 GpuMat& adjustROI( int dtop, int dbottom, int dleft, int dright );
\r
181 //! extracts a rectangular sub-GpuMatrix
\r
182 // (this is a generalized form of row, rowRange etc.)
\r
183 GpuMat operator()( Range rowRange, Range colRange ) const;
\r
184 GpuMat operator()( const Rect& roi ) const;
\r
186 //! returns true iff the GpuMatrix data is continuous
\r
187 // (i.e. when there are no gaps between successive rows).
\r
188 // similar to CV_IS_GpuMat_CONT(cvGpuMat->type)
\r
189 bool isContinuous() const;
\r
190 //! returns element size in bytes,
\r
191 // similar to CV_ELEM_SIZE(cvMat->type)
\r
192 size_t elemSize() const;
\r
193 //! returns the size of element channel in bytes.
\r
194 size_t elemSize1() const;
\r
195 //! returns element type, similar to CV_MAT_TYPE(cvMat->type)
\r
197 //! returns element type, similar to CV_MAT_DEPTH(cvMat->type)
\r
199 //! returns element type, similar to CV_MAT_CN(cvMat->type)
\r
200 int channels() const;
\r
201 //! returns step/elemSize1()
\r
202 size_t step1() const;
\r
203 //! returns GpuMatrix size:
\r
204 // width == number of columns, height == number of rows
\r
206 //! returns true if GpuMatrix data is NULL
\r
207 bool empty() const;
\r
209 //! returns pointer to y-th row
\r
210 uchar* ptr(int y = 0);
\r
211 const uchar* ptr(int y = 0) const;
\r
213 //! template version of the above method
\r
214 template<typename _Tp> _Tp* ptr(int y = 0);
\r
215 template<typename _Tp> const _Tp* ptr(int y = 0) const;
\r
217 //! matrix transposition
\r
220 /*! includes several bit-fields:
\r
221 - the magic signature
\r
224 - number of channels
\r
227 //! the number of rows and columns
\r
229 //! a distance between successive rows in bytes; includes the gap if any
\r
231 //! pointer to the data
\r
234 //! pointer to the reference counter;
\r
235 // when GpuMatrix points to user-allocated data, the pointer is NULL
\r
238 //! helper fields used in locateROI and adjustROI
\r
243 //#define TemplatedGpuMat // experimental now, deprecated to use
\r
244 #ifdef TemplatedGpuMat
\r
245 #include "GpuMat_BetaDeprecated.hpp"
\r
248 //////////////////////////////// CudaMem ////////////////////////////////
\r
249 // CudaMem is limited cv::Mat with page locked memory allocation.
\r
250 // Page locked memory is only needed for async and faster coping to GPU.
\r
251 // It is convertable to cv::Mat header without reference counting
\r
252 // so you can use it with other opencv functions.
\r
254 class CV_EXPORTS CudaMem
\r
257 enum { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2, ALLOC_WRITE_COMBINED = 4 };
\r
260 CudaMem(const CudaMem& m);
\r
262 CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED);
\r
263 CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
266 //! creates from cv::Mat with coping data
\r
267 explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);
\r
271 CudaMem& operator = (const CudaMem& m);
\r
273 //! returns deep copy of the matrix, i.e. the data is copied
\r
274 CudaMem clone() const;
\r
276 //! allocates new matrix data unless the matrix already has specified size and type.
\r
277 void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
278 void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
280 //! decrements reference counter and released memory if needed.
\r
283 //! returns matrix header with disabled reference counting for CudaMem data.
\r
284 Mat createMatHeader() const;
\r
285 operator Mat() const;
\r
287 //! maps host memory into device address space and returns GpuMat header for it. Throws exception if not supported by hardware.
\r
288 GpuMat createGpuMatHeader() const;
\r
289 operator GpuMat() const;
\r
291 //returns if host memory can be mapperd to gpu address space;
\r
292 static bool canMapHostMemory();
\r
294 // Please see cv::Mat for descriptions
\r
295 bool isContinuous() const;
\r
296 size_t elemSize() const;
\r
297 size_t elemSize1() const;
\r
300 int channels() const;
\r
301 size_t step1() const;
\r
303 bool empty() const;
\r
306 // Please see cv::Mat for descriptions
\r
320 //////////////////////////////// CudaStream ////////////////////////////////
\r
321 // Encapculates Cuda Stream. Provides interface for async coping.
\r
322 // Passed to each function that supports async kernel execution.
\r
323 // Reference counting is enabled
\r
325 class CV_EXPORTS Stream
\r
331 Stream(const Stream&);
\r
332 Stream& operator=(const Stream&);
\r
334 bool queryIfComplete();
\r
335 void waitForCompletion();
\r
337 //! downloads asynchronously.
\r
338 // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its subMat)
\r
339 void enqueueDownload(const GpuMat& src, CudaMem& dst);
\r
340 void enqueueDownload(const GpuMat& src, Mat& dst);
\r
342 //! uploads asynchronously.
\r
343 // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI)
\r
344 void enqueueUpload(const CudaMem& src, GpuMat& dst);
\r
345 void enqueueUpload(const Mat& src, GpuMat& dst);
\r
347 void enqueueCopy(const GpuMat& src, GpuMat& dst);
\r
349 void enqueueMemSet(const GpuMat& src, Scalar val);
\r
350 void enqueueMemSet(const GpuMat& src, Scalar val, const GpuMat& mask);
\r
352 // converts matrix type, ex from float to uchar depending on type
\r
353 void enqueueConvert(const GpuMat& src, GpuMat& dst, int type, double a = 1, double b = 0);
\r
359 friend struct StreamAccessor;
\r
362 ////////////////////////////// Arithmetics ///////////////////////////////////
\r
364 //! adds one matrix to another (c = a + b)
\r
365 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
366 CV_EXPORTS void add(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
367 //! adds scalar to a matrix (c = a + s)
\r
368 //! supports CV_32FC1 and CV_32FC2 type
\r
369 CV_EXPORTS void add(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
370 //! subtracts one matrix from another (c = a - b)
\r
371 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
372 CV_EXPORTS void subtract(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
373 //! subtracts scalar from a matrix (c = a - s)
\r
374 //! supports CV_32FC1 and CV_32FC2 type
\r
375 CV_EXPORTS void subtract(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
376 //! computes element-wise product of the two arrays (c = a * b)
\r
377 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
378 CV_EXPORTS void multiply(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
379 //! multiplies matrix to a scalar (c = a * s)
\r
380 //! supports CV_32FC1 and CV_32FC2 type
\r
381 CV_EXPORTS void multiply(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
382 //! computes element-wise quotient of the two arrays (c = a / b)
\r
383 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
384 CV_EXPORTS void divide(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
385 //! computes element-wise quotient of matrix and scalar (c = a / s)
\r
386 //! supports CV_32FC1 and CV_32FC2 type
\r
387 CV_EXPORTS void divide(const GpuMat& a, const Scalar& sc, GpuMat& c);
\r
389 //! transposes the matrix
\r
390 //! supports only CV_8UC1 type
\r
391 CV_EXPORTS void transpose(const GpuMat& src1, GpuMat& dst);
\r
393 //! computes element-wise absolute difference of two arrays (c = abs(a - b))
\r
394 //! supports CV_8UC1, CV_8UC4, CV_32SC1, CV_32FC1 types
\r
395 CV_EXPORTS void absdiff(const GpuMat& a, const GpuMat& b, GpuMat& c);
\r
396 //! computes element-wise absolute difference of array and scalar (c = abs(a - s))
\r
397 //! supports only CV_32FC1 type
\r
398 CV_EXPORTS void absdiff(const GpuMat& a, const Scalar& s, GpuMat& c);
\r
400 //! compares elements of two arrays (c = a <cmpop> b)
\r
401 //! supports CV_8UC4, CV_32FC1 types
\r
402 CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop);
\r
404 //! computes mean value and standard deviation of all or selected array elements
\r
405 //! supports only CV_8UC1 type
\r
406 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev);
\r
408 //! computes norm of array
\r
409 //! supports NORM_INF, NORM_L1, NORM_L2
\r
410 //! supports only CV_8UC1 type
\r
411 CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);
\r
413 //! computes norm of the difference between two arrays
\r
414 //! supports NORM_INF, NORM_L1, NORM_L2
\r
415 //! supports only CV_8UC1 type
\r
416 CV_EXPORTS double norm(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2);
\r
418 //! reverses the order of the rows, columns or both in a matrix
\r
419 //! supports CV_8UC1, CV_8UC4 types
\r
420 CV_EXPORTS void flip(const GpuMat& a, GpuMat& b, int flipCode);
\r
422 //! computes sum of array elements
\r
423 //! supports CV_8UC1, CV_8UC4 types
\r
424 //! disabled until fix crash
\r
425 CV_EXPORTS Scalar sum(const GpuMat& m);
\r
427 //! finds global minimum and maximum array elements and returns their values
\r
428 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat());
\r
430 //! finds global minimum and maximum array elements and returns their values
\r
431 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf);
\r
433 //! finds global minimum and maximum array elements and returns their values with locations
\r
434 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0,
\r
435 const GpuMat& mask=GpuMat());
\r
437 //! finds global minimum and maximum array elements and returns their values with locations
\r
438 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
\r
439 const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf);
\r
441 //! counts non-zero array elements
\r
442 CV_EXPORTS int countNonZero(const GpuMat& src);
\r
444 //! counts non-zero array elements
\r
445 CV_EXPORTS int countNonZero(const GpuMat& src, GpuMat& buf);
\r
447 //! transforms 8-bit unsigned integers using lookup table: dst(i)=lut(src(i))
\r
448 //! destination array will have the depth type as lut and the same channels number as source
\r
449 //! supports CV_8UC1, CV_8UC3 types
\r
450 CV_EXPORTS void LUT(const GpuMat& src, const Mat& lut, GpuMat& dst);
\r
452 //! makes multi-channel array out of several single-channel arrays
\r
453 CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst);
\r
455 //! makes multi-channel array out of several single-channel arrays
\r
456 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst);
\r
458 //! makes multi-channel array out of several single-channel arrays (async version)
\r
459 CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, const Stream& stream);
\r
461 //! makes multi-channel array out of several single-channel arrays (async version)
\r
462 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, const Stream& stream);
\r
464 //! copies each plane of a multi-channel array to a dedicated array
\r
465 CV_EXPORTS void split(const GpuMat& src, GpuMat* dst);
\r
467 //! copies each plane of a multi-channel array to a dedicated array
\r
468 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst);
\r
470 //! copies each plane of a multi-channel array to a dedicated array (async version)
\r
471 CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, const Stream& stream);
\r
473 //! copies each plane of a multi-channel array to a dedicated array (async version)
\r
474 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, const Stream& stream);
\r
476 //! computes exponent of each matrix element (b = e**a)
\r
477 //! supports only CV_32FC1 type
\r
478 CV_EXPORTS void exp(const GpuMat& a, GpuMat& b);
\r
480 //! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))
\r
481 //! supports only CV_32FC1 type
\r
482 CV_EXPORTS void log(const GpuMat& a, GpuMat& b);
\r
484 //! computes magnitude of complex (x(i).re, x(i).im) vector
\r
485 //! supports only CV_32FC2 type
\r
486 CV_EXPORTS void magnitude(const GpuMat& x, GpuMat& magnitude);
\r
488 //! computes squared magnitude of complex (x(i).re, x(i).im) vector
\r
489 //! supports only CV_32FC2 type
\r
490 CV_EXPORTS void magnitudeSqr(const GpuMat& x, GpuMat& magnitude);
\r
492 //! computes magnitude of each (x(i), y(i)) vector
\r
493 //! supports only floating-point source
\r
494 CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);
\r
496 CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);
\r
498 //! computes squared magnitude of each (x(i), y(i)) vector
\r
499 //! supports only floating-point source
\r
500 CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude);
\r
502 CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, const Stream& stream);
\r
504 //! computes angle (angle(i)) of each (x(i), y(i)) vector
\r
505 //! supports only floating-point source
\r
506 CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false);
\r
508 CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees, const Stream& stream);
\r
510 //! converts Cartesian coordinates to polar
\r
511 //! supports only floating-point source
\r
512 CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false);
\r
514 CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees, const Stream& stream);
\r
516 //! converts polar coordinates to Cartesian
\r
517 //! supports only floating-point source
\r
518 CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false);
\r
520 CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees, const Stream& stream);
\r
523 //! perfroms per-elements bit-wise inversion
\r
524 CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
526 CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
528 //! calculates per-element bit-wise disjunction of two arrays
\r
529 CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
531 CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
533 //! calculates per-element bit-wise conjunction of two arrays
\r
534 CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
536 CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
538 //! calculates per-element bit-wise "exclusive or" operation
\r
539 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat());
\r
541 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask, const Stream& stream);
\r
543 //! Logical operators
\r
544 CV_EXPORTS GpuMat operator ~ (const GpuMat& src);
\r
545 CV_EXPORTS GpuMat operator | (const GpuMat& src1, const GpuMat& src2);
\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
549 //! computes per-element minimum of two arrays (dst = min(src1, src2))
\r
550 CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst);
\r
552 CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream);
\r
554 //! computes per-element minimum of array and scalar (dst = min(src1, src2))
\r
555 CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst);
\r
557 CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst, const Stream& stream);
\r
559 //! computes per-element maximum of two arrays (dst = max(src1, src2))
\r
560 CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst);
\r
562 CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const Stream& stream);
\r
564 //! computes per-element maximum of array and scalar (dst = max(src1, src2))
\r
565 CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst);
\r
567 CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst, const Stream& stream);
\r
570 ////////////////////////////// Image processing //////////////////////////////
\r
572 //! DST[x,y] = SRC[xmap[x,y],ymap[x,y]] with bilinear interpolation.
\r
573 //! supports CV_8UC1, CV_8UC3 source types and CV_32FC1 map type
\r
574 CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap);
\r
576 //! Does mean shift filtering on GPU.
\r
577 CV_EXPORTS void meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr,
\r
578 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
\r
580 //! Does mean shift procedure on GPU.
\r
581 CV_EXPORTS void meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr,
\r
582 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
\r
584 //! Does mean shift segmentation with elimiation of small regions.
\r
585 CV_EXPORTS void meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize,
\r
586 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
\r
588 //! Does coloring of disparity image: [0..ndisp) -> [0..240, 1, 1] in HSV.
\r
589 //! Supported types of input disparity: CV_8U, CV_16S.
\r
590 //! Output disparity has CV_8UC4 type in BGRA format (alpha = 255).
\r
591 CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp);
\r
593 CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, const Stream& stream);
\r
595 //! Reprojects disparity image to 3D space.
\r
596 //! Supports CV_8U and CV_16S types of input disparity.
\r
597 //! The output is a 4-channel floating-point (CV_32FC4) matrix.
\r
598 //! Each element of this matrix will contain the 3D coordinates of the point (x,y,z,1), computed from the disparity map.
\r
599 //! Q is the 4x4 perspective transformation matrix that can be obtained with cvStereoRectify.
\r
600 CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q);
\r
602 CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, const Stream& stream);
\r
604 //! converts image from one color space to another
\r
605 CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0);
\r
607 CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn, const Stream& stream);
\r
609 //! applies fixed threshold to the image.
\r
610 //! Now supports only THRESH_TRUNC threshold type and one channels float source.
\r
611 CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh);
\r
613 //! resizes the image
\r
614 //! Supports INTER_NEAREST, INTER_LINEAR
\r
615 //! supports CV_8UC1, CV_8UC4 types
\r
616 CV_EXPORTS void resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR);
\r
618 //! warps the image using affine transformation
\r
619 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
620 CV_EXPORTS void warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR);
\r
622 //! warps the image using perspective transformation
\r
623 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
624 CV_EXPORTS void warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR);
\r
626 //! rotate 8bit single or four channel image
\r
627 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
628 //! supports CV_8UC1, CV_8UC4 types
\r
629 CV_EXPORTS void rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0, int interpolation = INTER_LINEAR);
\r
631 //! copies 2D array to a larger destination array and pads borders with user-specifiable constant
\r
632 //! supports CV_8UC1, CV_8UC4, CV_32SC1 types
\r
633 CV_EXPORTS void copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, const Scalar& value = Scalar());
\r
635 //! computes the integral image and integral for the squared image
\r
636 //! sum will have CV_32S type, sqsum - CV32F type
\r
637 //! supports only CV_8UC1 source type
\r
638 CV_EXPORTS void integral(GpuMat& src, GpuMat& sum, GpuMat& sqsum);
\r
640 //! computes the standard deviation of integral images
\r
641 //! supports only CV_32SC1 source type and CV_32FC1 sqr type
\r
642 //! output will have CV_32FC1 type
\r
643 CV_EXPORTS void rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect);
\r
645 //! applies Canny edge detector and produces the edge map
\r
646 //! supprots only CV_8UC1 source type
\r
647 //! disabled until fix crash
\r
648 CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double threshold1, double threshold2, int apertureSize = 3);
\r
650 //! computes Harris cornerness criteria at each image pixel
\r
651 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType=BORDER_REFLECT101);
\r
654 //! computes minimum eigen value of 2x2 derivative covariation matrix at each pixel - the cornerness criteria
\r
655 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
\r
658 //////////////////////////////// Filter Engine ////////////////////////////////
\r
661 The Base Class for 1D or Row-wise Filters
\r
663 This is the base class for linear or non-linear filters that process 1D data.
\r
664 In particular, such filters are used for the "horizontal" filtering parts in separable filters.
\r
666 class CV_EXPORTS BaseRowFilter_GPU
\r
669 BaseRowFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
670 virtual ~BaseRowFilter_GPU() {}
\r
671 virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;
\r
676 The Base Class for Column-wise Filters
\r
678 This is the base class for linear or non-linear filters that process columns of 2D arrays.
\r
679 Such filters are used for the "vertical" filtering parts in separable filters.
\r
681 class CV_EXPORTS BaseColumnFilter_GPU
\r
684 BaseColumnFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
685 virtual ~BaseColumnFilter_GPU() {}
\r
686 virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;
\r
691 The Base Class for Non-Separable 2D Filters.
\r
693 This is the base class for linear or non-linear 2D filters.
\r
695 class CV_EXPORTS BaseFilter_GPU
\r
698 BaseFilter_GPU(const Size& ksize_, const Point& anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
699 virtual ~BaseFilter_GPU() {}
\r
700 virtual void operator()(const GpuMat& src, GpuMat& dst) = 0;
\r
706 The Base Class for Filter Engine.
\r
708 The class can be used to apply an arbitrary filtering operation to an image.
\r
709 It contains all the necessary intermediate buffers.
\r
711 class CV_EXPORTS FilterEngine_GPU
\r
714 virtual ~FilterEngine_GPU() {}
\r
716 virtual void apply(const GpuMat& src, GpuMat& dst, Rect roi = Rect(0,0,-1,-1)) = 0;
\r
719 //! returns the non-separable filter engine with the specified filter
\r
720 CV_EXPORTS Ptr<FilterEngine_GPU> createFilter2D_GPU(const Ptr<BaseFilter_GPU> filter2D);
\r
722 //! returns the separable filter engine with the specified filters
\r
723 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>& rowFilter,
\r
724 const Ptr<BaseColumnFilter_GPU>& columnFilter);
\r
726 //! returns horizontal 1D box filter
\r
727 //! supports only CV_8UC1 source type and CV_32FC1 sum type
\r
728 CV_EXPORTS Ptr<BaseRowFilter_GPU> getRowSumFilter_GPU(int srcType, int sumType, int ksize, int anchor = -1);
\r
730 //! returns vertical 1D box filter
\r
731 //! supports only CV_8UC1 sum type and CV_32FC1 dst type
\r
732 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getColumnSumFilter_GPU(int sumType, int dstType, int ksize, int anchor = -1);
\r
734 //! returns 2D box filter
\r
735 //! supports CV_8UC1 and CV_8UC4 source type, dst type must be the same as source type
\r
736 CV_EXPORTS Ptr<BaseFilter_GPU> getBoxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1, -1));
\r
738 //! returns box filter engine
\r
739 CV_EXPORTS Ptr<FilterEngine_GPU> createBoxFilter_GPU(int srcType, int dstType, const Size& ksize,
\r
740 const Point& anchor = Point(-1,-1));
\r
742 //! returns 2D morphological filter
\r
743 //! only MORPH_ERODE and MORPH_DILATE are supported
\r
744 //! supports CV_8UC1 and CV_8UC4 types
\r
745 //! kernel must have CV_8UC1 type, one rows and cols == ksize.width * ksize.height
\r
746 CV_EXPORTS Ptr<BaseFilter_GPU> getMorphologyFilter_GPU(int op, int type, const Mat& kernel, const Size& ksize,
\r
747 Point anchor=Point(-1,-1));
\r
749 //! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported.
\r
750 CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat& kernel,
\r
751 const Point& anchor = Point(-1,-1), int iterations = 1);
\r
753 //! returns 2D filter with the specified kernel
\r
754 //! supports CV_8UC1 and CV_8UC4 types
\r
755 CV_EXPORTS Ptr<BaseFilter_GPU> getLinearFilter_GPU(int srcType, int dstType, const Mat& kernel, const Size& ksize,
\r
756 Point anchor = Point(-1, -1));
\r
758 //! returns the non-separable linear filter engine
\r
759 CV_EXPORTS Ptr<FilterEngine_GPU> createLinearFilter_GPU(int srcType, int dstType, const Mat& kernel,
\r
760 const Point& anchor = Point(-1,-1));
\r
762 //! returns the primitive row filter with the specified kernel
\r
763 CV_EXPORTS Ptr<BaseRowFilter_GPU> getLinearRowFilter_GPU(int srcType, int bufType, const Mat& rowKernel,
\r
766 //! returns the primitive column filter with the specified kernel
\r
767 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getLinearColumnFilter_GPU(int bufType, int dstType, const Mat& columnKernel,
\r
770 //! returns the separable linear filter engine
\r
771 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel,
\r
772 const Mat& columnKernel, const Point& anchor = Point(-1,-1));
\r
774 //! returns filter engine for the generalized Sobel operator
\r
775 CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize);
\r
777 //! returns the Gaussian filter engine
\r
778 CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, double sigma1, double sigma2 = 0);
\r
780 //! returns maximum filter
\r
781 CV_EXPORTS Ptr<BaseFilter_GPU> getMaxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
\r
783 //! returns minimum filter
\r
784 CV_EXPORTS Ptr<BaseFilter_GPU> getMinFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
\r
786 //! smooths the image using the normalized box filter
\r
787 //! supports CV_8UC1, CV_8UC4 types
\r
788 CV_EXPORTS void boxFilter(const GpuMat& src, GpuMat& dst, int ddepth, Size ksize, Point anchor = Point(-1,-1));
\r
790 //! a synonym for normalized box filter
\r
791 static inline void blur(const GpuMat& src, GpuMat& dst, Size ksize, Point anchor = Point(-1,-1)) { boxFilter(src, dst, -1, ksize, anchor); }
\r
793 //! erodes the image (applies the local minimum operator)
\r
794 CV_EXPORTS void erode( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
796 //! dilates the image (applies the local maximum operator)
\r
797 CV_EXPORTS void dilate( const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
799 //! applies an advanced morphological operation to the image
\r
800 CV_EXPORTS void morphologyEx( const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
802 //! applies non-separable 2D linear filter to the image
\r
803 CV_EXPORTS void filter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernel, Point anchor=Point(-1,-1));
\r
805 //! applies separable 2D linear filter to the image
\r
806 CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY,
\r
807 Point anchor = Point(-1,-1));
\r
809 //! applies generalized Sobel operator to the image
\r
810 CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1);
\r
812 //! applies the vertical or horizontal Scharr operator to the image
\r
813 CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, double scale = 1);
\r
815 //! smooths the image using Gaussian filter.
\r
816 CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, double sigma1, double sigma2 = 0);
\r
818 //! applies Laplacian operator to the image
\r
819 //! supports only ksize = 1 and ksize = 3
\r
820 CV_EXPORTS void Laplacian(const GpuMat& src, GpuMat& dst, int ddepth, int ksize = 1, double scale = 1);
\r
822 //////////////////////////////// Image Labeling ////////////////////////////////
\r
824 //!performs labeling via graph cuts
\r
825 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels, GpuMat& buf);
\r
827 ////////////////////////////////// Histograms //////////////////////////////////
\r
829 //! Compute levels with even distribution. levels will have 1 row and nLevels cols and CV_32SC1 type.
\r
830 CV_EXPORTS void evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel);
\r
831 //! Calculates histogram with evenly distributed bins for signle channel source.
\r
832 //! Supports CV_8UC1, CV_16UC1 and CV_16SC1 source types.
\r
833 //! Output hist will have one row and histSize cols and CV_32SC1 type.
\r
834 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel);
\r
835 //! Calculates histogram with evenly distributed bins for four-channel source.
\r
836 //! All channels of source are processed separately.
\r
837 //! Supports CV_8UC4, CV_16UC4 and CV_16SC4 source types.
\r
838 //! Output hist[i] will have one row and histSize[i] cols and CV_32SC1 type.
\r
839 CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4]);
\r
840 //! Calculates histogram with bins determined by levels array.
\r
841 //! levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
842 //! Supports CV_8UC1, CV_16UC1, CV_16SC1 and CV_32FC1 source types.
\r
843 //! Output hist will have one row and (levels.cols-1) cols and CV_32SC1 type.
\r
844 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels);
\r
845 //! Calculates histogram with bins determined by levels array.
\r
846 //! All levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
847 //! All channels of source are processed separately.
\r
848 //! Supports CV_8UC4, CV_16UC4, CV_16SC4 and CV_32FC4 source types.
\r
849 //! Output hist[i] will have one row and (levels[i].cols-1) cols and CV_32SC1 type.
\r
850 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4]);
\r
852 //////////////////////////////// StereoBM_GPU ////////////////////////////////
\r
854 class CV_EXPORTS StereoBM_GPU
\r
857 enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 };
\r
859 enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 };
\r
861 //! the default constructor
\r
863 //! the full constructor taking the camera-specific preset, number of disparities and the SAD window size. ndisparities must be multiple of 8.
\r
864 StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ);
\r
866 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair
\r
867 //! Output disparity has CV_8U type.
\r
868 void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity);
\r
871 void operator() ( const GpuMat& left, const GpuMat& right, GpuMat& disparity, const Stream & stream);
\r
873 //! Some heuristics that tries to estmate
\r
874 // if current GPU will be faster then CPU in this algorithm.
\r
875 // It queries current active device.
\r
876 static bool checkIfGpuCallReasonable();
\r
882 // If avergeTexThreshold == 0 => post procesing is disabled
\r
883 // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image
\r
884 // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold
\r
885 // i.e. input left image is low textured.
\r
886 float avergeTexThreshold;
\r
888 GpuMat minSSD, leBuf, riBuf;
\r
891 ////////////////////////// StereoBeliefPropagation ///////////////////////////
\r
892 // "Efficient Belief Propagation for Early Vision"
\r
895 class CV_EXPORTS StereoBeliefPropagation
\r
898 enum { DEFAULT_NDISP = 64 };
\r
899 enum { DEFAULT_ITERS = 5 };
\r
900 enum { DEFAULT_LEVELS = 5 };
\r
902 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels);
\r
904 //! the default constructor
\r
905 explicit StereoBeliefPropagation(int ndisp = DEFAULT_NDISP,
\r
906 int iters = DEFAULT_ITERS,
\r
907 int levels = DEFAULT_LEVELS,
\r
908 int msg_type = CV_32F);
\r
910 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
911 //! number of levels, truncation of data cost, data weight,
\r
912 //! truncation of discontinuity cost and discontinuity single jump
\r
913 //! DataTerm = data_weight * min(fabs(I2-I1), max_data_term)
\r
914 //! DiscTerm = min(disc_single_jump * fabs(f1-f2), max_disc_term)
\r
915 //! please see paper for more details
\r
916 StereoBeliefPropagation(int ndisp, int iters, int levels,
\r
917 float max_data_term, float data_weight,
\r
918 float max_disc_term, float disc_single_jump,
\r
919 int msg_type = CV_32F);
\r
921 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
922 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
923 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);
\r
926 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);
\r
929 //! version for user specified data term
\r
930 void operator()(const GpuMat& data, GpuMat& disparity);
\r
931 void operator()(const GpuMat& data, GpuMat& disparity, Stream& stream);
\r
938 float max_data_term;
\r
940 float max_disc_term;
\r
941 float disc_single_jump;
\r
945 GpuMat u, d, l, r, u2, d2, l2, r2;
\r
946 std::vector<GpuMat> datas;
\r
950 /////////////////////////// StereoConstantSpaceBP ///////////////////////////
\r
951 // "A Constant-Space Belief Propagation Algorithm for Stereo Matching"
\r
952 // Qingxiong Yang, Liang Wang
\86, Narendra Ahuja
\r
953 // http://vision.ai.uiuc.edu/~qyang6/
\r
955 class CV_EXPORTS StereoConstantSpaceBP
\r
958 enum { DEFAULT_NDISP = 128 };
\r
959 enum { DEFAULT_ITERS = 8 };
\r
960 enum { DEFAULT_LEVELS = 4 };
\r
961 enum { DEFAULT_NR_PLANE = 4 };
\r
963 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane);
\r
965 //! the default constructor
\r
966 explicit StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP,
\r
967 int iters = DEFAULT_ITERS,
\r
968 int levels = DEFAULT_LEVELS,
\r
969 int nr_plane = DEFAULT_NR_PLANE,
\r
970 int msg_type = CV_32F);
\r
972 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
973 //! number of levels, number of active disparity on the first level, truncation of data cost, data weight,
\r
974 //! truncation of discontinuity cost, discontinuity single jump and minimum disparity threshold
\r
975 StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,
\r
976 float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,
\r
977 int min_disp_th = 0,
\r
978 int msg_type = CV_32F);
\r
980 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
981 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
982 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity);
\r
985 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream);
\r
994 float max_data_term;
\r
996 float max_disc_term;
\r
997 float disc_single_jump;
\r
1003 bool use_local_init_data_cost;
\r
1005 GpuMat u[2], d[2], l[2], r[2];
\r
1006 GpuMat disp_selected_pyr[2];
\r
1009 GpuMat data_cost_selected;
\r
1016 /////////////////////////// DisparityBilateralFilter ///////////////////////////
\r
1017 // Disparity map refinement using joint bilateral filtering given a single color image.
\r
1018 // Qingxiong Yang, Liang Wang
\86, Narendra Ahuja
\r
1019 // http://vision.ai.uiuc.edu/~qyang6/
\r
1021 class CV_EXPORTS DisparityBilateralFilter
\r
1024 enum { DEFAULT_NDISP = 64 };
\r
1025 enum { DEFAULT_RADIUS = 3 };
\r
1026 enum { DEFAULT_ITERS = 1 };
\r
1028 //! the default constructor
\r
1029 explicit DisparityBilateralFilter(int ndisp = DEFAULT_NDISP, int radius = DEFAULT_RADIUS, int iters = DEFAULT_ITERS);
\r
1031 //! the full constructor taking the number of disparities, filter radius,
\r
1032 //! number of iterations, truncation of data continuity, truncation of disparity continuity
\r
1033 //! and filter range sigma
\r
1034 DisparityBilateralFilter(int ndisp, int radius, int iters, float edge_threshold, float max_disc_threshold, float sigma_range);
\r
1036 //! the disparity map refinement operator. Refine disparity map using joint bilateral filtering given a single color image.
\r
1037 //! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type.
\r
1038 void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst);
\r
1041 void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream);
\r
1048 float edge_threshold;
\r
1049 float max_disc_threshold;
\r
1050 float sigma_range;
\r
1052 GpuMat table_color;
\r
1053 GpuMat table_space;
\r
1057 //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
\r
1059 struct CV_EXPORTS HOGDescriptor
\r
1062 enum { DEFAULT_WIN_SIGMA = -1 };
\r
1063 enum { DEFAULT_NLEVELS = 64 };
\r
1064 enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
\r
1066 HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16),
\r
1067 Size block_stride=Size(8, 8), Size cell_size=Size(8, 8),
\r
1068 int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA,
\r
1069 double threshold_L2hys=0.2, bool gamma_correction=true,
\r
1070 int nlevels=DEFAULT_NLEVELS);
\r
1072 size_t getDescriptorSize() const;
\r
1073 size_t getBlockHistogramSize() const;
\r
1074 double getWinSigma() const;
\r
1076 static vector<float> getDefaultPeopleDetector();
\r
1077 static vector<float> getPeopleDetector_48x96();
\r
1078 static vector<float> getPeopleDetector_64x128();
\r
1079 void setSVMDetector(const vector<float>& detector);
\r
1080 bool checkDetectorSize() const;
\r
1082 void detect(const GpuMat& img, vector<Point>& found_locations, double hit_threshold=0,
\r
1083 Size win_stride=Size(), Size padding=Size());
\r
1084 void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
\r
1085 double hit_threshold=0, Size win_stride=Size(), Size padding=Size(),
\r
1086 double scale0=1.05, int group_threshold=2);
\r
1088 void getDescriptors(const GpuMat& img, Size win_stride, GpuMat& descriptors,
\r
1089 int descr_format=DESCR_FORMAT_COL_BY_COL);
\r
1093 Size block_stride;
\r
1097 double threshold_L2hys;
\r
1099 bool gamma_correction;
\r
1102 void computeBlockHistograms(const GpuMat& img);
\r
1103 void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle);
\r
1105 static int numPartsWithin(int size, int part_size, int stride);
\r
1106 static Size numPartsWithin(Size size, Size part_size, Size stride);
\r
1108 // Coefficients of the separating plane
\r
1112 // Results of the last classification step
\r
1116 // Results of the last histogram evaluation step
\r
1117 GpuMat block_hists;
\r
1119 // Gradients conputation results
\r
1120 GpuMat grad, qangle;
\r
1125 //! Speckle filtering - filters small connected components on diparity image.
\r
1126 //! It sets pixel (x,y) to newVal if it coresponds to small CC with size < maxSpeckleSize.
\r
1127 //! Threshold for border between CC is diffThreshold;
\r
1128 CV_EXPORTS void filterSpeckles( Mat& img, uchar newVal, int maxSpeckleSize, uchar diffThreshold, Mat& buf);
\r
1131 #include "opencv2/gpu/matrix_operations.hpp"
\r
1133 #endif /* __OPENCV_GPU_HPP__ */
\r