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
46 #ifndef SKIP_INCLUDES
\r
52 #include "opencv2/core/gpumat.hpp"
\r
53 #include "opencv2/imgproc/imgproc.hpp"
\r
54 #include "opencv2/objdetect/objdetect.hpp"
\r
55 #include "opencv2/features2d/features2d.hpp"
\r
57 namespace cv { namespace gpu {
\r
59 //////////////////////////////// CudaMem ////////////////////////////////
\r
60 // CudaMem is limited cv::Mat with page locked memory allocation.
\r
61 // Page locked memory is only needed for async and faster coping to GPU.
\r
62 // It is convertable to cv::Mat header without reference counting
\r
63 // so you can use it with other opencv functions.
\r
65 // Page-locks the matrix m memory and maps it for the device(s)
\r
66 CV_EXPORTS void registerPageLocked(Mat& m);
\r
67 // Unmaps the memory of matrix m, and makes it pageable again.
\r
68 CV_EXPORTS void unregisterPageLocked(Mat& m);
\r
70 class CV_EXPORTS CudaMem
\r
73 enum { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2, ALLOC_WRITE_COMBINED = 4 };
\r
76 CudaMem(const CudaMem& m);
\r
78 CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED);
\r
79 CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
82 //! creates from cv::Mat with coping data
\r
83 explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);
\r
87 CudaMem& operator = (const CudaMem& m);
\r
89 //! returns deep copy of the matrix, i.e. the data is copied
\r
90 CudaMem clone() const;
\r
92 //! allocates new matrix data unless the matrix already has specified size and type.
\r
93 void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
94 void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
\r
96 //! decrements reference counter and released memory if needed.
\r
99 //! returns matrix header with disabled reference counting for CudaMem data.
\r
100 Mat createMatHeader() const;
\r
101 operator Mat() const;
\r
103 //! maps host memory into device address space and returns GpuMat header for it. Throws exception if not supported by hardware.
\r
104 GpuMat createGpuMatHeader() const;
\r
105 operator GpuMat() const;
\r
107 //returns if host memory can be mapperd to gpu address space;
\r
108 static bool canMapHostMemory();
\r
110 // Please see cv::Mat for descriptions
\r
111 bool isContinuous() const;
\r
112 size_t elemSize() const;
\r
113 size_t elemSize1() const;
\r
116 int channels() const;
\r
117 size_t step1() const;
\r
119 bool empty() const;
\r
122 // Please see cv::Mat for descriptions
\r
136 //////////////////////////////// CudaStream ////////////////////////////////
\r
137 // Encapculates Cuda Stream. Provides interface for async coping.
\r
138 // Passed to each function that supports async kernel execution.
\r
139 // Reference counting is enabled
\r
141 class CV_EXPORTS Stream
\r
147 Stream(const Stream&);
\r
148 Stream& operator=(const Stream&);
\r
150 bool queryIfComplete();
\r
151 void waitForCompletion();
\r
153 //! downloads asynchronously.
\r
154 // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its subMat)
\r
155 void enqueueDownload(const GpuMat& src, CudaMem& dst);
\r
156 void enqueueDownload(const GpuMat& src, Mat& dst);
\r
158 //! uploads asynchronously.
\r
159 // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI)
\r
160 void enqueueUpload(const CudaMem& src, GpuMat& dst);
\r
161 void enqueueUpload(const Mat& src, GpuMat& dst);
\r
163 void enqueueCopy(const GpuMat& src, GpuMat& dst);
\r
165 void enqueueMemSet(GpuMat& src, Scalar val);
\r
166 void enqueueMemSet(GpuMat& src, Scalar val, const GpuMat& mask);
\r
168 // converts matrix type, ex from float to uchar depending on type
\r
169 void enqueueConvert(const GpuMat& src, GpuMat& dst, int type, double a = 1, double b = 0);
\r
171 static Stream& Null();
\r
173 operator bool() const;
\r
182 friend struct StreamAccessor;
\r
184 explicit Stream(Impl* impl);
\r
188 //////////////////////////////// Filter Engine ////////////////////////////////
\r
191 The Base Class for 1D or Row-wise Filters
\r
193 This is the base class for linear or non-linear filters that process 1D data.
\r
194 In particular, such filters are used for the "horizontal" filtering parts in separable filters.
\r
196 class CV_EXPORTS BaseRowFilter_GPU
\r
199 BaseRowFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
200 virtual ~BaseRowFilter_GPU() {}
\r
201 virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
\r
206 The Base Class for Column-wise Filters
\r
208 This is the base class for linear or non-linear filters that process columns of 2D arrays.
\r
209 Such filters are used for the "vertical" filtering parts in separable filters.
\r
211 class CV_EXPORTS BaseColumnFilter_GPU
\r
214 BaseColumnFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
215 virtual ~BaseColumnFilter_GPU() {}
\r
216 virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
\r
221 The Base Class for Non-Separable 2D Filters.
\r
223 This is the base class for linear or non-linear 2D filters.
\r
225 class CV_EXPORTS BaseFilter_GPU
\r
228 BaseFilter_GPU(const Size& ksize_, const Point& anchor_) : ksize(ksize_), anchor(anchor_) {}
\r
229 virtual ~BaseFilter_GPU() {}
\r
230 virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
\r
236 The Base Class for Filter Engine.
\r
238 The class can be used to apply an arbitrary filtering operation to an image.
\r
239 It contains all the necessary intermediate buffers.
\r
241 class CV_EXPORTS FilterEngine_GPU
\r
244 virtual ~FilterEngine_GPU() {}
\r
246 virtual void apply(const GpuMat& src, GpuMat& dst, Rect roi = Rect(0,0,-1,-1), Stream& stream = Stream::Null()) = 0;
\r
249 //! returns the non-separable filter engine with the specified filter
\r
250 CV_EXPORTS Ptr<FilterEngine_GPU> createFilter2D_GPU(const Ptr<BaseFilter_GPU>& filter2D, int srcType, int dstType);
\r
252 //! returns the separable filter engine with the specified filters
\r
253 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>& rowFilter,
\r
254 const Ptr<BaseColumnFilter_GPU>& columnFilter, int srcType, int bufType, int dstType);
\r
255 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>& rowFilter,
\r
256 const Ptr<BaseColumnFilter_GPU>& columnFilter, int srcType, int bufType, int dstType, GpuMat& buf);
\r
258 //! returns horizontal 1D box filter
\r
259 //! supports only CV_8UC1 source type and CV_32FC1 sum type
\r
260 CV_EXPORTS Ptr<BaseRowFilter_GPU> getRowSumFilter_GPU(int srcType, int sumType, int ksize, int anchor = -1);
\r
262 //! returns vertical 1D box filter
\r
263 //! supports only CV_8UC1 sum type and CV_32FC1 dst type
\r
264 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getColumnSumFilter_GPU(int sumType, int dstType, int ksize, int anchor = -1);
\r
266 //! returns 2D box filter
\r
267 //! supports CV_8UC1 and CV_8UC4 source type, dst type must be the same as source type
\r
268 CV_EXPORTS Ptr<BaseFilter_GPU> getBoxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1, -1));
\r
270 //! returns box filter engine
\r
271 CV_EXPORTS Ptr<FilterEngine_GPU> createBoxFilter_GPU(int srcType, int dstType, const Size& ksize,
\r
272 const Point& anchor = Point(-1,-1));
\r
274 //! returns 2D morphological filter
\r
275 //! only MORPH_ERODE and MORPH_DILATE are supported
\r
276 //! supports CV_8UC1 and CV_8UC4 types
\r
277 //! kernel must have CV_8UC1 type, one rows and cols == ksize.width * ksize.height
\r
278 CV_EXPORTS Ptr<BaseFilter_GPU> getMorphologyFilter_GPU(int op, int type, const Mat& kernel, const Size& ksize,
\r
279 Point anchor=Point(-1,-1));
\r
281 //! returns morphological filter engine. Only MORPH_ERODE and MORPH_DILATE are supported.
\r
282 CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat& kernel,
\r
283 const Point& anchor = Point(-1,-1), int iterations = 1);
\r
284 CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat& kernel, GpuMat& buf,
\r
285 const Point& anchor = Point(-1,-1), int iterations = 1);
\r
287 //! returns 2D filter with the specified kernel
\r
288 //! supports CV_8U, CV_16U and CV_32F one and four channel image
\r
289 CV_EXPORTS Ptr<BaseFilter_GPU> getLinearFilter_GPU(int srcType, int dstType, const Mat& kernel, Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
\r
291 //! returns the non-separable linear filter engine
\r
292 CV_EXPORTS Ptr<FilterEngine_GPU> createLinearFilter_GPU(int srcType, int dstType, const Mat& kernel,
\r
293 Point anchor = Point(-1,-1), int borderType = BORDER_DEFAULT);
\r
295 //! returns the primitive row filter with the specified kernel.
\r
296 //! supports only CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 source type.
\r
297 //! there are two version of algorithm: NPP and OpenCV.
\r
298 //! NPP calls when srcType == CV_8UC1 or srcType == CV_8UC4 and bufType == srcType,
\r
299 //! otherwise calls OpenCV version.
\r
300 //! NPP supports only BORDER_CONSTANT border type.
\r
301 //! OpenCV version supports only CV_32F as buffer depth and
\r
302 //! BORDER_REFLECT101, BORDER_REPLICATE and BORDER_CONSTANT border types.
\r
303 CV_EXPORTS Ptr<BaseRowFilter_GPU> getLinearRowFilter_GPU(int srcType, int bufType, const Mat& rowKernel,
\r
304 int anchor = -1, int borderType = BORDER_DEFAULT);
\r
306 //! returns the primitive column filter with the specified kernel.
\r
307 //! supports only CV_8UC1, CV_8UC4, CV_16SC1, CV_16SC2, CV_32SC1, CV_32FC1 dst type.
\r
308 //! there are two version of algorithm: NPP and OpenCV.
\r
309 //! NPP calls when dstType == CV_8UC1 or dstType == CV_8UC4 and bufType == dstType,
\r
310 //! otherwise calls OpenCV version.
\r
311 //! NPP supports only BORDER_CONSTANT border type.
\r
312 //! OpenCV version supports only CV_32F as buffer depth and
\r
313 //! BORDER_REFLECT101, BORDER_REPLICATE and BORDER_CONSTANT border types.
\r
314 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getLinearColumnFilter_GPU(int bufType, int dstType, const Mat& columnKernel,
\r
315 int anchor = -1, int borderType = BORDER_DEFAULT);
\r
317 //! returns the separable linear filter engine
\r
318 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel,
\r
319 const Mat& columnKernel, const Point& anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT,
\r
320 int columnBorderType = -1);
\r
321 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel,
\r
322 const Mat& columnKernel, GpuMat& buf, const Point& anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT,
\r
323 int columnBorderType = -1);
\r
325 //! returns filter engine for the generalized Sobel operator
\r
326 CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize,
\r
327 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
328 CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize, GpuMat& buf,
\r
329 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
331 //! returns the Gaussian filter engine
\r
332 CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, double sigma1, double sigma2 = 0,
\r
333 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
334 CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, GpuMat& buf, double sigma1, double sigma2 = 0,
\r
335 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
337 //! returns maximum filter
\r
338 CV_EXPORTS Ptr<BaseFilter_GPU> getMaxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
\r
340 //! returns minimum filter
\r
341 CV_EXPORTS Ptr<BaseFilter_GPU> getMinFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
\r
343 //! smooths the image using the normalized box filter
\r
344 //! supports CV_8UC1, CV_8UC4 types
\r
345 CV_EXPORTS void boxFilter(const GpuMat& src, GpuMat& dst, int ddepth, Size ksize, Point anchor = Point(-1,-1), Stream& stream = Stream::Null());
\r
347 //! a synonym for normalized box filter
\r
348 static inline void blur(const GpuMat& src, GpuMat& dst, Size ksize, Point anchor = Point(-1,-1), Stream& stream = Stream::Null())
\r
350 boxFilter(src, dst, -1, ksize, anchor, stream);
\r
353 //! erodes the image (applies the local minimum operator)
\r
354 CV_EXPORTS void erode(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
355 CV_EXPORTS void erode(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf,
\r
356 Point anchor = Point(-1, -1), int iterations = 1,
\r
357 Stream& stream = Stream::Null());
\r
359 //! dilates the image (applies the local maximum operator)
\r
360 CV_EXPORTS void dilate(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
361 CV_EXPORTS void dilate(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf,
\r
362 Point anchor = Point(-1, -1), int iterations = 1,
\r
363 Stream& stream = Stream::Null());
\r
365 //! applies an advanced morphological operation to the image
\r
366 CV_EXPORTS void morphologyEx(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
\r
367 CV_EXPORTS void morphologyEx(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, GpuMat& buf1, GpuMat& buf2,
\r
368 Point anchor = Point(-1, -1), int iterations = 1, Stream& stream = Stream::Null());
\r
370 //! applies non-separable 2D linear filter to the image
\r
371 CV_EXPORTS void filter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernel, Point anchor=Point(-1,-1), int borderType = BORDER_DEFAULT, Stream& stream = Stream::Null());
\r
373 //! applies separable 2D linear filter to the image
\r
374 CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY,
\r
375 Point anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
376 CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY, GpuMat& buf,
\r
377 Point anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1,
\r
378 Stream& stream = Stream::Null());
\r
380 //! applies generalized Sobel operator to the image
\r
381 CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1,
\r
382 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
383 CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, int ksize = 3, double scale = 1,
\r
384 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null());
\r
386 //! applies the vertical or horizontal Scharr operator to the image
\r
387 CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, double scale = 1,
\r
388 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
389 CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, double scale = 1,
\r
390 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null());
\r
392 //! smooths the image using Gaussian filter.
\r
393 CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, double sigma1, double sigma2 = 0,
\r
394 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
\r
395 CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, GpuMat& buf, double sigma1, double sigma2 = 0,
\r
396 int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null());
\r
398 //! applies Laplacian operator to the image
\r
399 //! supports only ksize = 1 and ksize = 3
\r
400 CV_EXPORTS void Laplacian(const GpuMat& src, GpuMat& dst, int ddepth, int ksize = 1, double scale = 1, int borderType = BORDER_DEFAULT, Stream& stream = Stream::Null());
\r
403 ////////////////////////////// Arithmetics ///////////////////////////////////
\r
405 //! implements generalized matrix product algorithm GEMM from BLAS
\r
406 CV_EXPORTS void gemm(const GpuMat& src1, const GpuMat& src2, double alpha,
\r
407 const GpuMat& src3, double beta, GpuMat& dst, int flags = 0, Stream& stream = Stream::Null());
\r
409 //! transposes the matrix
\r
410 //! supports matrix with element size = 1, 4 and 8 bytes (CV_8UC1, CV_8UC4, CV_16UC2, CV_32FC1, etc)
\r
411 CV_EXPORTS void transpose(const GpuMat& src1, GpuMat& dst, Stream& stream = Stream::Null());
\r
413 //! reverses the order of the rows, columns or both in a matrix
\r
414 //! supports 1, 3 and 4 channels images with CV_8U, CV_16U, CV_32S or CV_32F depth
\r
415 CV_EXPORTS void flip(const GpuMat& a, GpuMat& b, int flipCode, Stream& stream = Stream::Null());
\r
417 //! transforms 8-bit unsigned integers using lookup table: dst(i)=lut(src(i))
\r
418 //! destination array will have the depth type as lut and the same channels number as source
\r
419 //! supports CV_8UC1, CV_8UC3 types
\r
420 CV_EXPORTS void LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& stream = Stream::Null());
\r
422 //! makes multi-channel array out of several single-channel arrays
\r
423 CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream = Stream::Null());
\r
425 //! makes multi-channel array out of several single-channel arrays
\r
426 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
428 //! copies each plane of a multi-channel array to a dedicated array
\r
429 CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::Null());
\r
431 //! copies each plane of a multi-channel array to a dedicated array
\r
432 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, Stream& stream = Stream::Null());
\r
434 //! computes magnitude of complex (x(i).re, x(i).im) vector
\r
435 //! supports only CV_32FC2 type
\r
436 CV_EXPORTS void magnitude(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null());
\r
438 //! computes squared magnitude of complex (x(i).re, x(i).im) vector
\r
439 //! supports only CV_32FC2 type
\r
440 CV_EXPORTS void magnitudeSqr(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null());
\r
442 //! computes magnitude of each (x(i), y(i)) vector
\r
443 //! supports only floating-point source
\r
444 CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null());
\r
446 //! computes squared magnitude of each (x(i), y(i)) vector
\r
447 //! supports only floating-point source
\r
448 CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null());
\r
450 //! computes angle (angle(i)) of each (x(i), y(i)) vector
\r
451 //! supports only floating-point source
\r
452 CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
\r
454 //! converts Cartesian coordinates to polar
\r
455 //! supports only floating-point source
\r
456 CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
\r
458 //! converts polar coordinates to Cartesian
\r
459 //! supports only floating-point source
\r
460 CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false, Stream& stream = Stream::Null());
\r
463 //////////////////////////// Per-element operations ////////////////////////////////////
\r
465 //! adds one matrix to another (c = a + b)
\r
466 CV_EXPORTS void add(const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
\r
467 //! adds scalar to a matrix (c = a + s)
\r
468 CV_EXPORTS void add(const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
\r
470 //! subtracts one matrix from another (c = a - b)
\r
471 CV_EXPORTS void subtract(const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
\r
472 //! subtracts scalar from a matrix (c = a - s)
\r
473 CV_EXPORTS void subtract(const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
\r
475 //! computes element-wise weighted product of the two arrays (c = scale * a * b)
\r
476 CV_EXPORTS void multiply(const GpuMat& a, const GpuMat& b, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
\r
477 //! weighted multiplies matrix to a scalar (c = scale * a * s)
\r
478 CV_EXPORTS void multiply(const GpuMat& a, const Scalar& sc, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
\r
480 //! computes element-wise weighted quotient of the two arrays (c = a / b)
\r
481 CV_EXPORTS void divide(const GpuMat& a, const GpuMat& b, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
\r
482 //! computes element-wise weighted quotient of matrix and scalar (c = a / s)
\r
483 CV_EXPORTS void divide(const GpuMat& a, const Scalar& sc, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
\r
484 //! computes element-wise weighted reciprocal of an array (dst = scale/src2)
\r
485 CV_EXPORTS void divide(double scale, const GpuMat& b, GpuMat& c, int dtype = -1, Stream& stream = Stream::Null());
\r
487 //! computes the weighted sum of two arrays (dst = alpha*src1 + beta*src2 + gamma)
\r
488 CV_EXPORTS void addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst,
\r
489 int dtype = -1, Stream& stream = Stream::Null());
\r
491 //! adds scaled array to another one (dst = alpha*src1 + src2)
\r
492 static inline void scaleAdd(const GpuMat& src1, double alpha, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null())
\r
494 addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream);
\r
497 //! computes element-wise absolute difference of two arrays (c = abs(a - b))
\r
498 CV_EXPORTS void absdiff(const GpuMat& a, const GpuMat& b, GpuMat& c, Stream& stream = Stream::Null());
\r
499 //! computes element-wise absolute difference of array and scalar (c = abs(a - s))
\r
500 CV_EXPORTS void absdiff(const GpuMat& a, const Scalar& s, GpuMat& c, Stream& stream = Stream::Null());
\r
502 //! computes absolute value of each matrix element
\r
503 //! supports CV_16S and CV_32F depth
\r
504 CV_EXPORTS void abs(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
506 //! computes square of each pixel in an image
\r
507 //! supports CV_8U, CV_16U, CV_16S and CV_32F depth
\r
508 CV_EXPORTS void sqr(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
510 //! computes square root of each pixel in an image
\r
511 //! supports CV_8U, CV_16U, CV_16S and CV_32F depth
\r
512 CV_EXPORTS void sqrt(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
514 //! computes exponent of each matrix element (b = e**a)
\r
515 //! supports CV_8U, CV_16U, CV_16S and CV_32F depth
\r
516 CV_EXPORTS void exp(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null());
\r
518 //! computes natural logarithm of absolute value of each matrix element: b = log(abs(a))
\r
519 //! supports CV_8U, CV_16U, CV_16S and CV_32F depth
\r
520 CV_EXPORTS void log(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null());
\r
522 //! computes power of each matrix element:
\r
523 // (dst(i,j) = pow( src(i,j) , power), if src.type() is integer
\r
524 // (dst(i,j) = pow(fabs(src(i,j)), power), otherwise
\r
525 //! supports all, except depth == CV_64F
\r
526 CV_EXPORTS void pow(const GpuMat& src, double power, GpuMat& dst, Stream& stream = Stream::Null());
\r
528 //! compares elements of two arrays (c = a <cmpop> b)
\r
529 CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop, Stream& stream = Stream::Null());
\r
530 CV_EXPORTS void compare(const GpuMat& a, Scalar sc, GpuMat& c, int cmpop, Stream& stream = Stream::Null());
\r
532 //! performs per-elements bit-wise inversion
\r
533 CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
\r
535 //! calculates per-element bit-wise disjunction of two arrays
\r
536 CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
\r
537 //! calculates per-element bit-wise disjunction of array and scalar
\r
538 //! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth
\r
539 CV_EXPORTS void bitwise_or(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null());
\r
541 //! calculates per-element bit-wise conjunction of two arrays
\r
542 CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
\r
543 //! calculates per-element bit-wise conjunction of array and scalar
\r
544 //! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth
\r
545 CV_EXPORTS void bitwise_and(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null());
\r
547 //! calculates per-element bit-wise "exclusive or" operation
\r
548 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
\r
549 //! calculates per-element bit-wise "exclusive or" of array and scalar
\r
550 //! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth
\r
551 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null());
\r
553 //! pixel by pixel right shift of an image by a constant value
\r
554 //! supports 1, 3 and 4 channels images with integers elements
\r
555 CV_EXPORTS void rshift(const GpuMat& src, Scalar_<int> sc, GpuMat& dst, Stream& stream = Stream::Null());
\r
557 //! pixel by pixel left shift of an image by a constant value
\r
558 //! supports 1, 3 and 4 channels images with CV_8U, CV_16U or CV_32S depth
\r
559 CV_EXPORTS void lshift(const GpuMat& src, Scalar_<int> sc, GpuMat& dst, Stream& stream = Stream::Null());
\r
561 //! computes per-element minimum of two arrays (dst = min(src1, src2))
\r
562 CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null());
\r
564 //! computes per-element minimum of array and scalar (dst = min(src1, src2))
\r
565 CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null());
\r
567 //! computes per-element maximum of two arrays (dst = max(src1, src2))
\r
568 CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null());
\r
570 //! computes per-element maximum of array and scalar (dst = max(src1, src2))
\r
571 CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null());
\r
573 enum { ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_PLUS, ALPHA_OVER_PREMUL, ALPHA_IN_PREMUL, ALPHA_OUT_PREMUL,
\r
574 ALPHA_ATOP_PREMUL, ALPHA_XOR_PREMUL, ALPHA_PLUS_PREMUL, ALPHA_PREMUL};
\r
576 //! Composite two images using alpha opacity values contained in each image
\r
577 //! Supports CV_8UC4, CV_16UC4, CV_32SC4 and CV_32FC4 types
\r
578 CV_EXPORTS void alphaComp(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, int alpha_op, Stream& stream = Stream::Null());
\r
581 ////////////////////////////// Image processing //////////////////////////////
\r
583 //! DST[x,y] = SRC[xmap[x,y],ymap[x,y]]
\r
584 //! supports only CV_32FC1 map type
\r
585 CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap,
\r
586 int interpolation, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(),
\r
587 Stream& stream = Stream::Null());
\r
589 //! Does mean shift filtering on GPU.
\r
590 CV_EXPORTS void meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr,
\r
591 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1),
\r
592 Stream& stream = Stream::Null());
\r
594 //! Does mean shift procedure on GPU.
\r
595 CV_EXPORTS void meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr,
\r
596 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1),
\r
597 Stream& stream = Stream::Null());
\r
599 //! Does mean shift segmentation with elimination of small regions.
\r
600 CV_EXPORTS void meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize,
\r
601 TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
\r
603 //! Does coloring of disparity image: [0..ndisp) -> [0..240, 1, 1] in HSV.
\r
604 //! Supported types of input disparity: CV_8U, CV_16S.
\r
605 //! Output disparity has CV_8UC4 type in BGRA format (alpha = 255).
\r
606 CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, Stream& stream = Stream::Null());
\r
608 //! Reprojects disparity image to 3D space.
\r
609 //! Supports CV_8U and CV_16S types of input disparity.
\r
610 //! The output is a 3- or 4-channel floating-point matrix.
\r
611 //! Each element of this matrix will contain the 3D coordinates of the point (x,y,z,1), computed from the disparity map.
\r
612 //! Q is the 4x4 perspective transformation matrix that can be obtained with cvStereoRectify.
\r
613 CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, int dst_cn = 4, Stream& stream = Stream::Null());
\r
615 //! converts image from one color space to another
\r
616 CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0, Stream& stream = Stream::Null());
\r
619 //! dstOrder - Integer array describing how channel values are permutated. The n-th entry
\r
620 //! of the array contains the number of the channel that is stored in the n-th channel of
\r
621 //! the output image. E.g. Given an RGBA image, aDstOrder = [3,2,1,0] converts this to ABGR
\r
623 CV_EXPORTS void swapChannels(GpuMat& image, const int dstOrder[4], Stream& stream = Stream::Null());
\r
625 //! Routines for correcting image color gamma
\r
626 CV_EXPORTS void gammaCorrection(const GpuMat& src, GpuMat& dst, bool forward = true, Stream& stream = Stream::Null());
\r
628 //! applies fixed threshold to the image
\r
629 CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type, Stream& stream = Stream::Null());
\r
631 //! resizes the image
\r
632 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC, INTER_AREA
\r
633 CV_EXPORTS void resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
\r
635 //! warps the image using affine transformation
\r
636 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
637 CV_EXPORTS void warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR,
\r
638 int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
\r
640 CV_EXPORTS void buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null());
\r
642 //! warps the image using perspective transformation
\r
643 //! Supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
644 CV_EXPORTS void warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR,
\r
645 int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
\r
647 CV_EXPORTS void buildWarpPerspectiveMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null());
\r
649 //! builds plane warping maps
\r
650 CV_EXPORTS void buildWarpPlaneMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, const Mat &T, float scale,
\r
651 GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
\r
653 //! builds cylindrical warping maps
\r
654 CV_EXPORTS void buildWarpCylindricalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
\r
655 GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
\r
657 //! builds spherical warping maps
\r
658 CV_EXPORTS void buildWarpSphericalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
\r
659 GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
\r
661 //! rotates an image around the origin (0,0) and then shifts it
\r
662 //! supports INTER_NEAREST, INTER_LINEAR, INTER_CUBIC
\r
663 //! supports 1, 3 or 4 channels images with CV_8U, CV_16U or CV_32F depth
\r
664 CV_EXPORTS void rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0,
\r
665 int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
\r
667 //! copies 2D array to a larger destination array and pads borders with user-specifiable constant
\r
668 CV_EXPORTS void copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, int borderType,
\r
669 const Scalar& value = Scalar(), Stream& stream = Stream::Null());
\r
671 //! computes the integral image
\r
672 //! sum will have CV_32S type, but will contain unsigned int values
\r
673 //! supports only CV_8UC1 source type
\r
674 CV_EXPORTS void integral(const GpuMat& src, GpuMat& sum, Stream& stream = Stream::Null());
\r
675 //! buffered version
\r
676 CV_EXPORTS void integralBuffered(const GpuMat& src, GpuMat& sum, GpuMat& buffer, Stream& stream = Stream::Null());
\r
678 //! computes squared integral image
\r
679 //! result matrix will have 64F type, but will contain 64U values
\r
680 //! supports source images of 8UC1 type only
\r
681 CV_EXPORTS void sqrIntegral(const GpuMat& src, GpuMat& sqsum, Stream& stream = Stream::Null());
\r
683 //! computes vertical sum, supports only CV_32FC1 images
\r
684 CV_EXPORTS void columnSum(const GpuMat& src, GpuMat& sum);
\r
686 //! computes the standard deviation of integral images
\r
687 //! supports only CV_32SC1 source type and CV_32FC1 sqr type
\r
688 //! output will have CV_32FC1 type
\r
689 CV_EXPORTS void rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect, Stream& stream = Stream::Null());
\r
691 //! computes Harris cornerness criteria at each image pixel
\r
692 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
\r
693 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
\r
694 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, double k,
\r
695 int borderType = BORDER_REFLECT101, Stream& stream = Stream::Null());
\r
697 //! computes minimum eigen value of 2x2 derivative covariation matrix at each pixel - the cornerness criteria
\r
698 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
\r
699 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
\r
700 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize,
\r
701 int borderType=BORDER_REFLECT101, Stream& stream = Stream::Null());
\r
703 //! performs per-element multiplication of two full (not packed) Fourier spectrums
\r
704 //! supports 32FC2 matrixes only (interleaved format)
\r
705 CV_EXPORTS void mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB=false, Stream& stream = Stream::Null());
\r
707 //! performs per-element multiplication of two full (not packed) Fourier spectrums
\r
708 //! supports 32FC2 matrixes only (interleaved format)
\r
709 CV_EXPORTS void mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, float scale, bool conjB=false, Stream& stream = Stream::Null());
\r
711 //! Performs a forward or inverse discrete Fourier transform (1D or 2D) of floating point matrix.
\r
712 //! Param dft_size is the size of DFT transform.
\r
714 //! If the source matrix is not continous, then additional copy will be done,
\r
715 //! so to avoid copying ensure the source matrix is continous one. If you want to use
\r
716 //! preallocated output ensure it is continuous too, otherwise it will be reallocated.
\r
718 //! Being implemented via CUFFT real-to-complex transform result contains only non-redundant values
\r
719 //! in CUFFT's format. Result as full complex matrix for such kind of transform cannot be retrieved.
\r
721 //! For complex-to-real transform it is assumed that the source matrix is packed in CUFFT's format.
\r
722 CV_EXPORTS void dft(const GpuMat& src, GpuMat& dst, Size dft_size, int flags=0, Stream& stream = Stream::Null());
\r
724 struct CV_EXPORTS ConvolveBuf
\r
728 Size user_block_size;
\r
732 GpuMat image_spect, templ_spect, result_spect;
\r
733 GpuMat image_block, templ_block, result_data;
\r
735 void create(Size image_size, Size templ_size);
\r
736 static Size estimateBlockSize(Size result_size, Size templ_size);
\r
740 //! computes convolution (or cross-correlation) of two images using discrete Fourier transform
\r
741 //! supports source images of 32FC1 type only
\r
742 //! result matrix will have 32FC1 type
\r
743 CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr = false);
\r
744 CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr, ConvolveBuf& buf, Stream& stream = Stream::Null());
\r
746 struct CV_EXPORTS MatchTemplateBuf
\r
748 Size user_block_size;
\r
749 GpuMat imagef, templf;
\r
750 std::vector<GpuMat> images;
\r
751 std::vector<GpuMat> image_sums;
\r
752 std::vector<GpuMat> image_sqsums;
\r
755 //! computes the proximity map for the raster template and the image where the template is searched for
\r
756 CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, Stream &stream = Stream::Null());
\r
758 //! computes the proximity map for the raster template and the image where the template is searched for
\r
759 CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, MatchTemplateBuf &buf, Stream& stream = Stream::Null());
\r
761 //! smoothes the source image and downsamples it
\r
762 CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
764 //! upsamples the source image and then smoothes it
\r
765 CV_EXPORTS void pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
767 //! performs linear blending of two images
\r
768 //! to avoid accuracy errors sum of weigths shouldn't be very close to zero
\r
769 CV_EXPORTS void blendLinear(const GpuMat& img1, const GpuMat& img2, const GpuMat& weights1, const GpuMat& weights2,
\r
770 GpuMat& result, Stream& stream = Stream::Null());
\r
772 //! Performa bilateral filtering of passsed image
\r
773 CV_EXPORTS void bilateralFilter(const GpuMat& src, GpuMat& dst, int kernel_size, float sigma_color, float sigma_spatial,
\r
774 int borderMode = BORDER_DEFAULT, Stream& stream = Stream::Null());
\r
776 //! Brute force non-local means algorith (slow but universal)
\r
777 CV_EXPORTS void nonLocalMeans(const GpuMat& src, GpuMat& dst, float h,
\r
778 int search_widow_size = 11, int block_size = 7, int borderMode = BORDER_DEFAULT, Stream& s = Stream::Null());
\r
781 struct CV_EXPORTS CannyBuf;
\r
783 CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
\r
784 CV_EXPORTS void Canny(const GpuMat& image, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
\r
785 CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false);
\r
786 CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false);
\r
788 struct CV_EXPORTS CannyBuf
\r
791 explicit CannyBuf(const Size& image_size, int apperture_size = 3) {create(image_size, apperture_size);}
\r
792 CannyBuf(const GpuMat& dx_, const GpuMat& dy_);
\r
794 void create(const Size& image_size, int apperture_size = 3);
\r
799 GpuMat dx_buf, dy_buf;
\r
801 GpuMat trackBuf1, trackBuf2;
\r
802 Ptr<FilterEngine_GPU> filterDX, filterDY;
\r
805 class CV_EXPORTS ImagePyramid
\r
808 inline ImagePyramid() : nLayers_(0) {}
\r
809 inline ImagePyramid(const GpuMat& img, int nLayers, Stream& stream = Stream::Null())
\r
811 build(img, nLayers, stream);
\r
814 void build(const GpuMat& img, int nLayers, Stream& stream = Stream::Null());
\r
816 void getLayer(GpuMat& outImg, Size outRoi, Stream& stream = Stream::Null()) const;
\r
818 inline void release()
\r
827 std::vector<GpuMat> pyramid_;
\r
833 struct HoughLinesBuf
\r
839 CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
\r
840 CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
\r
841 CV_EXPORTS void HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines, OutputArray h_votes = noArray());
\r
845 struct HoughCirclesBuf
\r
853 CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096);
\r
854 CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096);
\r
855 CV_EXPORTS void HoughCirclesDownload(const GpuMat& d_circles, OutputArray h_circles);
\r
857 ////////////////////////////// Matrix reductions //////////////////////////////
\r
859 //! computes mean value and standard deviation of all or selected array elements
\r
860 //! supports only CV_8UC1 type
\r
861 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev);
\r
862 //! buffered version
\r
863 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev, GpuMat& buf);
\r
865 //! computes norm of array
\r
866 //! supports NORM_INF, NORM_L1, NORM_L2
\r
867 //! supports all matrices except 64F
\r
868 CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);
\r
870 //! computes norm of array
\r
871 //! supports NORM_INF, NORM_L1, NORM_L2
\r
872 //! supports all matrices except 64F
\r
873 CV_EXPORTS double norm(const GpuMat& src1, int normType, GpuMat& buf);
\r
875 //! computes norm of the difference between two arrays
\r
876 //! supports NORM_INF, NORM_L1, NORM_L2
\r
877 //! supports only CV_8UC1 type
\r
878 CV_EXPORTS double norm(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2);
\r
880 //! computes sum of array elements
\r
881 //! supports only single channel images
\r
882 CV_EXPORTS Scalar sum(const GpuMat& src);
\r
884 //! computes sum of array elements
\r
885 //! supports only single channel images
\r
886 CV_EXPORTS Scalar sum(const GpuMat& src, GpuMat& buf);
\r
888 //! computes sum of array elements absolute values
\r
889 //! supports only single channel images
\r
890 CV_EXPORTS Scalar absSum(const GpuMat& src);
\r
892 //! computes sum of array elements absolute values
\r
893 //! supports only single channel images
\r
894 CV_EXPORTS Scalar absSum(const GpuMat& src, GpuMat& buf);
\r
896 //! computes squared sum of array elements
\r
897 //! supports only single channel images
\r
898 CV_EXPORTS Scalar sqrSum(const GpuMat& src);
\r
900 //! computes squared sum of array elements
\r
901 //! supports only single channel images
\r
902 CV_EXPORTS Scalar sqrSum(const GpuMat& src, GpuMat& buf);
\r
904 //! finds global minimum and maximum array elements and returns their values
\r
905 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat());
\r
907 //! finds global minimum and maximum array elements and returns their values
\r
908 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf);
\r
910 //! finds global minimum and maximum array elements and returns their values with locations
\r
911 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0,
\r
912 const GpuMat& mask=GpuMat());
\r
914 //! finds global minimum and maximum array elements and returns their values with locations
\r
915 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
\r
916 const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf);
\r
918 //! counts non-zero array elements
\r
919 CV_EXPORTS int countNonZero(const GpuMat& src);
\r
921 //! counts non-zero array elements
\r
922 CV_EXPORTS int countNonZero(const GpuMat& src, GpuMat& buf);
\r
924 //! reduces a matrix to a vector
\r
925 CV_EXPORTS void reduce(const GpuMat& mtx, GpuMat& vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null());
\r
928 ///////////////////////////// Calibration 3D //////////////////////////////////
\r
930 CV_EXPORTS void transformPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
\r
931 GpuMat& dst, Stream& stream = Stream::Null());
\r
933 CV_EXPORTS void projectPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
\r
934 const Mat& camera_mat, const Mat& dist_coef, GpuMat& dst,
\r
935 Stream& stream = Stream::Null());
\r
937 CV_EXPORTS void solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat,
\r
938 const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess=false,
\r
939 int num_iters=100, float max_dist=8.0, int min_inlier_count=100,
\r
940 std::vector<int>* inliers=NULL);
\r
942 //////////////////////////////// Image Labeling ////////////////////////////////
\r
944 //!performs labeling via graph cuts of a 2D regular 4-connected graph.
\r
945 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels,
\r
946 GpuMat& buf, Stream& stream = Stream::Null());
\r
948 //!performs labeling via graph cuts of a 2D regular 8-connected graph.
\r
949 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& topLeft, GpuMat& topRight,
\r
950 GpuMat& bottom, GpuMat& bottomLeft, GpuMat& bottomRight,
\r
952 GpuMat& buf, Stream& stream = Stream::Null());
\r
954 //! compute mask for Generalized Flood fill componetns labeling.
\r
955 CV_EXPORTS void connectivityMask(const GpuMat& image, GpuMat& mask, const cv::Scalar& lo, const cv::Scalar& hi, Stream& stream = Stream::Null());
\r
957 //! performs connected componnents labeling.
\r
958 CV_EXPORTS void labelComponents(const GpuMat& mask, GpuMat& components, int flags = 0, Stream& stream = Stream::Null());
\r
960 ////////////////////////////////// Histograms //////////////////////////////////
\r
962 //! Compute levels with even distribution. levels will have 1 row and nLevels cols and CV_32SC1 type.
\r
963 CV_EXPORTS void evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel);
\r
964 //! Calculates histogram with evenly distributed bins for signle channel source.
\r
965 //! Supports CV_8UC1, CV_16UC1 and CV_16SC1 source types.
\r
966 //! Output hist will have one row and histSize cols and CV_32SC1 type.
\r
967 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
\r
968 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, GpuMat& buf, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
\r
969 //! Calculates histogram with evenly distributed bins for four-channel source.
\r
970 //! All channels of source are processed separately.
\r
971 //! Supports CV_8UC4, CV_16UC4 and CV_16SC4 source types.
\r
972 //! Output hist[i] will have one row and histSize[i] cols and CV_32SC1 type.
\r
973 CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream = Stream::Null());
\r
974 CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], GpuMat& buf, int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream = Stream::Null());
\r
975 //! Calculates histogram with bins determined by levels array.
\r
976 //! levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
977 //! Supports CV_8UC1, CV_16UC1, CV_16SC1 and CV_32FC1 source types.
\r
978 //! Output hist will have one row and (levels.cols-1) cols and CV_32SC1 type.
\r
979 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, Stream& stream = Stream::Null());
\r
980 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, GpuMat& buf, Stream& stream = Stream::Null());
\r
981 //! Calculates histogram with bins determined by levels array.
\r
982 //! All levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
983 //! All channels of source are processed separately.
\r
984 //! Supports CV_8UC4, CV_16UC4, CV_16SC4 and CV_32FC4 source types.
\r
985 //! Output hist[i] will have one row and (levels[i].cols-1) cols and CV_32SC1 type.
\r
986 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], Stream& stream = Stream::Null());
\r
987 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], GpuMat& buf, Stream& stream = Stream::Null());
\r
989 //! Calculates histogram for 8u one channel image
\r
990 //! Output hist will have one row, 256 cols and CV32SC1 type.
\r
991 CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, Stream& stream = Stream::Null());
\r
992 CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null());
\r
994 //! normalizes the grayscale image brightness and contrast by normalizing its histogram
\r
995 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
996 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, Stream& stream = Stream::Null());
\r
997 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null());
\r
999 //////////////////////////////// StereoBM_GPU ////////////////////////////////
\r
1001 class CV_EXPORTS StereoBM_GPU
\r
1004 enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 };
\r
1006 enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 };
\r
1008 //! the default constructor
\r
1010 //! the full constructor taking the camera-specific preset, number of disparities and the SAD window size. ndisparities must be multiple of 8.
\r
1011 StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ);
\r
1013 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair
\r
1014 //! Output disparity has CV_8U type.
\r
1015 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
\r
1017 //! Some heuristics that tries to estmate
\r
1018 // if current GPU will be faster than CPU in this algorithm.
\r
1019 // It queries current active device.
\r
1020 static bool checkIfGpuCallReasonable();
\r
1026 // If avergeTexThreshold == 0 => post procesing is disabled
\r
1027 // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image
\r
1028 // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold
\r
1029 // i.e. input left image is low textured.
\r
1030 float avergeTexThreshold;
\r
1033 GpuMat minSSD, leBuf, riBuf;
\r
1036 ////////////////////////// StereoBeliefPropagation ///////////////////////////
\r
1037 // "Efficient Belief Propagation for Early Vision"
\r
1040 class CV_EXPORTS StereoBeliefPropagation
\r
1043 enum { DEFAULT_NDISP = 64 };
\r
1044 enum { DEFAULT_ITERS = 5 };
\r
1045 enum { DEFAULT_LEVELS = 5 };
\r
1047 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels);
\r
1049 //! the default constructor
\r
1050 explicit StereoBeliefPropagation(int ndisp = DEFAULT_NDISP,
\r
1051 int iters = DEFAULT_ITERS,
\r
1052 int levels = DEFAULT_LEVELS,
\r
1053 int msg_type = CV_32F);
\r
1055 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
1056 //! number of levels, truncation of data cost, data weight,
\r
1057 //! truncation of discontinuity cost and discontinuity single jump
\r
1058 //! DataTerm = data_weight * min(fabs(I2-I1), max_data_term)
\r
1059 //! DiscTerm = min(disc_single_jump * fabs(f1-f2), max_disc_term)
\r
1060 //! please see paper for more details
\r
1061 StereoBeliefPropagation(int ndisp, int iters, int levels,
\r
1062 float max_data_term, float data_weight,
\r
1063 float max_disc_term, float disc_single_jump,
\r
1064 int msg_type = CV_32F);
\r
1066 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
1067 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
1068 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
\r
1071 //! version for user specified data term
\r
1072 void operator()(const GpuMat& data, GpuMat& disparity, Stream& stream = Stream::Null());
\r
1079 float max_data_term;
\r
1080 float data_weight;
\r
1081 float max_disc_term;
\r
1082 float disc_single_jump;
\r
1086 GpuMat u, d, l, r, u2, d2, l2, r2;
\r
1087 std::vector<GpuMat> datas;
\r
1091 /////////////////////////// StereoConstantSpaceBP ///////////////////////////
\r
1092 // "A Constant-Space Belief Propagation Algorithm for Stereo Matching"
\r
1093 // Qingxiong Yang, Liang Wang, Narendra Ahuja
\r
1094 // http://vision.ai.uiuc.edu/~qyang6/
\r
1096 class CV_EXPORTS StereoConstantSpaceBP
\r
1099 enum { DEFAULT_NDISP = 128 };
\r
1100 enum { DEFAULT_ITERS = 8 };
\r
1101 enum { DEFAULT_LEVELS = 4 };
\r
1102 enum { DEFAULT_NR_PLANE = 4 };
\r
1104 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane);
\r
1106 //! the default constructor
\r
1107 explicit StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP,
\r
1108 int iters = DEFAULT_ITERS,
\r
1109 int levels = DEFAULT_LEVELS,
\r
1110 int nr_plane = DEFAULT_NR_PLANE,
\r
1111 int msg_type = CV_32F);
\r
1113 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
1114 //! number of levels, number of active disparity on the first level, truncation of data cost, data weight,
\r
1115 //! truncation of discontinuity cost, discontinuity single jump and minimum disparity threshold
\r
1116 StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,
\r
1117 float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,
\r
1118 int min_disp_th = 0,
\r
1119 int msg_type = CV_32F);
\r
1121 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
1122 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
1123 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
\r
1132 float max_data_term;
\r
1133 float data_weight;
\r
1134 float max_disc_term;
\r
1135 float disc_single_jump;
\r
1141 bool use_local_init_data_cost;
\r
1143 GpuMat messages_buffers;
\r
1149 /////////////////////////// DisparityBilateralFilter ///////////////////////////
\r
1150 // Disparity map refinement using joint bilateral filtering given a single color image.
\r
1151 // Qingxiong Yang, Liang Wang, Narendra Ahuja
\r
1152 // http://vision.ai.uiuc.edu/~qyang6/
\r
1154 class CV_EXPORTS DisparityBilateralFilter
\r
1157 enum { DEFAULT_NDISP = 64 };
\r
1158 enum { DEFAULT_RADIUS = 3 };
\r
1159 enum { DEFAULT_ITERS = 1 };
\r
1161 //! the default constructor
\r
1162 explicit DisparityBilateralFilter(int ndisp = DEFAULT_NDISP, int radius = DEFAULT_RADIUS, int iters = DEFAULT_ITERS);
\r
1164 //! the full constructor taking the number of disparities, filter radius,
\r
1165 //! number of iterations, truncation of data continuity, truncation of disparity continuity
\r
1166 //! and filter range sigma
\r
1167 DisparityBilateralFilter(int ndisp, int radius, int iters, float edge_threshold, float max_disc_threshold, float sigma_range);
\r
1169 //! the disparity map refinement operator. Refine disparity map using joint bilateral filtering given a single color image.
\r
1170 //! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type.
\r
1171 void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream = Stream::Null());
\r
1178 float edge_threshold;
\r
1179 float max_disc_threshold;
\r
1180 float sigma_range;
\r
1182 GpuMat table_color;
\r
1183 GpuMat table_space;
\r
1187 //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
\r
1188 struct CV_EXPORTS HOGConfidence
\r
1191 vector<Point> locations;
\r
1192 vector<double> confidences;
\r
1193 vector<double> part_scores[4];
\r
1196 struct CV_EXPORTS HOGDescriptor
\r
1198 enum { DEFAULT_WIN_SIGMA = -1 };
\r
1199 enum { DEFAULT_NLEVELS = 64 };
\r
1200 enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
\r
1202 HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16),
\r
1203 Size block_stride=Size(8, 8), Size cell_size=Size(8, 8),
\r
1204 int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA,
\r
1205 double threshold_L2hys=0.2, bool gamma_correction=true,
\r
1206 int nlevels=DEFAULT_NLEVELS);
\r
1208 size_t getDescriptorSize() const;
\r
1209 size_t getBlockHistogramSize() const;
\r
1211 void setSVMDetector(const vector<float>& detector);
\r
1213 static vector<float> getDefaultPeopleDetector();
\r
1214 static vector<float> getPeopleDetector48x96();
\r
1215 static vector<float> getPeopleDetector64x128();
\r
1217 void detect(const GpuMat& img, vector<Point>& found_locations,
\r
1218 double hit_threshold=0, Size win_stride=Size(),
\r
1219 Size padding=Size());
\r
1221 void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
\r
1222 double hit_threshold=0, Size win_stride=Size(),
\r
1223 Size padding=Size(), double scale0=1.05,
\r
1224 int group_threshold=2);
\r
1226 void computeConfidence(const GpuMat& img, vector<Point>& hits, double hit_threshold,
\r
1227 Size win_stride, Size padding, vector<Point>& locations, vector<double>& confidences);
\r
1229 void computeConfidenceMultiScale(const GpuMat& img, vector<Rect>& found_locations,
\r
1230 double hit_threshold, Size win_stride, Size padding,
\r
1231 vector<HOGConfidence> &conf_out, int group_threshold);
\r
1233 void getDescriptors(const GpuMat& img, Size win_stride,
\r
1234 GpuMat& descriptors,
\r
1235 int descr_format=DESCR_FORMAT_COL_BY_COL);
\r
1239 Size block_stride;
\r
1243 double threshold_L2hys;
\r
1244 bool gamma_correction;
\r
1248 void computeBlockHistograms(const GpuMat& img);
\r
1249 void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle);
\r
1251 double getWinSigma() const;
\r
1252 bool checkDetectorSize() const;
\r
1254 static int numPartsWithin(int size, int part_size, int stride);
\r
1255 static Size numPartsWithin(Size size, Size part_size, Size stride);
\r
1257 // Coefficients of the separating plane
\r
1261 // Results of the last classification step
\r
1262 GpuMat labels, labels_buf;
\r
1265 // Results of the last histogram evaluation step
\r
1266 GpuMat block_hists, block_hists_buf;
\r
1268 // Gradients conputation results
\r
1269 GpuMat grad, qangle, grad_buf, qangle_buf;
\r
1271 // returns subbuffer with required size, reallocates buffer if nessesary.
\r
1272 static GpuMat getBuffer(const Size& sz, int type, GpuMat& buf);
\r
1273 static GpuMat getBuffer(int rows, int cols, int type, GpuMat& buf);
\r
1275 std::vector<GpuMat> image_scales;
\r
1279 ////////////////////////////////// BruteForceMatcher //////////////////////////////////
\r
1281 class CV_EXPORTS BFMatcher_GPU
\r
1284 explicit BFMatcher_GPU(int norm = cv::NORM_L2);
\r
1286 // Add descriptors to train descriptor collection
\r
1287 void add(const std::vector<GpuMat>& descCollection);
\r
1289 // Get train descriptors collection
\r
1290 const std::vector<GpuMat>& getTrainDescriptors() const;
\r
1292 // Clear train descriptors collection
\r
1295 // Return true if there are not train descriptors in collection
\r
1296 bool empty() const;
\r
1298 // Return true if the matcher supports mask in match methods
\r
1299 bool isMaskSupported() const;
\r
1301 // Find one best match for each query descriptor
\r
1302 void matchSingle(const GpuMat& query, const GpuMat& train,
\r
1303 GpuMat& trainIdx, GpuMat& distance,
\r
1304 const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
\r
1306 // Download trainIdx and distance and convert it to CPU vector with DMatch
\r
1307 static void matchDownload(const GpuMat& trainIdx, const GpuMat& distance, std::vector<DMatch>& matches);
\r
1308 // Convert trainIdx and distance to vector with DMatch
\r
1309 static void matchConvert(const Mat& trainIdx, const Mat& distance, std::vector<DMatch>& matches);
\r
1311 // Find one best match for each query descriptor
\r
1312 void match(const GpuMat& query, const GpuMat& train, std::vector<DMatch>& matches, const GpuMat& mask = GpuMat());
\r
1314 // Make gpu collection of trains and masks in suitable format for matchCollection function
\r
1315 void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection, const std::vector<GpuMat>& masks = std::vector<GpuMat>());
\r
1317 // Find one best match from train collection for each query descriptor
\r
1318 void matchCollection(const GpuMat& query, const GpuMat& trainCollection,
\r
1319 GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
\r
1320 const GpuMat& masks = GpuMat(), Stream& stream = Stream::Null());
\r
1322 // Download trainIdx, imgIdx and distance and convert it to vector with DMatch
\r
1323 static void matchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, std::vector<DMatch>& matches);
\r
1324 // Convert trainIdx, imgIdx and distance to vector with DMatch
\r
1325 static void matchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, std::vector<DMatch>& matches);
\r
1327 // Find one best match from train collection for each query descriptor.
\r
1328 void match(const GpuMat& query, std::vector<DMatch>& matches, const std::vector<GpuMat>& masks = std::vector<GpuMat>());
\r
1330 // Find k best matches for each query descriptor (in increasing order of distances)
\r
1331 void knnMatchSingle(const GpuMat& query, const GpuMat& train,
\r
1332 GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k,
\r
1333 const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
\r
1335 // Download trainIdx and distance and convert it to vector with DMatch
\r
1336 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1337 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1338 // matches vector will not contain matches for fully masked out query descriptors.
\r
1339 static void knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance,
\r
1340 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1341 // Convert trainIdx and distance to vector with DMatch
\r
1342 static void knnMatchConvert(const Mat& trainIdx, const Mat& distance,
\r
1343 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1345 // Find k best matches for each query descriptor (in increasing order of distances).
\r
1346 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1347 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1348 // matches vector will not contain matches for fully masked out query descriptors.
\r
1349 void knnMatch(const GpuMat& query, const GpuMat& train,
\r
1350 std::vector< std::vector<DMatch> >& matches, int k, const GpuMat& mask = GpuMat(),
\r
1351 bool compactResult = false);
\r
1353 // Find k best matches from train collection for each query descriptor (in increasing order of distances)
\r
1354 void knnMatch2Collection(const GpuMat& query, const GpuMat& trainCollection,
\r
1355 GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
\r
1356 const GpuMat& maskCollection = GpuMat(), Stream& stream = Stream::Null());
\r
1358 // Download trainIdx and distance and convert it to vector with DMatch
\r
1359 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1360 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1361 // matches vector will not contain matches for fully masked out query descriptors.
\r
1362 static void knnMatch2Download(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance,
\r
1363 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1364 // Convert trainIdx and distance to vector with DMatch
\r
1365 static void knnMatch2Convert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance,
\r
1366 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1368 // Find k best matches for each query descriptor (in increasing order of distances).
\r
1369 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1370 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1371 // matches vector will not contain matches for fully masked out query descriptors.
\r
1372 void knnMatch(const GpuMat& query, std::vector< std::vector<DMatch> >& matches, int k,
\r
1373 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
\r
1375 // Find best matches for each query descriptor which have distance less than maxDistance.
\r
1376 // nMatches.at<int>(0, queryIdx) will contain matches count for queryIdx.
\r
1377 // carefully nMatches can be greater than trainIdx.cols - it means that matcher didn't find all matches,
\r
1378 // because it didn't have enough memory.
\r
1379 // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nTrain / 100), 10),
\r
1380 // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
\r
1381 // Matches doesn't sorted.
\r
1382 void radiusMatchSingle(const GpuMat& query, const GpuMat& train,
\r
1383 GpuMat& trainIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance,
\r
1384 const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
\r
1386 // Download trainIdx, nMatches and distance and convert it to vector with DMatch.
\r
1387 // matches will be sorted in increasing order of distances.
\r
1388 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1389 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1390 // matches vector will not contain matches for fully masked out query descriptors.
\r
1391 static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, const GpuMat& nMatches,
\r
1392 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1393 // Convert trainIdx, nMatches and distance to vector with DMatch.
\r
1394 static void radiusMatchConvert(const Mat& trainIdx, const Mat& distance, const Mat& nMatches,
\r
1395 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1397 // Find best matches for each query descriptor which have distance less than maxDistance
\r
1398 // in increasing order of distances).
\r
1399 void radiusMatch(const GpuMat& query, const GpuMat& train,
\r
1400 std::vector< std::vector<DMatch> >& matches, float maxDistance,
\r
1401 const GpuMat& mask = GpuMat(), bool compactResult = false);
\r
1403 // Find best matches for each query descriptor which have distance less than maxDistance.
\r
1404 // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nQuery / 100), 10),
\r
1405 // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
\r
1406 // Matches doesn't sorted.
\r
1407 void radiusMatchCollection(const GpuMat& query, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance,
\r
1408 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), Stream& stream = Stream::Null());
\r
1410 // Download trainIdx, imgIdx, nMatches and distance and convert it to vector with DMatch.
\r
1411 // matches will be sorted in increasing order of distances.
\r
1412 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1413 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1414 // matches vector will not contain matches for fully masked out query descriptors.
\r
1415 static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, const GpuMat& nMatches,
\r
1416 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1417 // Convert trainIdx, nMatches and distance to vector with DMatch.
\r
1418 static void radiusMatchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, const Mat& nMatches,
\r
1419 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1421 // Find best matches from train collection for each query descriptor which have distance less than
\r
1422 // maxDistance (in increasing order of distances).
\r
1423 void radiusMatch(const GpuMat& query, std::vector< std::vector<DMatch> >& matches, float maxDistance,
\r
1424 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
\r
1429 std::vector<GpuMat> trainDescCollection;
\r
1432 template <class Distance>
\r
1433 class CV_EXPORTS BruteForceMatcher_GPU;
\r
1435 template <typename T>
\r
1436 class CV_EXPORTS BruteForceMatcher_GPU< L1<T> > : public BFMatcher_GPU
\r
1439 explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_L1) {}
\r
1440 explicit BruteForceMatcher_GPU(L1<T> /*d*/) : BFMatcher_GPU(NORM_L1) {}
\r
1442 template <typename T>
\r
1443 class CV_EXPORTS BruteForceMatcher_GPU< L2<T> > : public BFMatcher_GPU
\r
1446 explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_L2) {}
\r
1447 explicit BruteForceMatcher_GPU(L2<T> /*d*/) : BFMatcher_GPU(NORM_L2) {}
\r
1449 template <> class CV_EXPORTS BruteForceMatcher_GPU< Hamming > : public BFMatcher_GPU
\r
1452 explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_HAMMING) {}
\r
1453 explicit BruteForceMatcher_GPU(Hamming /*d*/) : BFMatcher_GPU(NORM_HAMMING) {}
\r
1456 ////////////////////////////////// CascadeClassifier_GPU //////////////////////////////////////////
\r
1457 // The cascade classifier class for object detection: supports old haar and new lbp xlm formats and nvbin for haar cascades olny.
\r
1458 class CV_EXPORTS CascadeClassifier_GPU
\r
1461 CascadeClassifier_GPU();
\r
1462 CascadeClassifier_GPU(const std::string& filename);
\r
1463 ~CascadeClassifier_GPU();
\r
1465 bool empty() const;
\r
1466 bool load(const std::string& filename);
\r
1469 /* returns number of detected objects */
\r
1470 int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor = 1.2, int minNeighbors = 4, Size minSize = Size());
\r
1472 bool findLargestObject;
\r
1473 bool visualizeInPlace;
\r
1475 Size getClassifierSize() const;
\r
1478 struct CascadeClassifierImpl;
\r
1479 CascadeClassifierImpl* impl;
\r
1480 struct HaarCascade;
\r
1481 struct LbpCascade;
\r
1482 friend class CascadeClassifier_GPU_LBP;
\r
1485 int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4);
\r
1488 ////////////////////////////////// SURF //////////////////////////////////////////
\r
1490 class CV_EXPORTS SURF_GPU
\r
1493 enum KeypointLayout
\r
1505 //! the default constructor
\r
1507 //! the full constructor taking all the necessary parameters
\r
1508 explicit SURF_GPU(double _hessianThreshold, int _nOctaves=4,
\r
1509 int _nOctaveLayers=2, bool _extended=false, float _keypointsRatio=0.01f, bool _upright = false);
\r
1511 //! returns the descriptor size in float's (64 or 128)
\r
1512 int descriptorSize() const;
\r
1514 //! upload host keypoints to device memory
\r
1515 static void uploadKeypoints(const vector<KeyPoint>& keypoints, GpuMat& keypointsGPU);
\r
1516 //! download keypoints from device to host memory
\r
1517 static void downloadKeypoints(const GpuMat& keypointsGPU, vector<KeyPoint>& keypoints);
\r
1519 //! download descriptors from device to host memory
\r
1520 static void downloadDescriptors(const GpuMat& descriptorsGPU, vector<float>& descriptors);
\r
1522 //! finds the keypoints using fast hessian detector used in SURF
\r
1523 //! supports CV_8UC1 images
\r
1524 //! keypoints will have nFeature cols and 6 rows
\r
1525 //! keypoints.ptr<float>(X_ROW)[i] will contain x coordinate of i'th feature
\r
1526 //! keypoints.ptr<float>(Y_ROW)[i] will contain y coordinate of i'th feature
\r
1527 //! keypoints.ptr<float>(LAPLACIAN_ROW)[i] will contain laplacian sign of i'th feature
\r
1528 //! keypoints.ptr<float>(OCTAVE_ROW)[i] will contain octave of i'th feature
\r
1529 //! keypoints.ptr<float>(SIZE_ROW)[i] will contain size of i'th feature
\r
1530 //! keypoints.ptr<float>(ANGLE_ROW)[i] will contain orientation of i'th feature
\r
1531 //! keypoints.ptr<float>(HESSIAN_ROW)[i] will contain response of i'th feature
\r
1532 void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints);
\r
1533 //! finds the keypoints and computes their descriptors.
\r
1534 //! Optionally it can compute descriptors for the user-provided keypoints and recompute keypoints direction
\r
1535 void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors,
\r
1536 bool useProvidedKeypoints = false);
\r
1538 void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
\r
1539 void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors,
\r
1540 bool useProvidedKeypoints = false);
\r
1542 void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, std::vector<float>& descriptors,
\r
1543 bool useProvidedKeypoints = false);
\r
1545 void releaseMemory();
\r
1547 // SURF parameters
\r
1548 double hessianThreshold;
\r
1550 int nOctaveLayers;
\r
1554 //! max keypoints = min(keypointsRatio * img.size().area(), 65535)
\r
1555 float keypointsRatio;
\r
1557 GpuMat sum, mask1, maskSum, intBuffer;
\r
1559 GpuMat det, trace;
\r
1561 GpuMat maxPosBuffer;
\r
1564 ////////////////////////////////// FAST //////////////////////////////////////////
\r
1566 class CV_EXPORTS FAST_GPU
\r
1576 // all features have same size
\r
1577 static const int FEATURE_SIZE = 7;
\r
1579 explicit FAST_GPU(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05);
\r
1581 //! finds the keypoints using FAST detector
\r
1582 //! supports only CV_8UC1 images
\r
1583 void operator ()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints);
\r
1584 void operator ()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
\r
1586 //! download keypoints from device to host memory
\r
1587 static void downloadKeypoints(const GpuMat& d_keypoints, std::vector<KeyPoint>& keypoints);
\r
1589 //! convert keypoints to KeyPoint vector
\r
1590 static void convertKeypoints(const Mat& h_keypoints, std::vector<KeyPoint>& keypoints);
\r
1592 //! release temporary buffer's memory
\r
1595 bool nonmaxSupression;
\r
1599 //! max keypoints = keypointsRatio * img.size().area()
\r
1600 double keypointsRatio;
\r
1602 //! find keypoints and compute it's response if nonmaxSupression is true
\r
1603 //! return count of detected keypoints
\r
1604 int calcKeyPointsLocation(const GpuMat& image, const GpuMat& mask);
\r
1606 //! get final array of keypoints
\r
1607 //! performs nonmax supression if needed
\r
1608 //! return final count of keypoints
\r
1609 int getKeyPoints(GpuMat& keypoints);
\r
1617 GpuMat d_keypoints_;
\r
1620 ////////////////////////////////// ORB //////////////////////////////////////////
\r
1622 class CV_EXPORTS ORB_GPU
\r
1638 DEFAULT_FAST_THRESHOLD = 20
\r
1642 explicit ORB_GPU(int nFeatures = 500, float scaleFactor = 1.2f, int nLevels = 8, int edgeThreshold = 31,
\r
1643 int firstLevel = 0, int WTA_K = 2, int scoreType = 0, int patchSize = 31);
\r
1645 //! Compute the ORB features on an image
\r
1646 //! image - the image to compute the features (supports only CV_8UC1 images)
\r
1647 //! mask - the mask to apply
\r
1648 //! keypoints - the resulting keypoints
\r
1649 void operator()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
\r
1650 void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints);
\r
1652 //! Compute the ORB features and descriptors on an image
\r
1653 //! image - the image to compute the features (supports only CV_8UC1 images)
\r
1654 //! mask - the mask to apply
\r
1655 //! keypoints - the resulting keypoints
\r
1656 //! descriptors - descriptors array
\r
1657 void operator()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors);
\r
1658 void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors);
\r
1660 //! download keypoints from device to host memory
\r
1661 static void downloadKeyPoints(GpuMat& d_keypoints, std::vector<KeyPoint>& keypoints);
\r
1662 //! convert keypoints to KeyPoint vector
\r
1663 static void convertKeyPoints(Mat& d_keypoints, std::vector<KeyPoint>& keypoints);
\r
1665 //! returns the descriptor size in bytes
\r
1666 inline int descriptorSize() const { return kBytes; }
\r
1668 inline void setFastParams(int threshold, bool nonmaxSupression = true)
\r
1670 fastDetector_.threshold = threshold;
\r
1671 fastDetector_.nonmaxSupression = nonmaxSupression;
\r
1674 //! release temporary buffer's memory
\r
1677 //! if true, image will be blurred before descriptors calculation
\r
1678 bool blurForDescriptor;
\r
1681 enum { kBytes = 32 };
\r
1683 void buildScalePyramids(const GpuMat& image, const GpuMat& mask);
\r
1685 void computeKeyPointsPyramid();
\r
1687 void computeDescriptors(GpuMat& descriptors);
\r
1689 void mergeKeyPoints(GpuMat& keypoints);
\r
1692 float scaleFactor_;
\r
1694 int edgeThreshold_;
\r
1700 // The number of desired features per scale
\r
1701 std::vector<size_t> n_features_per_level_;
\r
1703 // Points to compute BRIEF descriptors from
\r
1706 std::vector<GpuMat> imagePyr_;
\r
1707 std::vector<GpuMat> maskPyr_;
\r
1711 std::vector<GpuMat> keyPointsPyr_;
\r
1712 std::vector<int> keyPointsCount_;
\r
1714 FAST_GPU fastDetector_;
\r
1716 Ptr<FilterEngine_GPU> blurFilter;
\r
1718 GpuMat d_keypoints_;
\r
1721 ////////////////////////////////// Optical Flow //////////////////////////////////////////
\r
1723 class CV_EXPORTS BroxOpticalFlow
\r
1726 BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_) :
\r
1727 alpha(alpha_), gamma(gamma_), scale_factor(scale_factor_),
\r
1728 inner_iterations(inner_iterations_), outer_iterations(outer_iterations_), solver_iterations(solver_iterations_)
\r
1732 //! Compute optical flow
\r
1733 //! frame0 - source frame (supports only CV_32FC1 type)
\r
1734 //! frame1 - frame to track (with the same size and type as frame0)
\r
1735 //! u - flow horizontal component (along x axis)
\r
1736 //! v - flow vertical component (along y axis)
\r
1737 void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null());
\r
1739 //! flow smoothness
\r
1742 //! gradient constancy importance
\r
1745 //! pyramid scale factor
\r
1746 float scale_factor;
\r
1748 //! number of lagged non-linearity iterations (inner loop)
\r
1749 int inner_iterations;
\r
1751 //! number of warping iterations (number of pyramid levels)
\r
1752 int outer_iterations;
\r
1754 //! number of linear system solver iterations
\r
1755 int solver_iterations;
\r
1760 class CV_EXPORTS GoodFeaturesToTrackDetector_GPU
\r
1763 explicit GoodFeaturesToTrackDetector_GPU(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0,
\r
1764 int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04);
\r
1766 //! return 1 rows matrix with CV_32FC2 type
\r
1767 void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat());
\r
1770 double qualityLevel;
\r
1771 double minDistance;
\r
1774 bool useHarrisDetector;
\r
1777 void releaseMemory()
\r
1783 minMaxbuf_.release();
\r
1784 tmpCorners_.release();
\r
1792 GpuMat minMaxbuf_;
\r
1793 GpuMat tmpCorners_;
\r
1796 inline GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU(int maxCorners_, double qualityLevel_, double minDistance_,
\r
1797 int blockSize_, bool useHarrisDetector_, double harrisK_)
\r
1799 maxCorners = maxCorners_;
\r
1800 qualityLevel = qualityLevel_;
\r
1801 minDistance = minDistance_;
\r
1802 blockSize = blockSize_;
\r
1803 useHarrisDetector = useHarrisDetector_;
\r
1804 harrisK = harrisK_;
\r
1808 class CV_EXPORTS PyrLKOpticalFlow
\r
1811 PyrLKOpticalFlow();
\r
1813 void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts,
\r
1814 GpuMat& status, GpuMat* err = 0);
\r
1816 void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0);
\r
1818 void releaseMemory();
\r
1823 bool useInitialFlow;
\r
1826 vector<GpuMat> prevPyr_;
\r
1827 vector<GpuMat> nextPyr_;
\r
1834 bool isDeviceArch11_;
\r
1838 class CV_EXPORTS FarnebackOpticalFlow
\r
1841 FarnebackOpticalFlow()
\r
1845 fastPyramids = false;
\r
1851 isDeviceArch11_ = !DeviceInfo().supports(FEATURE_SET_COMPUTE_12);
\r
1856 bool fastPyramids;
\r
1863 void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null());
\r
1865 void releaseMemory()
\r
1867 frames_[0].release();
\r
1868 frames_[1].release();
\r
1869 pyrLevel_[0].release();
\r
1870 pyrLevel_[1].release();
\r
1875 blurredFrame_[0].release();
\r
1876 blurredFrame_[1].release();
\r
1877 pyramid0_.clear();
\r
1878 pyramid1_.clear();
\r
1882 void prepareGaussian(
\r
1883 int n, double sigma, float *g, float *xg, float *xxg,
\r
1884 double &ig11, double &ig03, double &ig33, double &ig55);
\r
1886 void setPolynomialExpansionConsts(int n, double sigma);
\r
1888 void updateFlow_boxFilter(
\r
1889 const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat &flowy,
\r
1890 GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]);
\r
1892 void updateFlow_gaussianBlur(
\r
1893 const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat& flowy,
\r
1894 GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]);
\r
1896 GpuMat frames_[2];
\r
1897 GpuMat pyrLevel_[2], M_, bufM_, R_[2], blurredFrame_[2];
\r
1898 std::vector<GpuMat> pyramid0_, pyramid1_;
\r
1900 bool isDeviceArch11_;
\r
1904 //! Interpolate frames (images) using provided optical flow (displacement field).
\r
1905 //! frame0 - frame 0 (32-bit floating point images, single channel)
\r
1906 //! frame1 - frame 1 (the same type and size)
\r
1907 //! fu - forward horizontal displacement
\r
1908 //! fv - forward vertical displacement
\r
1909 //! bu - backward horizontal displacement
\r
1910 //! bv - backward vertical displacement
\r
1911 //! pos - new frame position
\r
1912 //! newFrame - new frame
\r
1913 //! buf - temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat;
\r
1914 //! occlusion masks 0, occlusion masks 1,
\r
1915 //! interpolated forward flow 0, interpolated forward flow 1,
\r
1916 //! interpolated backward flow 0, interpolated backward flow 1
\r
1918 CV_EXPORTS void interpolateFrames(const GpuMat& frame0, const GpuMat& frame1,
\r
1919 const GpuMat& fu, const GpuMat& fv,
\r
1920 const GpuMat& bu, const GpuMat& bv,
\r
1921 float pos, GpuMat& newFrame, GpuMat& buf,
\r
1922 Stream& stream = Stream::Null());
\r
1924 CV_EXPORTS void createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMat& vertex, GpuMat& colors);
\r
1927 //////////////////////// Background/foreground segmentation ////////////////////////
\r
1929 // Foreground Object Detection from Videos Containing Complex Background.
\r
1930 // Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian.
\r
1932 class CV_EXPORTS FGDStatModel
\r
1935 struct CV_EXPORTS Params
\r
1937 int Lc; // Quantized levels per 'color' component. Power of two, typically 32, 64 or 128.
\r
1938 int N1c; // Number of color vectors used to model normal background color variation at a given pixel.
\r
1939 int N2c; // Number of color vectors retained at given pixel. Must be > N1c, typically ~ 5/3 of N1c.
\r
1940 // Used to allow the first N1c vectors to adapt over time to changing background.
\r
1942 int Lcc; // Quantized levels per 'color co-occurrence' component. Power of two, typically 16, 32 or 64.
\r
1943 int N1cc; // Number of color co-occurrence vectors used to model normal background color variation at a given pixel.
\r
1944 int N2cc; // Number of color co-occurrence vectors retained at given pixel. Must be > N1cc, typically ~ 5/3 of N1cc.
\r
1945 // Used to allow the first N1cc vectors to adapt over time to changing background.
\r
1947 bool is_obj_without_holes; // If TRUE we ignore holes within foreground blobs. Defaults to TRUE.
\r
1948 int perform_morphing; // Number of erode-dilate-erode foreground-blob cleanup iterations.
\r
1949 // These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.
\r
1951 float alpha1; // How quickly we forget old background pixel values seen. Typically set to 0.1.
\r
1952 float alpha2; // "Controls speed of feature learning". Depends on T. Typical value circa 0.005.
\r
1953 float alpha3; // Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.
\r
1955 float delta; // Affects color and color co-occurrence quantization, typically set to 2.
\r
1956 float T; // A percentage value which determines when new features can be recognized as new background. (Typically 0.9).
\r
1957 float minArea; // Discard foreground blobs whose bounding box is smaller than this threshold.
\r
1963 // out_cn - channels count in output result (can be 3 or 4)
\r
1964 // 4-channels require more memory, but a bit faster
\r
1965 explicit FGDStatModel(int out_cn = 3);
\r
1966 explicit FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3);
\r
1970 void create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params());
\r
1973 int update(const cv::gpu::GpuMat& curFrame);
\r
1975 //8UC3 or 8UC4 reference background image
\r
1976 cv::gpu::GpuMat background;
\r
1978 //8UC1 foreground image
\r
1979 cv::gpu::GpuMat foreground;
\r
1981 std::vector< std::vector<cv::Point> > foreground_regions;
\r
1984 FGDStatModel(const FGDStatModel&);
\r
1985 FGDStatModel& operator=(const FGDStatModel&);
\r
1988 std::auto_ptr<Impl> impl_;
\r
1992 Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm
\r
1994 The class implements the following algorithm:
\r
1995 "An improved adaptive background mixture model for real-time tracking with shadow detection"
\r
1996 P. KadewTraKuPong and R. Bowden,
\r
1997 Proc. 2nd European Workshp on Advanced Video-Based Surveillance Systems, 2001."
\r
1998 http://personal.ee.surrey.ac.uk/Personal/R.Bowden/publications/avbs01/avbs01.pdf
\r
2000 class CV_EXPORTS MOG_GPU
\r
2003 //! the default constructor
\r
2004 MOG_GPU(int nmixtures = -1);
\r
2006 //! re-initiaization method
\r
2007 void initialize(Size frameSize, int frameType);
\r
2009 //! the update operator
\r
2010 void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null());
\r
2012 //! computes a background image which are the mean of all background gaussians
\r
2013 void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
\r
2015 //! releases all inner buffers
\r
2019 float varThreshold;
\r
2020 float backgroundRatio;
\r
2037 The class implements the following algorithm:
\r
2038 "Improved adaptive Gausian mixture model for background subtraction"
\r
2040 International Conference Pattern Recognition, UK, August, 2004.
\r
2041 http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf
\r
2043 class CV_EXPORTS MOG2_GPU
\r
2046 //! the default constructor
\r
2047 MOG2_GPU(int nmixtures = -1);
\r
2049 //! re-initiaization method
\r
2050 void initialize(Size frameSize, int frameType);
\r
2052 //! the update operator
\r
2053 void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
\r
2055 //! computes a background image which are the mean of all background gaussians
\r
2056 void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
\r
2058 //! releases all inner buffers
\r
2062 // you should call initialize after parameters changes
\r
2066 //! here it is the maximum allowed number of mixture components.
\r
2067 //! Actual number is determined dynamically per pixel
\r
2068 float varThreshold;
\r
2069 // threshold on the squared Mahalanobis distance to decide if it is well described
\r
2070 // by the background model or not. Related to Cthr from the paper.
\r
2071 // This does not influence the update of the background. A typical value could be 4 sigma
\r
2072 // and that is varThreshold=4*4=16; Corresponds to Tb in the paper.
\r
2074 /////////////////////////
\r
2075 // less important parameters - things you might change but be carefull
\r
2076 ////////////////////////
\r
2078 float backgroundRatio;
\r
2079 // corresponds to fTB=1-cf from the paper
\r
2080 // TB - threshold when the component becomes significant enough to be included into
\r
2081 // the background model. It is the TB=1-cf from the paper. So I use cf=0.1 => TB=0.
\r
2082 // For alpha=0.001 it means that the mode should exist for approximately 105 frames before
\r
2083 // it is considered foreground
\r
2084 // float noiseSigma;
\r
2085 float varThresholdGen;
\r
2087 //correspondts to Tg - threshold on the squared Mahalan. dist. to decide
\r
2088 //when a sample is close to the existing components. If it is not close
\r
2089 //to any a new component will be generated. I use 3 sigma => Tg=3*3=9.
\r
2090 //Smaller Tg leads to more generated components and higher Tg might make
\r
2091 //lead to small number of components but they can grow too large
\r
2096 //initial variance for the newly generated components.
\r
2097 //It will will influence the speed of adaptation. A good guess should be made.
\r
2098 //A simple way is to estimate the typical standard deviation from the images.
\r
2099 //I used here 10 as a reasonable value
\r
2100 // min and max can be used to further control the variance
\r
2101 float fCT; //CT - complexity reduction prior
\r
2102 //this is related to the number of samples needed to accept that a component
\r
2103 //actually exists. We use CT=0.05 of all the samples. By setting CT=0 you get
\r
2104 //the standard Stauffer&Grimson algorithm (maybe not exact but very similar)
\r
2106 //shadow detection parameters
\r
2107 bool bShadowDetection; //default 1 - do shadow detection
\r
2108 unsigned char nShadowDetection; //do shadow detection - insert this value as the detection result - 127 default value
\r
2110 // Tau - shadow threshold. The shadow is detected if the pixel is darker
\r
2111 //version of the background. Tau is a threshold on how much darker the shadow can be.
\r
2112 //Tau= 0.5 means that if pixel is more than 2 times darker then it is not shadow
\r
2113 //See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003.
\r
2126 GpuMat bgmodelUsedModes_; //keep track of number of modes per pixel
\r
2130 * The class implements the following algorithm:
\r
2131 * "ViBe: A universal background subtraction algorithm for video sequences"
\r
2132 * O. Barnich and M. Van D Roogenbroeck
\r
2133 * IEEE Transactions on Image Processing, 20(6) :1709-1724, June 2011
\r
2135 class CV_EXPORTS VIBE_GPU
\r
2138 //! the default constructor
\r
2139 explicit VIBE_GPU(unsigned long rngSeed = 1234567);
\r
2141 //! re-initiaization method
\r
2142 void initialize(const GpuMat& firstFrame, Stream& stream = Stream::Null());
\r
2144 //! the update operator
\r
2145 void operator()(const GpuMat& frame, GpuMat& fgmask, Stream& stream = Stream::Null());
\r
2147 //! releases all inner buffers
\r
2150 int nbSamples; // number of samples per pixel
\r
2151 int reqMatches; // #_min
\r
2153 int subsamplingFactor; // amount of random subsampling
\r
2158 unsigned long rngSeed_;
\r
2159 GpuMat randStates_;
\r
2165 * Background Subtractor module. Takes a series of images and returns a sequence of mask (8UC1)
\r
2166 * images of the same size, where 255 indicates Foreground and 0 represents Background.
\r
2167 * This class implements an algorithm described in "Visual Tracking of Human Visitors under
\r
2168 * Variable-Lighting Conditions for a Responsive Audio Art Installation," A. Godbehere,
\r
2169 * A. Matsukawa, K. Goldberg, American Control Conference, Montreal, June 2012.
\r
2171 class CV_EXPORTS GMG_GPU
\r
2177 * Validate parameters and set up data structures for appropriate frame size.
\r
2178 * @param frameSize Input frame size
\r
2179 * @param min Minimum value taken on by pixels in image sequence. Usually 0
\r
2180 * @param max Maximum value taken on by pixels in image sequence. e.g. 1.0 or 255
\r
2182 void initialize(Size frameSize, float min = 0.0f, float max = 255.0f);
\r
2185 * Performs single-frame background subtraction and builds up a statistical background image
\r
2187 * @param frame Input frame
\r
2188 * @param fgmask Output mask image representing foreground and background pixels
\r
2189 * @param stream Stream for the asynchronous version
\r
2191 void operator ()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
\r
2193 //! Releases all inner buffers
\r
2196 //! Total number of distinct colors to maintain in histogram.
\r
2199 //! Set between 0.0 and 1.0, determines how quickly features are "forgotten" from histograms.
\r
2200 float learningRate;
\r
2202 //! Number of frames of video to use to initialize histograms.
\r
2203 int numInitializationFrames;
\r
2205 //! Number of discrete levels in each channel to be used in histograms.
\r
2206 int quantizationLevels;
\r
2208 //! Prior probability that any given pixel is a background pixel. A sensitivity parameter.
\r
2209 float backgroundPrior;
\r
2211 //! Value above which pixel is determined to be FG.
\r
2212 float decisionThreshold;
\r
2214 //! Smoothing radius, in pixels, for cleaning up FG image.
\r
2215 int smoothingRadius;
\r
2217 //! Perform background model update.
\r
2218 bool updateBackgroundModel;
\r
2221 float maxVal_, minVal_;
\r
2227 GpuMat nfeatures_;
\r
2231 Ptr<FilterEngine_GPU> boxFilter_;
\r
2235 ////////////////////////////////// Video Encoding //////////////////////////////////
\r
2237 // Works only under Windows
\r
2238 // Supports olny H264 video codec and AVI files
\r
2239 class CV_EXPORTS VideoWriter_GPU
\r
2242 struct EncoderParams;
\r
2244 // Callbacks for video encoder, use it if you want to work with raw video stream
\r
2245 class EncoderCallBack;
\r
2247 enum SurfaceFormat
\r
2258 VideoWriter_GPU();
\r
2259 VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2260 VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2261 VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2262 VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2263 ~VideoWriter_GPU();
\r
2265 // all methods throws cv::Exception if error occurs
\r
2266 void open(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2267 void open(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2268 void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2269 void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2271 bool isOpened() const;
\r
2274 void write(const cv::gpu::GpuMat& image, bool lastFrame = false);
\r
2276 struct CV_EXPORTS EncoderParams
\r
2278 int P_Interval; // NVVE_P_INTERVAL,
\r
2279 int IDR_Period; // NVVE_IDR_PERIOD,
\r
2280 int DynamicGOP; // NVVE_DYNAMIC_GOP,
\r
2281 int RCType; // NVVE_RC_TYPE,
\r
2282 int AvgBitrate; // NVVE_AVG_BITRATE,
\r
2283 int PeakBitrate; // NVVE_PEAK_BITRATE,
\r
2284 int QP_Level_Intra; // NVVE_QP_LEVEL_INTRA,
\r
2285 int QP_Level_InterP; // NVVE_QP_LEVEL_INTER_P,
\r
2286 int QP_Level_InterB; // NVVE_QP_LEVEL_INTER_B,
\r
2287 int DeblockMode; // NVVE_DEBLOCK_MODE,
\r
2288 int ProfileLevel; // NVVE_PROFILE_LEVEL,
\r
2289 int ForceIntra; // NVVE_FORCE_INTRA,
\r
2290 int ForceIDR; // NVVE_FORCE_IDR,
\r
2291 int ClearStat; // NVVE_CLEAR_STAT,
\r
2292 int DIMode; // NVVE_SET_DEINTERLACE,
\r
2293 int Presets; // NVVE_PRESETS,
\r
2294 int DisableCabac; // NVVE_DISABLE_CABAC,
\r
2295 int NaluFramingType; // NVVE_CONFIGURE_NALU_FRAMING_TYPE
\r
2296 int DisableSPSPPS; // NVVE_DISABLE_SPS_PPS
\r
2299 explicit EncoderParams(const std::string& configFile);
\r
2301 void load(const std::string& configFile);
\r
2302 void save(const std::string& configFile) const;
\r
2305 EncoderParams getParams() const;
\r
2307 class CV_EXPORTS EncoderCallBack
\r
2317 virtual ~EncoderCallBack() {}
\r
2319 // callback function to signal the start of bitstream that is to be encoded
\r
2320 // must return pointer to buffer
\r
2321 virtual uchar* acquireBitStream(int* bufferSize) = 0;
\r
2323 // callback function to signal that the encoded bitstream is ready to be written to file
\r
2324 virtual void releaseBitStream(unsigned char* data, int size) = 0;
\r
2326 // callback function to signal that the encoding operation on the frame has started
\r
2327 virtual void onBeginFrame(int frameNumber, PicType picType) = 0;
\r
2329 // callback function signals that the encoding operation on the frame has finished
\r
2330 virtual void onEndFrame(int frameNumber, PicType picType) = 0;
\r
2334 VideoWriter_GPU(const VideoWriter_GPU&);
\r
2335 VideoWriter_GPU& operator=(const VideoWriter_GPU&);
\r
2338 std::auto_ptr<Impl> impl_;
\r
2342 ////////////////////////////////// Video Decoding //////////////////////////////////////////
\r
2347 class VideoParser;
\r
2350 class CV_EXPORTS VideoReader_GPU
\r
2364 Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), // Y,U,V (4:2:0)
\r
2365 Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0)
\r
2366 Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0)
\r
2367 Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2)
\r
2368 Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')), // UYVY (4:2:2)
\r
2382 ChromaFormat chromaFormat;
\r
2387 class VideoSource;
\r
2389 VideoReader_GPU();
\r
2390 explicit VideoReader_GPU(const std::string& filename);
\r
2391 explicit VideoReader_GPU(const cv::Ptr<VideoSource>& source);
\r
2393 ~VideoReader_GPU();
\r
2395 void open(const std::string& filename);
\r
2396 void open(const cv::Ptr<VideoSource>& source);
\r
2397 bool isOpened() const;
\r
2401 bool read(GpuMat& image);
\r
2403 FormatInfo format() const;
\r
2404 void dumpFormat(std::ostream& st);
\r
2406 class CV_EXPORTS VideoSource
\r
2409 VideoSource() : frameQueue_(0), videoParser_(0) {}
\r
2410 virtual ~VideoSource() {}
\r
2412 virtual FormatInfo format() const = 0;
\r
2413 virtual void start() = 0;
\r
2414 virtual void stop() = 0;
\r
2415 virtual bool isStarted() const = 0;
\r
2416 virtual bool hasError() const = 0;
\r
2418 void setFrameQueue(detail::FrameQueue* frameQueue) { frameQueue_ = frameQueue; }
\r
2419 void setVideoParser(detail::VideoParser* videoParser) { videoParser_ = videoParser; }
\r
2422 bool parseVideoData(const uchar* data, size_t size, bool endOfStream = false);
\r
2425 VideoSource(const VideoSource&);
\r
2426 VideoSource& operator =(const VideoSource&);
\r
2428 detail::FrameQueue* frameQueue_;
\r
2429 detail::VideoParser* videoParser_;
\r
2433 VideoReader_GPU(const VideoReader_GPU&);
\r
2434 VideoReader_GPU& operator =(const VideoReader_GPU&);
\r
2437 std::auto_ptr<Impl> impl_;
\r
2440 //! removes points (CV_32FC2, single row matrix) with zero mask value
\r
2441 CV_EXPORTS void compactPoints(GpuMat &points0, GpuMat &points1, const GpuMat &mask);
\r
2443 CV_EXPORTS void calcWobbleSuppressionMaps(
\r
2444 int left, int idx, int right, Size size, const Mat &ml, const Mat &mr,
\r
2445 GpuMat &mapx, GpuMat &mapy);
\r
2447 } // namespace gpu
\r
2451 #endif /* __OPENCV_GPU_HPP__ */
\r