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
773 struct CV_EXPORTS CannyBuf;
\r
775 CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
\r
776 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
777 CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false);
\r
778 CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false);
\r
780 struct CV_EXPORTS CannyBuf
\r
783 explicit CannyBuf(const Size& image_size, int apperture_size = 3) {create(image_size, apperture_size);}
\r
784 CannyBuf(const GpuMat& dx_, const GpuMat& dy_);
\r
786 void create(const Size& image_size, int apperture_size = 3);
\r
791 GpuMat dx_buf, dy_buf;
\r
793 GpuMat trackBuf1, trackBuf2;
\r
794 Ptr<FilterEngine_GPU> filterDX, filterDY;
\r
797 class CV_EXPORTS ImagePyramid
\r
800 inline ImagePyramid() : nLayers_(0) {}
\r
801 inline ImagePyramid(const GpuMat& img, int nLayers, Stream& stream = Stream::Null())
\r
803 build(img, nLayers, stream);
\r
806 void build(const GpuMat& img, int nLayers, Stream& stream = Stream::Null());
\r
808 void getLayer(GpuMat& outImg, Size outRoi, Stream& stream = Stream::Null()) const;
\r
810 inline void release()
\r
819 std::vector<GpuMat> pyramid_;
\r
824 CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
\r
825 CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, GpuMat& accum, GpuMat& buf, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
\r
826 CV_EXPORTS void HoughLinesTransform(const GpuMat& src, GpuMat& accum, GpuMat& buf, float rho, float theta);
\r
827 CV_EXPORTS void HoughLinesGet(const GpuMat& accum, GpuMat& lines, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
\r
828 CV_EXPORTS void HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines, OutputArray h_votes = noArray());
\r
830 ////////////////////////////// Matrix reductions //////////////////////////////
\r
832 //! computes mean value and standard deviation of all or selected array elements
\r
833 //! supports only CV_8UC1 type
\r
834 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev);
\r
835 //! buffered version
\r
836 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev, GpuMat& buf);
\r
838 //! computes norm of array
\r
839 //! supports NORM_INF, NORM_L1, NORM_L2
\r
840 //! supports all matrices except 64F
\r
841 CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);
\r
843 //! computes norm of array
\r
844 //! supports NORM_INF, NORM_L1, NORM_L2
\r
845 //! supports all matrices except 64F
\r
846 CV_EXPORTS double norm(const GpuMat& src1, int normType, GpuMat& buf);
\r
848 //! computes norm of the difference between two arrays
\r
849 //! supports NORM_INF, NORM_L1, NORM_L2
\r
850 //! supports only CV_8UC1 type
\r
851 CV_EXPORTS double norm(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2);
\r
853 //! computes sum of array elements
\r
854 //! supports only single channel images
\r
855 CV_EXPORTS Scalar sum(const GpuMat& src);
\r
857 //! computes sum of array elements
\r
858 //! supports only single channel images
\r
859 CV_EXPORTS Scalar sum(const GpuMat& src, GpuMat& buf);
\r
861 //! computes sum of array elements absolute values
\r
862 //! supports only single channel images
\r
863 CV_EXPORTS Scalar absSum(const GpuMat& src);
\r
865 //! computes sum of array elements absolute values
\r
866 //! supports only single channel images
\r
867 CV_EXPORTS Scalar absSum(const GpuMat& src, GpuMat& buf);
\r
869 //! computes squared sum of array elements
\r
870 //! supports only single channel images
\r
871 CV_EXPORTS Scalar sqrSum(const GpuMat& src);
\r
873 //! computes squared sum of array elements
\r
874 //! supports only single channel images
\r
875 CV_EXPORTS Scalar sqrSum(const GpuMat& src, GpuMat& buf);
\r
877 //! finds global minimum and maximum array elements and returns their values
\r
878 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat());
\r
880 //! finds global minimum and maximum array elements and returns their values
\r
881 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf);
\r
883 //! finds global minimum and maximum array elements and returns their values with locations
\r
884 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0,
\r
885 const GpuMat& mask=GpuMat());
\r
887 //! finds global minimum and maximum array elements and returns their values with locations
\r
888 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
\r
889 const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf);
\r
891 //! counts non-zero array elements
\r
892 CV_EXPORTS int countNonZero(const GpuMat& src);
\r
894 //! counts non-zero array elements
\r
895 CV_EXPORTS int countNonZero(const GpuMat& src, GpuMat& buf);
\r
897 //! reduces a matrix to a vector
\r
898 CV_EXPORTS void reduce(const GpuMat& mtx, GpuMat& vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null());
\r
901 ///////////////////////////// Calibration 3D //////////////////////////////////
\r
903 CV_EXPORTS void transformPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
\r
904 GpuMat& dst, Stream& stream = Stream::Null());
\r
906 CV_EXPORTS void projectPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
\r
907 const Mat& camera_mat, const Mat& dist_coef, GpuMat& dst,
\r
908 Stream& stream = Stream::Null());
\r
910 CV_EXPORTS void solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat,
\r
911 const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess=false,
\r
912 int num_iters=100, float max_dist=8.0, int min_inlier_count=100,
\r
913 std::vector<int>* inliers=NULL);
\r
915 //////////////////////////////// Image Labeling ////////////////////////////////
\r
917 //!performs labeling via graph cuts of a 2D regular 4-connected graph.
\r
918 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels,
\r
919 GpuMat& buf, Stream& stream = Stream::Null());
\r
921 //!performs labeling via graph cuts of a 2D regular 8-connected graph.
\r
922 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& topLeft, GpuMat& topRight,
\r
923 GpuMat& bottom, GpuMat& bottomLeft, GpuMat& bottomRight,
\r
925 GpuMat& buf, Stream& stream = Stream::Null());
\r
927 //! compute mask for Generalized Flood fill componetns labeling.
\r
928 CV_EXPORTS void connectivityMask(const GpuMat& image, GpuMat& mask, const cv::Scalar& lo, const cv::Scalar& hi, Stream& stream = Stream::Null());
\r
930 //! performs connected componnents labeling.
\r
931 CV_EXPORTS void labelComponents(const GpuMat& mask, GpuMat& components, int flags = 0, Stream& stream = Stream::Null());
\r
933 ////////////////////////////////// Histograms //////////////////////////////////
\r
935 //! Compute levels with even distribution. levels will have 1 row and nLevels cols and CV_32SC1 type.
\r
936 CV_EXPORTS void evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel);
\r
937 //! Calculates histogram with evenly distributed bins for signle channel source.
\r
938 //! Supports CV_8UC1, CV_16UC1 and CV_16SC1 source types.
\r
939 //! Output hist will have one row and histSize cols and CV_32SC1 type.
\r
940 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
\r
941 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, GpuMat& buf, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
\r
942 //! Calculates histogram with evenly distributed bins for four-channel source.
\r
943 //! All channels of source are processed separately.
\r
944 //! Supports CV_8UC4, CV_16UC4 and CV_16SC4 source types.
\r
945 //! Output hist[i] will have one row and histSize[i] cols and CV_32SC1 type.
\r
946 CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream = Stream::Null());
\r
947 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
948 //! Calculates histogram with bins determined by levels array.
\r
949 //! levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
950 //! Supports CV_8UC1, CV_16UC1, CV_16SC1 and CV_32FC1 source types.
\r
951 //! Output hist will have one row and (levels.cols-1) cols and CV_32SC1 type.
\r
952 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, Stream& stream = Stream::Null());
\r
953 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, GpuMat& buf, Stream& stream = Stream::Null());
\r
954 //! Calculates histogram with bins determined by levels array.
\r
955 //! All levels must have one row and CV_32SC1 type if source has integer type or CV_32FC1 otherwise.
\r
956 //! All channels of source are processed separately.
\r
957 //! Supports CV_8UC4, CV_16UC4, CV_16SC4 and CV_32FC4 source types.
\r
958 //! Output hist[i] will have one row and (levels[i].cols-1) cols and CV_32SC1 type.
\r
959 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], Stream& stream = Stream::Null());
\r
960 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], GpuMat& buf, Stream& stream = Stream::Null());
\r
962 //! Calculates histogram for 8u one channel image
\r
963 //! Output hist will have one row, 256 cols and CV32SC1 type.
\r
964 CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, Stream& stream = Stream::Null());
\r
965 CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null());
\r
967 //! normalizes the grayscale image brightness and contrast by normalizing its histogram
\r
968 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
\r
969 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, Stream& stream = Stream::Null());
\r
970 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null());
\r
972 //////////////////////////////// StereoBM_GPU ////////////////////////////////
\r
974 class CV_EXPORTS StereoBM_GPU
\r
977 enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 };
\r
979 enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 };
\r
981 //! the default constructor
\r
983 //! the full constructor taking the camera-specific preset, number of disparities and the SAD window size. ndisparities must be multiple of 8.
\r
984 StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ);
\r
986 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair
\r
987 //! Output disparity has CV_8U type.
\r
988 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
\r
990 //! Some heuristics that tries to estmate
\r
991 // if current GPU will be faster than CPU in this algorithm.
\r
992 // It queries current active device.
\r
993 static bool checkIfGpuCallReasonable();
\r
999 // If avergeTexThreshold == 0 => post procesing is disabled
\r
1000 // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image
\r
1001 // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold
\r
1002 // i.e. input left image is low textured.
\r
1003 float avergeTexThreshold;
\r
1006 GpuMat minSSD, leBuf, riBuf;
\r
1009 ////////////////////////// StereoBeliefPropagation ///////////////////////////
\r
1010 // "Efficient Belief Propagation for Early Vision"
\r
1013 class CV_EXPORTS StereoBeliefPropagation
\r
1016 enum { DEFAULT_NDISP = 64 };
\r
1017 enum { DEFAULT_ITERS = 5 };
\r
1018 enum { DEFAULT_LEVELS = 5 };
\r
1020 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels);
\r
1022 //! the default constructor
\r
1023 explicit StereoBeliefPropagation(int ndisp = DEFAULT_NDISP,
\r
1024 int iters = DEFAULT_ITERS,
\r
1025 int levels = DEFAULT_LEVELS,
\r
1026 int msg_type = CV_32F);
\r
1028 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
1029 //! number of levels, truncation of data cost, data weight,
\r
1030 //! truncation of discontinuity cost and discontinuity single jump
\r
1031 //! DataTerm = data_weight * min(fabs(I2-I1), max_data_term)
\r
1032 //! DiscTerm = min(disc_single_jump * fabs(f1-f2), max_disc_term)
\r
1033 //! please see paper for more details
\r
1034 StereoBeliefPropagation(int ndisp, int iters, int levels,
\r
1035 float max_data_term, float data_weight,
\r
1036 float max_disc_term, float disc_single_jump,
\r
1037 int msg_type = CV_32F);
\r
1039 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
1040 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
1041 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
\r
1044 //! version for user specified data term
\r
1045 void operator()(const GpuMat& data, GpuMat& disparity, Stream& stream = Stream::Null());
\r
1052 float max_data_term;
\r
1053 float data_weight;
\r
1054 float max_disc_term;
\r
1055 float disc_single_jump;
\r
1059 GpuMat u, d, l, r, u2, d2, l2, r2;
\r
1060 std::vector<GpuMat> datas;
\r
1064 /////////////////////////// StereoConstantSpaceBP ///////////////////////////
\r
1065 // "A Constant-Space Belief Propagation Algorithm for Stereo Matching"
\r
1066 // Qingxiong Yang, Liang Wang, Narendra Ahuja
\r
1067 // http://vision.ai.uiuc.edu/~qyang6/
\r
1069 class CV_EXPORTS StereoConstantSpaceBP
\r
1072 enum { DEFAULT_NDISP = 128 };
\r
1073 enum { DEFAULT_ITERS = 8 };
\r
1074 enum { DEFAULT_LEVELS = 4 };
\r
1075 enum { DEFAULT_NR_PLANE = 4 };
\r
1077 static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane);
\r
1079 //! the default constructor
\r
1080 explicit StereoConstantSpaceBP(int ndisp = DEFAULT_NDISP,
\r
1081 int iters = DEFAULT_ITERS,
\r
1082 int levels = DEFAULT_LEVELS,
\r
1083 int nr_plane = DEFAULT_NR_PLANE,
\r
1084 int msg_type = CV_32F);
\r
1086 //! the full constructor taking the number of disparities, number of BP iterations on each level,
\r
1087 //! number of levels, number of active disparity on the first level, truncation of data cost, data weight,
\r
1088 //! truncation of discontinuity cost, discontinuity single jump and minimum disparity threshold
\r
1089 StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,
\r
1090 float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,
\r
1091 int min_disp_th = 0,
\r
1092 int msg_type = CV_32F);
\r
1094 //! the stereo correspondence operator. Finds the disparity for the specified rectified stereo pair,
\r
1095 //! if disparity is empty output type will be CV_16S else output type will be disparity.type().
\r
1096 void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
\r
1105 float max_data_term;
\r
1106 float data_weight;
\r
1107 float max_disc_term;
\r
1108 float disc_single_jump;
\r
1114 bool use_local_init_data_cost;
\r
1116 GpuMat messages_buffers;
\r
1122 /////////////////////////// DisparityBilateralFilter ///////////////////////////
\r
1123 // Disparity map refinement using joint bilateral filtering given a single color image.
\r
1124 // Qingxiong Yang, Liang Wang, Narendra Ahuja
\r
1125 // http://vision.ai.uiuc.edu/~qyang6/
\r
1127 class CV_EXPORTS DisparityBilateralFilter
\r
1130 enum { DEFAULT_NDISP = 64 };
\r
1131 enum { DEFAULT_RADIUS = 3 };
\r
1132 enum { DEFAULT_ITERS = 1 };
\r
1134 //! the default constructor
\r
1135 explicit DisparityBilateralFilter(int ndisp = DEFAULT_NDISP, int radius = DEFAULT_RADIUS, int iters = DEFAULT_ITERS);
\r
1137 //! the full constructor taking the number of disparities, filter radius,
\r
1138 //! number of iterations, truncation of data continuity, truncation of disparity continuity
\r
1139 //! and filter range sigma
\r
1140 DisparityBilateralFilter(int ndisp, int radius, int iters, float edge_threshold, float max_disc_threshold, float sigma_range);
\r
1142 //! the disparity map refinement operator. Refine disparity map using joint bilateral filtering given a single color image.
\r
1143 //! disparity must have CV_8U or CV_16S type, image must have CV_8UC1 or CV_8UC3 type.
\r
1144 void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream = Stream::Null());
\r
1151 float edge_threshold;
\r
1152 float max_disc_threshold;
\r
1153 float sigma_range;
\r
1155 GpuMat table_color;
\r
1156 GpuMat table_space;
\r
1160 //////////////// HOG (Histogram-of-Oriented-Gradients) Descriptor and Object Detector //////////////
\r
1161 struct CV_EXPORTS HOGConfidence
\r
1164 vector<Point> locations;
\r
1165 vector<double> confidences;
\r
1166 vector<double> part_scores[4];
\r
1169 struct CV_EXPORTS HOGDescriptor
\r
1171 enum { DEFAULT_WIN_SIGMA = -1 };
\r
1172 enum { DEFAULT_NLEVELS = 64 };
\r
1173 enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
\r
1175 HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16),
\r
1176 Size block_stride=Size(8, 8), Size cell_size=Size(8, 8),
\r
1177 int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA,
\r
1178 double threshold_L2hys=0.2, bool gamma_correction=true,
\r
1179 int nlevels=DEFAULT_NLEVELS);
\r
1181 size_t getDescriptorSize() const;
\r
1182 size_t getBlockHistogramSize() const;
\r
1184 void setSVMDetector(const vector<float>& detector);
\r
1186 static vector<float> getDefaultPeopleDetector();
\r
1187 static vector<float> getPeopleDetector48x96();
\r
1188 static vector<float> getPeopleDetector64x128();
\r
1190 void detect(const GpuMat& img, vector<Point>& found_locations,
\r
1191 double hit_threshold=0, Size win_stride=Size(),
\r
1192 Size padding=Size());
\r
1194 void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
\r
1195 double hit_threshold=0, Size win_stride=Size(),
\r
1196 Size padding=Size(), double scale0=1.05,
\r
1197 int group_threshold=2);
\r
1199 void computeConfidence(const GpuMat& img, vector<Point>& hits, double hit_threshold,
\r
1200 Size win_stride, Size padding, vector<Point>& locations, vector<double>& confidences);
\r
1202 void computeConfidenceMultiScale(const GpuMat& img, vector<Rect>& found_locations,
\r
1203 double hit_threshold, Size win_stride, Size padding,
\r
1204 vector<HOGConfidence> &conf_out, int group_threshold);
\r
1206 void getDescriptors(const GpuMat& img, Size win_stride,
\r
1207 GpuMat& descriptors,
\r
1208 int descr_format=DESCR_FORMAT_COL_BY_COL);
\r
1212 Size block_stride;
\r
1216 double threshold_L2hys;
\r
1217 bool gamma_correction;
\r
1221 void computeBlockHistograms(const GpuMat& img);
\r
1222 void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle);
\r
1224 double getWinSigma() const;
\r
1225 bool checkDetectorSize() const;
\r
1227 static int numPartsWithin(int size, int part_size, int stride);
\r
1228 static Size numPartsWithin(Size size, Size part_size, Size stride);
\r
1230 // Coefficients of the separating plane
\r
1234 // Results of the last classification step
\r
1235 GpuMat labels, labels_buf;
\r
1238 // Results of the last histogram evaluation step
\r
1239 GpuMat block_hists, block_hists_buf;
\r
1241 // Gradients conputation results
\r
1242 GpuMat grad, qangle, grad_buf, qangle_buf;
\r
1244 // returns subbuffer with required size, reallocates buffer if nessesary.
\r
1245 static GpuMat getBuffer(const Size& sz, int type, GpuMat& buf);
\r
1246 static GpuMat getBuffer(int rows, int cols, int type, GpuMat& buf);
\r
1248 std::vector<GpuMat> image_scales;
\r
1252 ////////////////////////////////// BruteForceMatcher //////////////////////////////////
\r
1254 class CV_EXPORTS BFMatcher_GPU
\r
1257 explicit BFMatcher_GPU(int norm = cv::NORM_L2);
\r
1259 // Add descriptors to train descriptor collection
\r
1260 void add(const std::vector<GpuMat>& descCollection);
\r
1262 // Get train descriptors collection
\r
1263 const std::vector<GpuMat>& getTrainDescriptors() const;
\r
1265 // Clear train descriptors collection
\r
1268 // Return true if there are not train descriptors in collection
\r
1269 bool empty() const;
\r
1271 // Return true if the matcher supports mask in match methods
\r
1272 bool isMaskSupported() const;
\r
1274 // Find one best match for each query descriptor
\r
1275 void matchSingle(const GpuMat& query, const GpuMat& train,
\r
1276 GpuMat& trainIdx, GpuMat& distance,
\r
1277 const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
\r
1279 // Download trainIdx and distance and convert it to CPU vector with DMatch
\r
1280 static void matchDownload(const GpuMat& trainIdx, const GpuMat& distance, std::vector<DMatch>& matches);
\r
1281 // Convert trainIdx and distance to vector with DMatch
\r
1282 static void matchConvert(const Mat& trainIdx, const Mat& distance, std::vector<DMatch>& matches);
\r
1284 // Find one best match for each query descriptor
\r
1285 void match(const GpuMat& query, const GpuMat& train, std::vector<DMatch>& matches, const GpuMat& mask = GpuMat());
\r
1287 // Make gpu collection of trains and masks in suitable format for matchCollection function
\r
1288 void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection, const std::vector<GpuMat>& masks = std::vector<GpuMat>());
\r
1290 // Find one best match from train collection for each query descriptor
\r
1291 void matchCollection(const GpuMat& query, const GpuMat& trainCollection,
\r
1292 GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
\r
1293 const GpuMat& masks = GpuMat(), Stream& stream = Stream::Null());
\r
1295 // Download trainIdx, imgIdx and distance and convert it to vector with DMatch
\r
1296 static void matchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, std::vector<DMatch>& matches);
\r
1297 // Convert trainIdx, imgIdx and distance to vector with DMatch
\r
1298 static void matchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, std::vector<DMatch>& matches);
\r
1300 // Find one best match from train collection for each query descriptor.
\r
1301 void match(const GpuMat& query, std::vector<DMatch>& matches, const std::vector<GpuMat>& masks = std::vector<GpuMat>());
\r
1303 // Find k best matches for each query descriptor (in increasing order of distances)
\r
1304 void knnMatchSingle(const GpuMat& query, const GpuMat& train,
\r
1305 GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k,
\r
1306 const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
\r
1308 // Download trainIdx and distance and convert it to vector with DMatch
\r
1309 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1310 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1311 // matches vector will not contain matches for fully masked out query descriptors.
\r
1312 static void knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance,
\r
1313 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1314 // Convert trainIdx and distance to vector with DMatch
\r
1315 static void knnMatchConvert(const Mat& trainIdx, const Mat& distance,
\r
1316 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1318 // Find k best matches for each query descriptor (in increasing order of distances).
\r
1319 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1320 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1321 // matches vector will not contain matches for fully masked out query descriptors.
\r
1322 void knnMatch(const GpuMat& query, const GpuMat& train,
\r
1323 std::vector< std::vector<DMatch> >& matches, int k, const GpuMat& mask = GpuMat(),
\r
1324 bool compactResult = false);
\r
1326 // Find k best matches from train collection for each query descriptor (in increasing order of distances)
\r
1327 void knnMatch2Collection(const GpuMat& query, const GpuMat& trainCollection,
\r
1328 GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
\r
1329 const GpuMat& maskCollection = GpuMat(), Stream& stream = Stream::Null());
\r
1331 // Download trainIdx and distance and convert it to vector with DMatch
\r
1332 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1333 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1334 // matches vector will not contain matches for fully masked out query descriptors.
\r
1335 static void knnMatch2Download(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance,
\r
1336 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1337 // Convert trainIdx and distance to vector with DMatch
\r
1338 static void knnMatch2Convert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance,
\r
1339 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1341 // Find k best matches for each query descriptor (in increasing order of distances).
\r
1342 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1343 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1344 // matches vector will not contain matches for fully masked out query descriptors.
\r
1345 void knnMatch(const GpuMat& query, std::vector< std::vector<DMatch> >& matches, int k,
\r
1346 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
\r
1348 // Find best matches for each query descriptor which have distance less than maxDistance.
\r
1349 // nMatches.at<int>(0, queryIdx) will contain matches count for queryIdx.
\r
1350 // carefully nMatches can be greater than trainIdx.cols - it means that matcher didn't find all matches,
\r
1351 // because it didn't have enough memory.
\r
1352 // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nTrain / 100), 10),
\r
1353 // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
\r
1354 // Matches doesn't sorted.
\r
1355 void radiusMatchSingle(const GpuMat& query, const GpuMat& train,
\r
1356 GpuMat& trainIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance,
\r
1357 const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
\r
1359 // Download trainIdx, nMatches and distance and convert it to vector with DMatch.
\r
1360 // matches will be sorted in increasing order of distances.
\r
1361 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1362 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1363 // matches vector will not contain matches for fully masked out query descriptors.
\r
1364 static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, const GpuMat& nMatches,
\r
1365 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1366 // Convert trainIdx, nMatches and distance to vector with DMatch.
\r
1367 static void radiusMatchConvert(const Mat& trainIdx, const Mat& distance, const Mat& nMatches,
\r
1368 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1370 // Find best matches for each query descriptor which have distance less than maxDistance
\r
1371 // in increasing order of distances).
\r
1372 void radiusMatch(const GpuMat& query, const GpuMat& train,
\r
1373 std::vector< std::vector<DMatch> >& matches, float maxDistance,
\r
1374 const GpuMat& mask = GpuMat(), bool compactResult = false);
\r
1376 // Find best matches for each query descriptor which have distance less than maxDistance.
\r
1377 // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nQuery / 100), 10),
\r
1378 // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
\r
1379 // Matches doesn't sorted.
\r
1380 void radiusMatchCollection(const GpuMat& query, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance,
\r
1381 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), Stream& stream = Stream::Null());
\r
1383 // Download trainIdx, imgIdx, nMatches and distance and convert it to vector with DMatch.
\r
1384 // matches will be sorted in increasing order of distances.
\r
1385 // compactResult is used when mask is not empty. If compactResult is false matches
\r
1386 // vector will have the same size as queryDescriptors rows. If compactResult is true
\r
1387 // matches vector will not contain matches for fully masked out query descriptors.
\r
1388 static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, const GpuMat& nMatches,
\r
1389 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1390 // Convert trainIdx, nMatches and distance to vector with DMatch.
\r
1391 static void radiusMatchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, const Mat& nMatches,
\r
1392 std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
\r
1394 // Find best matches from train collection for each query descriptor which have distance less than
\r
1395 // maxDistance (in increasing order of distances).
\r
1396 void radiusMatch(const GpuMat& query, std::vector< std::vector<DMatch> >& matches, float maxDistance,
\r
1397 const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
\r
1402 std::vector<GpuMat> trainDescCollection;
\r
1405 template <class Distance>
\r
1406 class CV_EXPORTS BruteForceMatcher_GPU;
\r
1408 template <typename T>
\r
1409 class CV_EXPORTS BruteForceMatcher_GPU< L1<T> > : public BFMatcher_GPU
\r
1412 explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_L1) {}
\r
1413 explicit BruteForceMatcher_GPU(L1<T> /*d*/) : BFMatcher_GPU(NORM_L1) {}
\r
1415 template <typename T>
\r
1416 class CV_EXPORTS BruteForceMatcher_GPU< L2<T> > : public BFMatcher_GPU
\r
1419 explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_L2) {}
\r
1420 explicit BruteForceMatcher_GPU(L2<T> /*d*/) : BFMatcher_GPU(NORM_L2) {}
\r
1422 template <> class CV_EXPORTS BruteForceMatcher_GPU< Hamming > : public BFMatcher_GPU
\r
1425 explicit BruteForceMatcher_GPU() : BFMatcher_GPU(NORM_HAMMING) {}
\r
1426 explicit BruteForceMatcher_GPU(Hamming /*d*/) : BFMatcher_GPU(NORM_HAMMING) {}
\r
1429 ////////////////////////////////// CascadeClassifier_GPU //////////////////////////////////////////
\r
1430 // The cascade classifier class for object detection: supports old haar and new lbp xlm formats and nvbin for haar cascades olny.
\r
1431 class CV_EXPORTS CascadeClassifier_GPU
\r
1434 CascadeClassifier_GPU();
\r
1435 CascadeClassifier_GPU(const std::string& filename);
\r
1436 ~CascadeClassifier_GPU();
\r
1438 bool empty() const;
\r
1439 bool load(const std::string& filename);
\r
1442 /* returns number of detected objects */
\r
1443 int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor = 1.2, int minNeighbors = 4, Size minSize = Size());
\r
1445 bool findLargestObject;
\r
1446 bool visualizeInPlace;
\r
1448 Size getClassifierSize() const;
\r
1451 struct CascadeClassifierImpl;
\r
1452 CascadeClassifierImpl* impl;
\r
1453 struct HaarCascade;
\r
1454 struct LbpCascade;
\r
1455 friend class CascadeClassifier_GPU_LBP;
\r
1458 int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, Size maxObjectSize, Size minSize = Size(), double scaleFactor = 1.1, int minNeighbors = 4);
\r
1461 ////////////////////////////////// SURF //////////////////////////////////////////
\r
1463 class CV_EXPORTS SURF_GPU
\r
1466 enum KeypointLayout
\r
1478 //! the default constructor
\r
1480 //! the full constructor taking all the necessary parameters
\r
1481 explicit SURF_GPU(double _hessianThreshold, int _nOctaves=4,
\r
1482 int _nOctaveLayers=2, bool _extended=false, float _keypointsRatio=0.01f, bool _upright = false);
\r
1484 //! returns the descriptor size in float's (64 or 128)
\r
1485 int descriptorSize() const;
\r
1487 //! upload host keypoints to device memory
\r
1488 static void uploadKeypoints(const vector<KeyPoint>& keypoints, GpuMat& keypointsGPU);
\r
1489 //! download keypoints from device to host memory
\r
1490 static void downloadKeypoints(const GpuMat& keypointsGPU, vector<KeyPoint>& keypoints);
\r
1492 //! download descriptors from device to host memory
\r
1493 static void downloadDescriptors(const GpuMat& descriptorsGPU, vector<float>& descriptors);
\r
1495 //! finds the keypoints using fast hessian detector used in SURF
\r
1496 //! supports CV_8UC1 images
\r
1497 //! keypoints will have nFeature cols and 6 rows
\r
1498 //! keypoints.ptr<float>(X_ROW)[i] will contain x coordinate of i'th feature
\r
1499 //! keypoints.ptr<float>(Y_ROW)[i] will contain y coordinate of i'th feature
\r
1500 //! keypoints.ptr<float>(LAPLACIAN_ROW)[i] will contain laplacian sign of i'th feature
\r
1501 //! keypoints.ptr<float>(OCTAVE_ROW)[i] will contain octave of i'th feature
\r
1502 //! keypoints.ptr<float>(SIZE_ROW)[i] will contain size of i'th feature
\r
1503 //! keypoints.ptr<float>(ANGLE_ROW)[i] will contain orientation of i'th feature
\r
1504 //! keypoints.ptr<float>(HESSIAN_ROW)[i] will contain response of i'th feature
\r
1505 void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints);
\r
1506 //! finds the keypoints and computes their descriptors.
\r
1507 //! Optionally it can compute descriptors for the user-provided keypoints and recompute keypoints direction
\r
1508 void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors,
\r
1509 bool useProvidedKeypoints = false);
\r
1511 void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
\r
1512 void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors,
\r
1513 bool useProvidedKeypoints = false);
\r
1515 void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, std::vector<float>& descriptors,
\r
1516 bool useProvidedKeypoints = false);
\r
1518 void releaseMemory();
\r
1520 // SURF parameters
\r
1521 double hessianThreshold;
\r
1523 int nOctaveLayers;
\r
1527 //! max keypoints = min(keypointsRatio * img.size().area(), 65535)
\r
1528 float keypointsRatio;
\r
1530 GpuMat sum, mask1, maskSum, intBuffer;
\r
1532 GpuMat det, trace;
\r
1534 GpuMat maxPosBuffer;
\r
1537 ////////////////////////////////// FAST //////////////////////////////////////////
\r
1539 class CV_EXPORTS FAST_GPU
\r
1549 // all features have same size
\r
1550 static const int FEATURE_SIZE = 7;
\r
1552 explicit FAST_GPU(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05);
\r
1554 //! finds the keypoints using FAST detector
\r
1555 //! supports only CV_8UC1 images
\r
1556 void operator ()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints);
\r
1557 void operator ()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
\r
1559 //! download keypoints from device to host memory
\r
1560 static void downloadKeypoints(const GpuMat& d_keypoints, std::vector<KeyPoint>& keypoints);
\r
1562 //! convert keypoints to KeyPoint vector
\r
1563 static void convertKeypoints(const Mat& h_keypoints, std::vector<KeyPoint>& keypoints);
\r
1565 //! release temporary buffer's memory
\r
1568 bool nonmaxSupression;
\r
1572 //! max keypoints = keypointsRatio * img.size().area()
\r
1573 double keypointsRatio;
\r
1575 //! find keypoints and compute it's response if nonmaxSupression is true
\r
1576 //! return count of detected keypoints
\r
1577 int calcKeyPointsLocation(const GpuMat& image, const GpuMat& mask);
\r
1579 //! get final array of keypoints
\r
1580 //! performs nonmax supression if needed
\r
1581 //! return final count of keypoints
\r
1582 int getKeyPoints(GpuMat& keypoints);
\r
1590 GpuMat d_keypoints_;
\r
1593 ////////////////////////////////// ORB //////////////////////////////////////////
\r
1595 class CV_EXPORTS ORB_GPU
\r
1611 DEFAULT_FAST_THRESHOLD = 20
\r
1615 explicit ORB_GPU(int nFeatures = 500, float scaleFactor = 1.2f, int nLevels = 8, int edgeThreshold = 31,
\r
1616 int firstLevel = 0, int WTA_K = 2, int scoreType = 0, int patchSize = 31);
\r
1618 //! Compute the ORB features on an image
\r
1619 //! image - the image to compute the features (supports only CV_8UC1 images)
\r
1620 //! mask - the mask to apply
\r
1621 //! keypoints - the resulting keypoints
\r
1622 void operator()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
\r
1623 void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints);
\r
1625 //! Compute the ORB features and descriptors on an image
\r
1626 //! image - the image to compute the features (supports only CV_8UC1 images)
\r
1627 //! mask - the mask to apply
\r
1628 //! keypoints - the resulting keypoints
\r
1629 //! descriptors - descriptors array
\r
1630 void operator()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors);
\r
1631 void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors);
\r
1633 //! download keypoints from device to host memory
\r
1634 static void downloadKeyPoints(GpuMat& d_keypoints, std::vector<KeyPoint>& keypoints);
\r
1635 //! convert keypoints to KeyPoint vector
\r
1636 static void convertKeyPoints(Mat& d_keypoints, std::vector<KeyPoint>& keypoints);
\r
1638 //! returns the descriptor size in bytes
\r
1639 inline int descriptorSize() const { return kBytes; }
\r
1641 inline void setFastParams(int threshold, bool nonmaxSupression = true)
\r
1643 fastDetector_.threshold = threshold;
\r
1644 fastDetector_.nonmaxSupression = nonmaxSupression;
\r
1647 //! release temporary buffer's memory
\r
1650 //! if true, image will be blurred before descriptors calculation
\r
1651 bool blurForDescriptor;
\r
1654 enum { kBytes = 32 };
\r
1656 void buildScalePyramids(const GpuMat& image, const GpuMat& mask);
\r
1658 void computeKeyPointsPyramid();
\r
1660 void computeDescriptors(GpuMat& descriptors);
\r
1662 void mergeKeyPoints(GpuMat& keypoints);
\r
1665 float scaleFactor_;
\r
1667 int edgeThreshold_;
\r
1673 // The number of desired features per scale
\r
1674 std::vector<size_t> n_features_per_level_;
\r
1676 // Points to compute BRIEF descriptors from
\r
1679 std::vector<GpuMat> imagePyr_;
\r
1680 std::vector<GpuMat> maskPyr_;
\r
1684 std::vector<GpuMat> keyPointsPyr_;
\r
1685 std::vector<int> keyPointsCount_;
\r
1687 FAST_GPU fastDetector_;
\r
1689 Ptr<FilterEngine_GPU> blurFilter;
\r
1691 GpuMat d_keypoints_;
\r
1694 ////////////////////////////////// Optical Flow //////////////////////////////////////////
\r
1696 class CV_EXPORTS BroxOpticalFlow
\r
1699 BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_) :
\r
1700 alpha(alpha_), gamma(gamma_), scale_factor(scale_factor_),
\r
1701 inner_iterations(inner_iterations_), outer_iterations(outer_iterations_), solver_iterations(solver_iterations_)
\r
1705 //! Compute optical flow
\r
1706 //! frame0 - source frame (supports only CV_32FC1 type)
\r
1707 //! frame1 - frame to track (with the same size and type as frame0)
\r
1708 //! u - flow horizontal component (along x axis)
\r
1709 //! v - flow vertical component (along y axis)
\r
1710 void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null());
\r
1712 //! flow smoothness
\r
1715 //! gradient constancy importance
\r
1718 //! pyramid scale factor
\r
1719 float scale_factor;
\r
1721 //! number of lagged non-linearity iterations (inner loop)
\r
1722 int inner_iterations;
\r
1724 //! number of warping iterations (number of pyramid levels)
\r
1725 int outer_iterations;
\r
1727 //! number of linear system solver iterations
\r
1728 int solver_iterations;
\r
1733 class CV_EXPORTS GoodFeaturesToTrackDetector_GPU
\r
1736 explicit GoodFeaturesToTrackDetector_GPU(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0,
\r
1737 int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04);
\r
1739 //! return 1 rows matrix with CV_32FC2 type
\r
1740 void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat());
\r
1743 double qualityLevel;
\r
1744 double minDistance;
\r
1747 bool useHarrisDetector;
\r
1750 void releaseMemory()
\r
1756 minMaxbuf_.release();
\r
1757 tmpCorners_.release();
\r
1765 GpuMat minMaxbuf_;
\r
1766 GpuMat tmpCorners_;
\r
1769 inline GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU(int maxCorners_, double qualityLevel_, double minDistance_,
\r
1770 int blockSize_, bool useHarrisDetector_, double harrisK_)
\r
1772 maxCorners = maxCorners_;
\r
1773 qualityLevel = qualityLevel_;
\r
1774 minDistance = minDistance_;
\r
1775 blockSize = blockSize_;
\r
1776 useHarrisDetector = useHarrisDetector_;
\r
1777 harrisK = harrisK_;
\r
1781 class CV_EXPORTS PyrLKOpticalFlow
\r
1784 PyrLKOpticalFlow();
\r
1786 void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts,
\r
1787 GpuMat& status, GpuMat* err = 0);
\r
1789 void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0);
\r
1791 void releaseMemory();
\r
1796 bool useInitialFlow;
\r
1799 vector<GpuMat> prevPyr_;
\r
1800 vector<GpuMat> nextPyr_;
\r
1807 bool isDeviceArch11_;
\r
1811 class CV_EXPORTS FarnebackOpticalFlow
\r
1814 FarnebackOpticalFlow()
\r
1818 fastPyramids = false;
\r
1824 isDeviceArch11_ = !DeviceInfo().supports(FEATURE_SET_COMPUTE_12);
\r
1829 bool fastPyramids;
\r
1836 void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null());
\r
1838 void releaseMemory()
\r
1840 frames_[0].release();
\r
1841 frames_[1].release();
\r
1842 pyrLevel_[0].release();
\r
1843 pyrLevel_[1].release();
\r
1848 blurredFrame_[0].release();
\r
1849 blurredFrame_[1].release();
\r
1850 pyramid0_.clear();
\r
1851 pyramid1_.clear();
\r
1855 void prepareGaussian(
\r
1856 int n, double sigma, float *g, float *xg, float *xxg,
\r
1857 double &ig11, double &ig03, double &ig33, double &ig55);
\r
1859 void setPolynomialExpansionConsts(int n, double sigma);
\r
1861 void updateFlow_boxFilter(
\r
1862 const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat &flowy,
\r
1863 GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]);
\r
1865 void updateFlow_gaussianBlur(
\r
1866 const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat& flowy,
\r
1867 GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]);
\r
1869 GpuMat frames_[2];
\r
1870 GpuMat pyrLevel_[2], M_, bufM_, R_[2], blurredFrame_[2];
\r
1871 std::vector<GpuMat> pyramid0_, pyramid1_;
\r
1873 bool isDeviceArch11_;
\r
1877 //! Interpolate frames (images) using provided optical flow (displacement field).
\r
1878 //! frame0 - frame 0 (32-bit floating point images, single channel)
\r
1879 //! frame1 - frame 1 (the same type and size)
\r
1880 //! fu - forward horizontal displacement
\r
1881 //! fv - forward vertical displacement
\r
1882 //! bu - backward horizontal displacement
\r
1883 //! bv - backward vertical displacement
\r
1884 //! pos - new frame position
\r
1885 //! newFrame - new frame
\r
1886 //! buf - temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat;
\r
1887 //! occlusion masks 0, occlusion masks 1,
\r
1888 //! interpolated forward flow 0, interpolated forward flow 1,
\r
1889 //! interpolated backward flow 0, interpolated backward flow 1
\r
1891 CV_EXPORTS void interpolateFrames(const GpuMat& frame0, const GpuMat& frame1,
\r
1892 const GpuMat& fu, const GpuMat& fv,
\r
1893 const GpuMat& bu, const GpuMat& bv,
\r
1894 float pos, GpuMat& newFrame, GpuMat& buf,
\r
1895 Stream& stream = Stream::Null());
\r
1897 CV_EXPORTS void createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMat& vertex, GpuMat& colors);
\r
1900 //////////////////////// Background/foreground segmentation ////////////////////////
\r
1902 // Foreground Object Detection from Videos Containing Complex Background.
\r
1903 // Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian.
\r
1905 class CV_EXPORTS FGDStatModel
\r
1908 struct CV_EXPORTS Params
\r
1910 int Lc; // Quantized levels per 'color' component. Power of two, typically 32, 64 or 128.
\r
1911 int N1c; // Number of color vectors used to model normal background color variation at a given pixel.
\r
1912 int N2c; // Number of color vectors retained at given pixel. Must be > N1c, typically ~ 5/3 of N1c.
\r
1913 // Used to allow the first N1c vectors to adapt over time to changing background.
\r
1915 int Lcc; // Quantized levels per 'color co-occurrence' component. Power of two, typically 16, 32 or 64.
\r
1916 int N1cc; // Number of color co-occurrence vectors used to model normal background color variation at a given pixel.
\r
1917 int N2cc; // Number of color co-occurrence vectors retained at given pixel. Must be > N1cc, typically ~ 5/3 of N1cc.
\r
1918 // Used to allow the first N1cc vectors to adapt over time to changing background.
\r
1920 bool is_obj_without_holes; // If TRUE we ignore holes within foreground blobs. Defaults to TRUE.
\r
1921 int perform_morphing; // Number of erode-dilate-erode foreground-blob cleanup iterations.
\r
1922 // These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.
\r
1924 float alpha1; // How quickly we forget old background pixel values seen. Typically set to 0.1.
\r
1925 float alpha2; // "Controls speed of feature learning". Depends on T. Typical value circa 0.005.
\r
1926 float alpha3; // Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.
\r
1928 float delta; // Affects color and color co-occurrence quantization, typically set to 2.
\r
1929 float T; // A percentage value which determines when new features can be recognized as new background. (Typically 0.9).
\r
1930 float minArea; // Discard foreground blobs whose bounding box is smaller than this threshold.
\r
1936 // out_cn - channels count in output result (can be 3 or 4)
\r
1937 // 4-channels require more memory, but a bit faster
\r
1938 explicit FGDStatModel(int out_cn = 3);
\r
1939 explicit FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3);
\r
1943 void create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params());
\r
1946 int update(const cv::gpu::GpuMat& curFrame);
\r
1948 //8UC3 or 8UC4 reference background image
\r
1949 cv::gpu::GpuMat background;
\r
1951 //8UC1 foreground image
\r
1952 cv::gpu::GpuMat foreground;
\r
1954 std::vector< std::vector<cv::Point> > foreground_regions;
\r
1957 FGDStatModel(const FGDStatModel&);
\r
1958 FGDStatModel& operator=(const FGDStatModel&);
\r
1961 std::auto_ptr<Impl> impl_;
\r
1965 Gaussian Mixture-based Backbround/Foreground Segmentation Algorithm
\r
1967 The class implements the following algorithm:
\r
1968 "An improved adaptive background mixture model for real-time tracking with shadow detection"
\r
1969 P. KadewTraKuPong and R. Bowden,
\r
1970 Proc. 2nd European Workshp on Advanced Video-Based Surveillance Systems, 2001."
\r
1971 http://personal.ee.surrey.ac.uk/Personal/R.Bowden/publications/avbs01/avbs01.pdf
\r
1973 class CV_EXPORTS MOG_GPU
\r
1976 //! the default constructor
\r
1977 MOG_GPU(int nmixtures = -1);
\r
1979 //! re-initiaization method
\r
1980 void initialize(Size frameSize, int frameType);
\r
1982 //! the update operator
\r
1983 void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null());
\r
1985 //! computes a background image which are the mean of all background gaussians
\r
1986 void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
\r
1988 //! releases all inner buffers
\r
1992 float varThreshold;
\r
1993 float backgroundRatio;
\r
2010 The class implements the following algorithm:
\r
2011 "Improved adaptive Gausian mixture model for background subtraction"
\r
2013 International Conference Pattern Recognition, UK, August, 2004.
\r
2014 http://www.zoranz.net/Publications/zivkovic2004ICPR.pdf
\r
2016 class CV_EXPORTS MOG2_GPU
\r
2019 //! the default constructor
\r
2020 MOG2_GPU(int nmixtures = -1);
\r
2022 //! re-initiaization method
\r
2023 void initialize(Size frameSize, int frameType);
\r
2025 //! the update operator
\r
2026 void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
\r
2028 //! computes a background image which are the mean of all background gaussians
\r
2029 void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
\r
2031 //! releases all inner buffers
\r
2035 // you should call initialize after parameters changes
\r
2039 //! here it is the maximum allowed number of mixture components.
\r
2040 //! Actual number is determined dynamically per pixel
\r
2041 float varThreshold;
\r
2042 // threshold on the squared Mahalanobis distance to decide if it is well described
\r
2043 // by the background model or not. Related to Cthr from the paper.
\r
2044 // This does not influence the update of the background. A typical value could be 4 sigma
\r
2045 // and that is varThreshold=4*4=16; Corresponds to Tb in the paper.
\r
2047 /////////////////////////
\r
2048 // less important parameters - things you might change but be carefull
\r
2049 ////////////////////////
\r
2051 float backgroundRatio;
\r
2052 // corresponds to fTB=1-cf from the paper
\r
2053 // TB - threshold when the component becomes significant enough to be included into
\r
2054 // the background model. It is the TB=1-cf from the paper. So I use cf=0.1 => TB=0.
\r
2055 // For alpha=0.001 it means that the mode should exist for approximately 105 frames before
\r
2056 // it is considered foreground
\r
2057 // float noiseSigma;
\r
2058 float varThresholdGen;
\r
2060 //correspondts to Tg - threshold on the squared Mahalan. dist. to decide
\r
2061 //when a sample is close to the existing components. If it is not close
\r
2062 //to any a new component will be generated. I use 3 sigma => Tg=3*3=9.
\r
2063 //Smaller Tg leads to more generated components and higher Tg might make
\r
2064 //lead to small number of components but they can grow too large
\r
2069 //initial variance for the newly generated components.
\r
2070 //It will will influence the speed of adaptation. A good guess should be made.
\r
2071 //A simple way is to estimate the typical standard deviation from the images.
\r
2072 //I used here 10 as a reasonable value
\r
2073 // min and max can be used to further control the variance
\r
2074 float fCT; //CT - complexity reduction prior
\r
2075 //this is related to the number of samples needed to accept that a component
\r
2076 //actually exists. We use CT=0.05 of all the samples. By setting CT=0 you get
\r
2077 //the standard Stauffer&Grimson algorithm (maybe not exact but very similar)
\r
2079 //shadow detection parameters
\r
2080 bool bShadowDetection; //default 1 - do shadow detection
\r
2081 unsigned char nShadowDetection; //do shadow detection - insert this value as the detection result - 127 default value
\r
2083 // Tau - shadow threshold. The shadow is detected if the pixel is darker
\r
2084 //version of the background. Tau is a threshold on how much darker the shadow can be.
\r
2085 //Tau= 0.5 means that if pixel is more than 2 times darker then it is not shadow
\r
2086 //See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003.
\r
2099 GpuMat bgmodelUsedModes_; //keep track of number of modes per pixel
\r
2103 * The class implements the following algorithm:
\r
2104 * "ViBe: A universal background subtraction algorithm for video sequences"
\r
2105 * O. Barnich and M. Van D Roogenbroeck
\r
2106 * IEEE Transactions on Image Processing, 20(6) :1709-1724, June 2011
\r
2108 class CV_EXPORTS VIBE_GPU
\r
2111 //! the default constructor
\r
2112 explicit VIBE_GPU(unsigned long rngSeed = 1234567);
\r
2114 //! re-initiaization method
\r
2115 void initialize(const GpuMat& firstFrame, Stream& stream = Stream::Null());
\r
2117 //! the update operator
\r
2118 void operator()(const GpuMat& frame, GpuMat& fgmask, Stream& stream = Stream::Null());
\r
2120 //! releases all inner buffers
\r
2123 int nbSamples; // number of samples per pixel
\r
2124 int reqMatches; // #_min
\r
2126 int subsamplingFactor; // amount of random subsampling
\r
2131 unsigned long rngSeed_;
\r
2132 GpuMat randStates_;
\r
2138 * Background Subtractor module. Takes a series of images and returns a sequence of mask (8UC1)
\r
2139 * images of the same size, where 255 indicates Foreground and 0 represents Background.
\r
2140 * This class implements an algorithm described in "Visual Tracking of Human Visitors under
\r
2141 * Variable-Lighting Conditions for a Responsive Audio Art Installation," A. Godbehere,
\r
2142 * A. Matsukawa, K. Goldberg, American Control Conference, Montreal, June 2012.
\r
2144 class CV_EXPORTS GMG_GPU
\r
2150 * Validate parameters and set up data structures for appropriate frame size.
\r
2151 * @param frameSize Input frame size
\r
2152 * @param min Minimum value taken on by pixels in image sequence. Usually 0
\r
2153 * @param max Maximum value taken on by pixels in image sequence. e.g. 1.0 or 255
\r
2155 void initialize(Size frameSize, float min = 0.0f, float max = 255.0f);
\r
2158 * Performs single-frame background subtraction and builds up a statistical background image
\r
2160 * @param frame Input frame
\r
2161 * @param fgmask Output mask image representing foreground and background pixels
\r
2162 * @param stream Stream for the asynchronous version
\r
2164 void operator ()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
\r
2166 //! Releases all inner buffers
\r
2169 //! Total number of distinct colors to maintain in histogram.
\r
2172 //! Set between 0.0 and 1.0, determines how quickly features are "forgotten" from histograms.
\r
2173 float learningRate;
\r
2175 //! Number of frames of video to use to initialize histograms.
\r
2176 int numInitializationFrames;
\r
2178 //! Number of discrete levels in each channel to be used in histograms.
\r
2179 int quantizationLevels;
\r
2181 //! Prior probability that any given pixel is a background pixel. A sensitivity parameter.
\r
2182 float backgroundPrior;
\r
2184 //! Value above which pixel is determined to be FG.
\r
2185 float decisionThreshold;
\r
2187 //! Smoothing radius, in pixels, for cleaning up FG image.
\r
2188 int smoothingRadius;
\r
2190 //! Perform background model update.
\r
2191 bool updateBackgroundModel;
\r
2194 float maxVal_, minVal_;
\r
2200 GpuMat nfeatures_;
\r
2204 Ptr<FilterEngine_GPU> boxFilter_;
\r
2208 ////////////////////////////////// Video Encoding //////////////////////////////////
\r
2210 // Works only under Windows
\r
2211 // Supports olny H264 video codec and AVI files
\r
2212 class CV_EXPORTS VideoWriter_GPU
\r
2215 struct EncoderParams;
\r
2217 // Callbacks for video encoder, use it if you want to work with raw video stream
\r
2218 class EncoderCallBack;
\r
2220 enum SurfaceFormat
\r
2231 VideoWriter_GPU();
\r
2232 VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2233 VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2234 VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2235 VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2236 ~VideoWriter_GPU();
\r
2238 // all methods throws cv::Exception if error occurs
\r
2239 void open(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2240 void open(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2241 void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
\r
2242 void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
\r
2244 bool isOpened() const;
\r
2247 void write(const cv::gpu::GpuMat& image, bool lastFrame = false);
\r
2249 struct CV_EXPORTS EncoderParams
\r
2251 int P_Interval; // NVVE_P_INTERVAL,
\r
2252 int IDR_Period; // NVVE_IDR_PERIOD,
\r
2253 int DynamicGOP; // NVVE_DYNAMIC_GOP,
\r
2254 int RCType; // NVVE_RC_TYPE,
\r
2255 int AvgBitrate; // NVVE_AVG_BITRATE,
\r
2256 int PeakBitrate; // NVVE_PEAK_BITRATE,
\r
2257 int QP_Level_Intra; // NVVE_QP_LEVEL_INTRA,
\r
2258 int QP_Level_InterP; // NVVE_QP_LEVEL_INTER_P,
\r
2259 int QP_Level_InterB; // NVVE_QP_LEVEL_INTER_B,
\r
2260 int DeblockMode; // NVVE_DEBLOCK_MODE,
\r
2261 int ProfileLevel; // NVVE_PROFILE_LEVEL,
\r
2262 int ForceIntra; // NVVE_FORCE_INTRA,
\r
2263 int ForceIDR; // NVVE_FORCE_IDR,
\r
2264 int ClearStat; // NVVE_CLEAR_STAT,
\r
2265 int DIMode; // NVVE_SET_DEINTERLACE,
\r
2266 int Presets; // NVVE_PRESETS,
\r
2267 int DisableCabac; // NVVE_DISABLE_CABAC,
\r
2268 int NaluFramingType; // NVVE_CONFIGURE_NALU_FRAMING_TYPE
\r
2269 int DisableSPSPPS; // NVVE_DISABLE_SPS_PPS
\r
2272 explicit EncoderParams(const std::string& configFile);
\r
2274 void load(const std::string& configFile);
\r
2275 void save(const std::string& configFile) const;
\r
2278 EncoderParams getParams() const;
\r
2280 class CV_EXPORTS EncoderCallBack
\r
2290 virtual ~EncoderCallBack() {}
\r
2292 // callback function to signal the start of bitstream that is to be encoded
\r
2293 // must return pointer to buffer
\r
2294 virtual uchar* acquireBitStream(int* bufferSize) = 0;
\r
2296 // callback function to signal that the encoded bitstream is ready to be written to file
\r
2297 virtual void releaseBitStream(unsigned char* data, int size) = 0;
\r
2299 // callback function to signal that the encoding operation on the frame has started
\r
2300 virtual void onBeginFrame(int frameNumber, PicType picType) = 0;
\r
2302 // callback function signals that the encoding operation on the frame has finished
\r
2303 virtual void onEndFrame(int frameNumber, PicType picType) = 0;
\r
2307 VideoWriter_GPU(const VideoWriter_GPU&);
\r
2308 VideoWriter_GPU& operator=(const VideoWriter_GPU&);
\r
2311 std::auto_ptr<Impl> impl_;
\r
2315 ////////////////////////////////// Video Decoding //////////////////////////////////////////
\r
2320 class VideoParser;
\r
2323 class CV_EXPORTS VideoReader_GPU
\r
2337 Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')), // Y,U,V (4:2:0)
\r
2338 Uncompressed_YV12 = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,V,U (4:2:0)
\r
2339 Uncompressed_NV12 = (('N'<<24)|('V'<<16)|('1'<<8)|('2')), // Y,UV (4:2:0)
\r
2340 Uncompressed_YUYV = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')), // YUYV/YUY2 (4:2:2)
\r
2341 Uncompressed_UYVY = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')), // UYVY (4:2:2)
\r
2355 ChromaFormat chromaFormat;
\r
2360 class VideoSource;
\r
2362 VideoReader_GPU();
\r
2363 explicit VideoReader_GPU(const std::string& filename);
\r
2364 explicit VideoReader_GPU(const cv::Ptr<VideoSource>& source);
\r
2366 ~VideoReader_GPU();
\r
2368 void open(const std::string& filename);
\r
2369 void open(const cv::Ptr<VideoSource>& source);
\r
2370 bool isOpened() const;
\r
2374 bool read(GpuMat& image);
\r
2376 FormatInfo format() const;
\r
2377 void dumpFormat(std::ostream& st);
\r
2379 class CV_EXPORTS VideoSource
\r
2382 VideoSource() : frameQueue_(0), videoParser_(0) {}
\r
2383 virtual ~VideoSource() {}
\r
2385 virtual FormatInfo format() const = 0;
\r
2386 virtual void start() = 0;
\r
2387 virtual void stop() = 0;
\r
2388 virtual bool isStarted() const = 0;
\r
2389 virtual bool hasError() const = 0;
\r
2391 void setFrameQueue(detail::FrameQueue* frameQueue) { frameQueue_ = frameQueue; }
\r
2392 void setVideoParser(detail::VideoParser* videoParser) { videoParser_ = videoParser; }
\r
2395 bool parseVideoData(const uchar* data, size_t size, bool endOfStream = false);
\r
2398 VideoSource(const VideoSource&);
\r
2399 VideoSource& operator =(const VideoSource&);
\r
2401 detail::FrameQueue* frameQueue_;
\r
2402 detail::VideoParser* videoParser_;
\r
2406 VideoReader_GPU(const VideoReader_GPU&);
\r
2407 VideoReader_GPU& operator =(const VideoReader_GPU&);
\r
2410 std::auto_ptr<Impl> impl_;
\r
2413 //! removes points (CV_32FC2, single row matrix) with zero mask value
\r
2414 CV_EXPORTS void compactPoints(GpuMat &points0, GpuMat &points1, const GpuMat &mask);
\r
2416 CV_EXPORTS void calcWobbleSuppressionMaps(
\r
2417 int left, int idx, int right, Size size, const Mat &ml, const Mat &mr,
\r
2418 GpuMat &mapx, GpuMat &mapy);
\r
2420 } // namespace gpu
\r
2424 #endif /* __OPENCV_GPU_HPP__ */
\r