include/opencv2/gpu/gpu.hpp
Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                           License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Third party copyrights are property of their respective owners.
00016 //
00017 // Redistribution and use in source and binary forms, with or without modification,
00018 // are permitted provided that the following conditions are met:
00019 //
00020 //   * Redistribution's of source code must retain the above copyright notice,
00021 //     this list of conditions and the following disclaimer.
00022 //
00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
00024 //     this list of conditions and the following disclaimer in the documentation
00025 //     and/or other GpuMaterials provided with the distribution.
00026 //
00027 //   * The name of the copyright holders may not be used to endorse or promote products
00028 //     derived from this software without specific prior written permission.
00029 //
00030 // This software is provided by the copyright holders and contributors "as is" and
00031 // any express or implied warranties, including, but not limited to, the implied
00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
00034 // indirect, incidental, special, exemplary, or consequential damages
00035 // (including, but not limited to, procurement of substitute goods or services;
00036 // loss of use, data, or profits; or business interruption) however caused
00037 // and on any theory of liability, whether in contract, strict liability,
00038 // or tort (including negligence or otherwise) arising in any way out of
00039 // the use of this software, even if advised of the possibility of such damage.
00040 //
00041 //M*/
00042 
00043 #ifndef __OPENCV_GPU_HPP__
00044 #define __OPENCV_GPU_HPP__
00045 
00046 #ifndef SKIP_INCLUDES
00047 #include <vector>
00048 #include <memory>
00049 #include <iosfwd>
00050 #endif
00051 
00052 #include "opencv2/core/gpumat.hpp"
00053 #include "opencv2/imgproc/imgproc.hpp"
00054 #include "opencv2/objdetect/objdetect.hpp"
00055 #include "opencv2/features2d/features2d.hpp"
00056 
00057 namespace cv { namespace gpu {
00058 
00060 // CudaMem is limited cv::Mat with page locked memory allocation.
00061 // Page locked memory is only needed for async and faster coping to GPU.
00062 // It is convertable to cv::Mat header without reference counting
00063 // so you can use it with other opencv functions.
00064 
00065 // Page-locks the matrix m memory and maps it for the device(s)
00066 CV_EXPORTS void registerPageLocked(Mat& m);
00067 // Unmaps the memory of matrix m, and makes it pageable again.
00068 CV_EXPORTS void unregisterPageLocked(Mat& m);
00069 
00070 class CV_EXPORTS CudaMem
00071 {
00072 public:
00073     enum  { ALLOC_PAGE_LOCKED = 1, ALLOC_ZEROCOPY = 2, ALLOC_WRITE_COMBINED = 4 };
00074 
00075     CudaMem();
00076     CudaMem(const CudaMem& m);
00077 
00078     CudaMem(int rows, int cols, int type, int _alloc_type = ALLOC_PAGE_LOCKED);
00079     CudaMem(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
00080 
00081 
00083     explicit CudaMem(const Mat& m, int alloc_type = ALLOC_PAGE_LOCKED);
00084 
00085     ~CudaMem();
00086 
00087     CudaMem& operator = (const CudaMem& m);
00088 
00090     CudaMem clone() const;
00091 
00093     void create(int rows, int cols, int type, int alloc_type = ALLOC_PAGE_LOCKED);
00094     void create(Size size, int type, int alloc_type = ALLOC_PAGE_LOCKED);
00095 
00097     void release();
00098 
00100     Mat createMatHeader() const;
00101     operator Mat() const;
00102 
00104     GpuMat createGpuMatHeader() const;
00105     operator GpuMat() const;
00106 
00107     //returns if host memory can be mapperd to gpu address space;
00108     static bool canMapHostMemory();
00109 
00110     // Please see cv::Mat for descriptions
00111     bool isContinuous() const;
00112     size_t elemSize() const;
00113     size_t elemSize1() const;
00114     int type() const;
00115     int depth() const;
00116     int channels() const;
00117     size_t step1() const;
00118     Size size() const;
00119     bool empty() const;
00120 
00121 
00122     // Please see cv::Mat for descriptions
00123     int flags;
00124     int rows, cols;
00125     size_t step;
00126 
00127     uchar* data;
00128     int* refcount;
00129 
00130     uchar* datastart;
00131     uchar* dataend;
00132 
00133     int alloc_type;
00134 };
00135 
00137 // Encapculates Cuda Stream. Provides interface for async coping.
00138 // Passed to each function that supports async kernel execution.
00139 // Reference counting is enabled
00140 
00141 class CV_EXPORTS Stream
00142 {
00143 public:
00144     Stream();
00145     ~Stream();
00146 
00147     Stream(const Stream&);
00148     Stream& operator=(const Stream&);
00149 
00150     bool queryIfComplete();
00151     void waitForCompletion();
00152 
00154     // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its subMat)
00155     void enqueueDownload(const GpuMat& src, CudaMem& dst);
00156     void enqueueDownload(const GpuMat& src, Mat& dst);
00157 
00159     // Warning! cv::Mat must point to page locked memory (i.e. to CudaMem data or to its ROI)
00160     void enqueueUpload(const CudaMem& src, GpuMat& dst);
00161     void enqueueUpload(const Mat& src, GpuMat& dst);
00162 
00163     void enqueueCopy(const GpuMat& src, GpuMat& dst);
00164 
00165     void enqueueMemSet(GpuMat& src, Scalar val);
00166     void enqueueMemSet(GpuMat& src, Scalar val, const GpuMat& mask);
00167 
00168     // converts matrix type, ex from float to uchar depending on type
00169     void enqueueConvert(const GpuMat& src, GpuMat& dst, int type, double a = 1, double b = 0);
00170 
00171     static Stream& Null();
00172 
00173     operator bool() const;
00174 
00175 private:
00176     void create();
00177     void release();
00178 
00179     struct Impl;
00180     Impl *impl;
00181 
00182     friend struct StreamAccessor;
00183 
00184     explicit Stream(Impl* impl);
00185 };
00186 
00187 
00189 
00196 class CV_EXPORTS BaseRowFilter_GPU
00197 {
00198 public:
00199     BaseRowFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
00200     virtual ~BaseRowFilter_GPU() {}
00201     virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
00202     int ksize, anchor;
00203 };
00204 
00211 class CV_EXPORTS BaseColumnFilter_GPU
00212 {
00213 public:
00214     BaseColumnFilter_GPU(int ksize_, int anchor_) : ksize(ksize_), anchor(anchor_) {}
00215     virtual ~BaseColumnFilter_GPU() {}
00216     virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
00217     int ksize, anchor;
00218 };
00219 
00225 class CV_EXPORTS BaseFilter_GPU
00226 {
00227 public:
00228     BaseFilter_GPU(const Size& ksize_, const Point& anchor_) : ksize(ksize_), anchor(anchor_) {}
00229     virtual ~BaseFilter_GPU() {}
00230     virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
00231     Size ksize;
00232     Point anchor;
00233 };
00234 
00241 class CV_EXPORTS FilterEngine_GPU
00242 {
00243 public:
00244     virtual ~FilterEngine_GPU() {}
00245 
00246     virtual void apply(const GpuMat& src, GpuMat& dst, Rect roi = Rect(0,0,-1,-1), Stream& stream = Stream::Null()) = 0;
00247 };
00248 
00250 CV_EXPORTS Ptr<FilterEngine_GPU> createFilter2D_GPU(const Ptr<BaseFilter_GPU>& filter2D, int srcType, int dstType);
00251 
00253 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>& rowFilter,
00254     const Ptr<BaseColumnFilter_GPU>& columnFilter, int srcType, int bufType, int dstType);
00255 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableFilter_GPU(const Ptr<BaseRowFilter_GPU>& rowFilter,
00256     const Ptr<BaseColumnFilter_GPU>& columnFilter, int srcType, int bufType, int dstType, GpuMat& buf);
00257 
00260 CV_EXPORTS Ptr<BaseRowFilter_GPU> getRowSumFilter_GPU(int srcType, int sumType, int ksize, int anchor = -1);
00261 
00264 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getColumnSumFilter_GPU(int sumType, int dstType, int ksize, int anchor = -1);
00265 
00268 CV_EXPORTS Ptr<BaseFilter_GPU> getBoxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1, -1));
00269 
00271 CV_EXPORTS Ptr<FilterEngine_GPU> createBoxFilter_GPU(int srcType, int dstType, const Size& ksize,
00272     const Point& anchor = Point(-1,-1));
00273 
00278 CV_EXPORTS Ptr<BaseFilter_GPU> getMorphologyFilter_GPU(int op, int type, const Mat& kernel, const Size& ksize,
00279     Point anchor=Point(-1,-1));
00280 
00282 CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat& kernel,
00283     const Point& anchor = Point(-1,-1), int iterations = 1);
00284 CV_EXPORTS Ptr<FilterEngine_GPU> createMorphologyFilter_GPU(int op, int type, const Mat& kernel, GpuMat& buf,
00285     const Point& anchor = Point(-1,-1), int iterations = 1);
00286 
00289 CV_EXPORTS Ptr<BaseFilter_GPU> getLinearFilter_GPU(int srcType, int dstType, const Mat& kernel, Point anchor = Point(-1, -1), int borderType = BORDER_DEFAULT);
00290 
00292 CV_EXPORTS Ptr<FilterEngine_GPU> createLinearFilter_GPU(int srcType, int dstType, const Mat& kernel,
00293     Point anchor = Point(-1,-1), int borderType = BORDER_DEFAULT);
00294 
00303 CV_EXPORTS Ptr<BaseRowFilter_GPU> getLinearRowFilter_GPU(int srcType, int bufType, const Mat& rowKernel,
00304     int anchor = -1, int borderType = BORDER_DEFAULT);
00305 
00314 CV_EXPORTS Ptr<BaseColumnFilter_GPU> getLinearColumnFilter_GPU(int bufType, int dstType, const Mat& columnKernel,
00315     int anchor = -1, int borderType = BORDER_DEFAULT);
00316 
00318 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel,
00319     const Mat& columnKernel, const Point& anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT,
00320     int columnBorderType = -1);
00321 CV_EXPORTS Ptr<FilterEngine_GPU> createSeparableLinearFilter_GPU(int srcType, int dstType, const Mat& rowKernel,
00322     const Mat& columnKernel, GpuMat& buf, const Point& anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT,
00323     int columnBorderType = -1);
00324 
00326 CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize,
00327                                                        int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00328 CV_EXPORTS Ptr<FilterEngine_GPU> createDerivFilter_GPU(int srcType, int dstType, int dx, int dy, int ksize, GpuMat& buf,
00329                                                        int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00330 
00332 CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, double sigma1, double sigma2 = 0,
00333                                                           int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00334 CV_EXPORTS Ptr<FilterEngine_GPU> createGaussianFilter_GPU(int type, Size ksize, GpuMat& buf, double sigma1, double sigma2 = 0,
00335                                                           int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00336 
00338 CV_EXPORTS Ptr<BaseFilter_GPU> getMaxFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
00339 
00341 CV_EXPORTS Ptr<BaseFilter_GPU> getMinFilter_GPU(int srcType, int dstType, const Size& ksize, Point anchor = Point(-1,-1));
00342 
00345 CV_EXPORTS void boxFilter(const GpuMat& src, GpuMat& dst, int ddepth, Size ksize, Point anchor = Point(-1,-1), Stream& stream = Stream::Null());
00346 
00348 static inline void blur(const GpuMat& src, GpuMat& dst, Size ksize, Point anchor = Point(-1,-1), Stream& stream = Stream::Null())
00349 {
00350     boxFilter(src, dst, -1, ksize, anchor, stream);
00351 }
00352 
00354 CV_EXPORTS void erode(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
00355 CV_EXPORTS void erode(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf,
00356                       Point anchor = Point(-1, -1), int iterations = 1,
00357                       Stream& stream = Stream::Null());
00358 
00360 CV_EXPORTS void dilate(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
00361 CV_EXPORTS void dilate(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf,
00362                        Point anchor = Point(-1, -1), int iterations = 1,
00363                        Stream& stream = Stream::Null());
00364 
00366 CV_EXPORTS void morphologyEx(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor = Point(-1, -1), int iterations = 1);
00367 CV_EXPORTS void morphologyEx(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, GpuMat& buf1, GpuMat& buf2,
00368                              Point anchor = Point(-1, -1), int iterations = 1, Stream& stream = Stream::Null());
00369 
00371 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());
00372 
00374 CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY,
00375                             Point anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00376 CV_EXPORTS void sepFilter2D(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY, GpuMat& buf,
00377                             Point anchor = Point(-1,-1), int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1,
00378                             Stream& stream = Stream::Null());
00379 
00381 CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1,
00382                       int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00383 CV_EXPORTS void Sobel(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, int ksize = 3, double scale = 1,
00384                       int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null());
00385 
00387 CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, double scale = 1,
00388                        int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00389 CV_EXPORTS void Scharr(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, double scale = 1,
00390                        int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null());
00391 
00393 CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, double sigma1, double sigma2 = 0,
00394                              int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1);
00395 CV_EXPORTS void GaussianBlur(const GpuMat& src, GpuMat& dst, Size ksize, GpuMat& buf, double sigma1, double sigma2 = 0,
00396                              int rowBorderType = BORDER_DEFAULT, int columnBorderType = -1, Stream& stream = Stream::Null());
00397 
00400 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());
00401 
00402 
00404 
00406 CV_EXPORTS void gemm(const GpuMat& src1, const GpuMat& src2, double alpha,
00407     const GpuMat& src3, double beta, GpuMat& dst, int flags = 0, Stream& stream = Stream::Null());
00408 
00411 CV_EXPORTS void transpose(const GpuMat& src1, GpuMat& dst, Stream& stream = Stream::Null());
00412 
00415 CV_EXPORTS void flip(const GpuMat& a, GpuMat& b, int flipCode, Stream& stream = Stream::Null());
00416 
00420 CV_EXPORTS void LUT(const GpuMat& src, const Mat& lut, GpuMat& dst, Stream& stream = Stream::Null());
00421 
00423 CV_EXPORTS void merge(const GpuMat* src, size_t n, GpuMat& dst, Stream& stream = Stream::Null());
00424 
00426 CV_EXPORTS void merge(const vector<GpuMat>& src, GpuMat& dst, Stream& stream = Stream::Null());
00427 
00429 CV_EXPORTS void split(const GpuMat& src, GpuMat* dst, Stream& stream = Stream::Null());
00430 
00432 CV_EXPORTS void split(const GpuMat& src, vector<GpuMat>& dst, Stream& stream = Stream::Null());
00433 
00436 CV_EXPORTS void magnitude(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null());
00437 
00440 CV_EXPORTS void magnitudeSqr(const GpuMat& xy, GpuMat& magnitude, Stream& stream = Stream::Null());
00441 
00444 CV_EXPORTS void magnitude(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null());
00445 
00448 CV_EXPORTS void magnitudeSqr(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, Stream& stream = Stream::Null());
00449 
00452 CV_EXPORTS void phase(const GpuMat& x, const GpuMat& y, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
00453 
00456 CV_EXPORTS void cartToPolar(const GpuMat& x, const GpuMat& y, GpuMat& magnitude, GpuMat& angle, bool angleInDegrees = false, Stream& stream = Stream::Null());
00457 
00460 CV_EXPORTS void polarToCart(const GpuMat& magnitude, const GpuMat& angle, GpuMat& x, GpuMat& y, bool angleInDegrees = false, Stream& stream = Stream::Null());
00461 
00462 
00464 
00466 CV_EXPORTS void add(const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
00468 CV_EXPORTS void add(const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
00469 
00471 CV_EXPORTS void subtract(const GpuMat& a, const GpuMat& b, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
00473 CV_EXPORTS void subtract(const GpuMat& a, const Scalar& sc, GpuMat& c, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null());
00474 
00476 CV_EXPORTS void multiply(const GpuMat& a, const GpuMat& b, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
00478 CV_EXPORTS void multiply(const GpuMat& a, const Scalar& sc, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
00479 
00481 CV_EXPORTS void divide(const GpuMat& a, const GpuMat& b, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
00483 CV_EXPORTS void divide(const GpuMat& a, const Scalar& sc, GpuMat& c, double scale = 1, int dtype = -1, Stream& stream = Stream::Null());
00485 CV_EXPORTS void divide(double scale, const GpuMat& b, GpuMat& c, int dtype = -1, Stream& stream = Stream::Null());
00486 
00488 CV_EXPORTS void addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst,
00489                             int dtype = -1, Stream& stream = Stream::Null());
00490 
00492 static inline void scaleAdd(const GpuMat& src1, double alpha, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null())
00493 {
00494     addWeighted(src1, alpha, src2, 1.0, 0.0, dst, -1, stream);
00495 }
00496 
00498 CV_EXPORTS void absdiff(const GpuMat& a, const GpuMat& b, GpuMat& c, Stream& stream = Stream::Null());
00500 CV_EXPORTS void absdiff(const GpuMat& a, const Scalar& s, GpuMat& c, Stream& stream = Stream::Null());
00501 
00504 CV_EXPORTS void abs(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
00505 
00508 CV_EXPORTS void sqr(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
00509 
00512 CV_EXPORTS void sqrt(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
00513 
00516 CV_EXPORTS void exp(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null());
00517 
00520 CV_EXPORTS void log(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null());
00521 
00523 //    (dst(i,j) = pow(     src(i,j) , power), if src.type() is integer
00524 //    (dst(i,j) = pow(fabs(src(i,j)), power), otherwise
00526 CV_EXPORTS void pow(const GpuMat& src, double power, GpuMat& dst, Stream& stream = Stream::Null());
00527 
00529 CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop, Stream& stream = Stream::Null());
00530 
00532 CV_EXPORTS void bitwise_not(const GpuMat& src, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
00533 
00535 CV_EXPORTS void bitwise_or(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
00538 CV_EXPORTS void bitwise_or(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null());
00539 
00541 CV_EXPORTS void bitwise_and(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
00544 CV_EXPORTS void bitwise_and(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null());
00545 
00547 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask=GpuMat(), Stream& stream = Stream::Null());
00550 CV_EXPORTS void bitwise_xor(const GpuMat& src1, const Scalar& sc, GpuMat& dst, Stream& stream = Stream::Null());
00551 
00554 CV_EXPORTS void rshift(const GpuMat& src, Scalar_<int> sc, GpuMat& dst, Stream& stream = Stream::Null());
00555 
00558 CV_EXPORTS void lshift(const GpuMat& src, Scalar_<int> sc, GpuMat& dst, Stream& stream = Stream::Null());
00559 
00561 CV_EXPORTS void min(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null());
00562 
00564 CV_EXPORTS void min(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null());
00565 
00567 CV_EXPORTS void max(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null());
00568 
00570 CV_EXPORTS void max(const GpuMat& src1, double src2, GpuMat& dst, Stream& stream = Stream::Null());
00571 
00572 enum { ALPHA_OVER, ALPHA_IN, ALPHA_OUT, ALPHA_ATOP, ALPHA_XOR, ALPHA_PLUS, ALPHA_OVER_PREMUL, ALPHA_IN_PREMUL, ALPHA_OUT_PREMUL,
00573        ALPHA_ATOP_PREMUL, ALPHA_XOR_PREMUL, ALPHA_PLUS_PREMUL, ALPHA_PREMUL};
00574 
00577 CV_EXPORTS void alphaComp(const GpuMat& img1, const GpuMat& img2, GpuMat& dst, int alpha_op, Stream& stream = Stream::Null());
00578 
00579 
00581 
00584 CV_EXPORTS void remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap,
00585                       int interpolation, int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(),
00586                       Stream& stream = Stream::Null());
00587 
00589 CV_EXPORTS void meanShiftFiltering(const GpuMat& src, GpuMat& dst, int sp, int sr,
00590                                    TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1),
00591                                    Stream& stream = Stream::Null());
00592 
00594 CV_EXPORTS void meanShiftProc(const GpuMat& src, GpuMat& dstr, GpuMat& dstsp, int sp, int sr,
00595                               TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1),
00596                               Stream& stream = Stream::Null());
00597 
00599 CV_EXPORTS void meanShiftSegmentation(const GpuMat& src, Mat& dst, int sp, int sr, int minsize,
00600                                       TermCriteria criteria = TermCriteria(TermCriteria::MAX_ITER + TermCriteria::EPS, 5, 1));
00601 
00605 CV_EXPORTS void drawColorDisp(const GpuMat& src_disp, GpuMat& dst_disp, int ndisp, Stream& stream = Stream::Null());
00606 
00612 CV_EXPORTS void reprojectImageTo3D(const GpuMat& disp, GpuMat& xyzw, const Mat& Q, int dst_cn = 4, Stream& stream = Stream::Null());
00613 
00615 CV_EXPORTS void cvtColor(const GpuMat& src, GpuMat& dst, int code, int dcn = 0, Stream& stream = Stream::Null());
00616 
00622 CV_EXPORTS void swapChannels(GpuMat& image, const int dstOrder[4], Stream& stream = Stream::Null());
00623 
00625 CV_EXPORTS void gammaCorrection(const GpuMat& src, GpuMat& dst, bool forward = true, Stream& stream = Stream::Null());
00626 
00628 CV_EXPORTS double threshold(const GpuMat& src, GpuMat& dst, double thresh, double maxval, int type, Stream& stream = Stream::Null());
00629 
00632 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());
00633 
00636 CV_EXPORTS void warpAffine(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR,
00637     int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
00638 
00639 CV_EXPORTS void buildWarpAffineMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null());
00640 
00643 CV_EXPORTS void warpPerspective(const GpuMat& src, GpuMat& dst, const Mat& M, Size dsize, int flags = INTER_LINEAR,
00644     int borderMode = BORDER_CONSTANT, Scalar borderValue = Scalar(), Stream& stream = Stream::Null());
00645 
00646 CV_EXPORTS void buildWarpPerspectiveMaps(const Mat& M, bool inverse, Size dsize, GpuMat& xmap, GpuMat& ymap, Stream& stream = Stream::Null());
00647 
00649 CV_EXPORTS void buildWarpPlaneMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, const Mat &T, float scale,
00650                                    GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
00651 
00653 CV_EXPORTS void buildWarpCylindricalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
00654                                          GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
00655 
00657 CV_EXPORTS void buildWarpSphericalMaps(Size src_size, Rect dst_roi, const Mat &K, const Mat& R, float scale,
00658                                        GpuMat& map_x, GpuMat& map_y, Stream& stream = Stream::Null());
00659 
00663 CV_EXPORTS void rotate(const GpuMat& src, GpuMat& dst, Size dsize, double angle, double xShift = 0, double yShift = 0,
00664                        int interpolation = INTER_LINEAR, Stream& stream = Stream::Null());
00665 
00667 CV_EXPORTS void copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, int borderType,
00668                                const Scalar& value = Scalar(), Stream& stream = Stream::Null());
00669 
00673 CV_EXPORTS void integral(const GpuMat& src, GpuMat& sum, Stream& stream = Stream::Null());
00675 CV_EXPORTS void integralBuffered(const GpuMat& src, GpuMat& sum, GpuMat& buffer, Stream& stream = Stream::Null());
00676 
00680 CV_EXPORTS void sqrIntegral(const GpuMat& src, GpuMat& sqsum, Stream& stream = Stream::Null());
00681 
00683 CV_EXPORTS void columnSum(const GpuMat& src, GpuMat& sum);
00684 
00688 CV_EXPORTS void rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect, Stream& stream = Stream::Null());
00689 
00691 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
00692 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, double k, int borderType = BORDER_REFLECT101);
00693 CV_EXPORTS void cornerHarris(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize, double k,
00694                              int borderType = BORDER_REFLECT101, Stream& stream = Stream::Null());
00695 
00697 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
00698 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, int blockSize, int ksize, int borderType=BORDER_REFLECT101);
00699 CV_EXPORTS void cornerMinEigenVal(const GpuMat& src, GpuMat& dst, GpuMat& Dx, GpuMat& Dy, GpuMat& buf, int blockSize, int ksize,
00700     int borderType=BORDER_REFLECT101, Stream& stream = Stream::Null());
00701 
00704 CV_EXPORTS void mulSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, bool conjB=false, Stream& stream = Stream::Null());
00705 
00708 CV_EXPORTS void mulAndScaleSpectrums(const GpuMat& a, const GpuMat& b, GpuMat& c, int flags, float scale, bool conjB=false, Stream& stream = Stream::Null());
00709 
00721 CV_EXPORTS void dft(const GpuMat& src, GpuMat& dst, Size dft_size, int flags=0, Stream& stream = Stream::Null());
00722 
00723 struct CV_EXPORTS ConvolveBuf
00724 {
00725     Size result_size;
00726     Size block_size;
00727     Size user_block_size;
00728     Size dft_size;
00729     int spect_len;
00730 
00731     GpuMat image_spect, templ_spect, result_spect;
00732     GpuMat image_block, templ_block, result_data;
00733 
00734     void create(Size image_size, Size templ_size);
00735     static Size estimateBlockSize(Size result_size, Size templ_size);
00736 };
00737 
00738 
00742 CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr = false);
00743 CV_EXPORTS void convolve(const GpuMat& image, const GpuMat& templ, GpuMat& result, bool ccorr, ConvolveBuf& buf, Stream& stream = Stream::Null());
00744 
00745 struct CV_EXPORTS MatchTemplateBuf
00746 {
00747     Size user_block_size;
00748     GpuMat imagef, templf;
00749     std::vector<GpuMat> images;
00750     std::vector<GpuMat> image_sums;
00751     std::vector<GpuMat> image_sqsums;
00752 };
00753 
00755 CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, Stream &stream = Stream::Null());
00756 
00758 CV_EXPORTS void matchTemplate(const GpuMat& image, const GpuMat& templ, GpuMat& result, int method, MatchTemplateBuf &buf, Stream& stream = Stream::Null());
00759 
00761 CV_EXPORTS void pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
00762 
00764 CV_EXPORTS void pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
00765 
00768 CV_EXPORTS void blendLinear(const GpuMat& img1, const GpuMat& img2, const GpuMat& weights1, const GpuMat& weights2,
00769                             GpuMat& result, Stream& stream = Stream::Null());
00770 
00772 CV_EXPORTS void bilateralFilter(const GpuMat& src, GpuMat& dst, int kernel_size, float sigma_color, float sigma_spatial,
00773                                 int borderMode = BORDER_DEFAULT, Stream& stream = Stream::Null());
00774 
00776 CV_EXPORTS void nonLocalMeans(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, int borderMode = BORDER_DEFAULT, Stream& s = Stream::Null());
00777 
00779 class CV_EXPORTS FastNonLocalMeansDenoising
00780 {
00781 public:
00783     void simpleMethod(const GpuMat& src, GpuMat& dst, float h, int search_window = 21, int block_size = 7, Stream& s = Stream::Null());
00784 
00786     void labMethod(const GpuMat& src, GpuMat& dst, float h_luminance, float h_color, int search_window = 21, int block_size = 7, Stream& s = Stream::Null());
00787 
00788 private:
00789 
00790     GpuMat buffer, extended_src_buffer;
00791     GpuMat lab, l, ab;
00792 };
00793 
00794 
00795 struct CV_EXPORTS CannyBuf;
00796 
00797 CV_EXPORTS void Canny(const GpuMat& image, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
00798 CV_EXPORTS void Canny(const GpuMat& image, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, int apperture_size = 3, bool L2gradient = false);
00799 CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false);
00800 CV_EXPORTS void Canny(const GpuMat& dx, const GpuMat& dy, CannyBuf& buf, GpuMat& edges, double low_thresh, double high_thresh, bool L2gradient = false);
00801 
00802 struct CV_EXPORTS CannyBuf
00803 {
00804     CannyBuf() {}
00805     explicit CannyBuf(const Size& image_size, int apperture_size = 3) {create(image_size, apperture_size);}
00806     CannyBuf(const GpuMat& dx_, const GpuMat& dy_);
00807 
00808     void create(const Size& image_size, int apperture_size = 3);
00809 
00810     void release();
00811 
00812     GpuMat dx, dy;
00813     GpuMat dx_buf, dy_buf;
00814     GpuMat edgeBuf;
00815     GpuMat trackBuf1, trackBuf2;
00816     Ptr<FilterEngine_GPU> filterDX, filterDY;
00817 };
00818 
00819 class CV_EXPORTS ImagePyramid
00820 {
00821 public:
00822     inline ImagePyramid() : nLayers_(0) {}
00823     inline ImagePyramid(const GpuMat& img, int nLayers, Stream& stream = Stream::Null())
00824     {
00825         build(img, nLayers, stream);
00826     }
00827 
00828     void build(const GpuMat& img, int nLayers, Stream& stream = Stream::Null());
00829 
00830     void getLayer(GpuMat& outImg, Size outRoi, Stream& stream = Stream::Null()) const;
00831 
00832     inline void release()
00833     {
00834         layer0_.release();
00835         pyramid_.clear();
00836         nLayers_ = 0;
00837     }
00838 
00839 private:
00840     GpuMat layer0_;
00841     std::vector<GpuMat> pyramid_;
00842     int nLayers_;
00843 };
00844 
00846 
00847 struct HoughLinesBuf
00848 {
00849     GpuMat accum;
00850     GpuMat list;
00851 };
00852 
00853 CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
00854 CV_EXPORTS void HoughLines(const GpuMat& src, GpuMat& lines, HoughLinesBuf& buf, float rho, float theta, int threshold, bool doSort = false, int maxLines = 4096);
00855 CV_EXPORTS void HoughLinesDownload(const GpuMat& d_lines, OutputArray h_lines, OutputArray h_votes = noArray());
00856 
00858 
00859 struct HoughCirclesBuf
00860 {
00861     GpuMat edges;
00862     GpuMat accum;
00863     GpuMat list;
00864     CannyBuf cannyBuf;
00865 };
00866 
00867 CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096);
00868 CV_EXPORTS void HoughCircles(const GpuMat& src, GpuMat& circles, HoughCirclesBuf& buf, int method, float dp, float minDist, int cannyThreshold, int votesThreshold, int minRadius, int maxRadius, int maxCircles = 4096);
00869 CV_EXPORTS void HoughCirclesDownload(const GpuMat& d_circles, OutputArray h_circles);
00870 
00874 class CV_EXPORTS GeneralizedHough_GPU : public Algorithm
00875 {
00876 public:
00877     static Ptr<GeneralizedHough_GPU> create(int method);
00878 
00879     virtual ~GeneralizedHough_GPU();
00880 
00882     void setTemplate(const GpuMat& templ, int cannyThreshold = 100, Point templCenter = Point(-1, -1));
00883     void setTemplate(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, Point templCenter = Point(-1, -1));
00884 
00886     void detect(const GpuMat& image, GpuMat& positions, int cannyThreshold = 100);
00887     void detect(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, GpuMat& positions);
00888 
00889     void download(const GpuMat& d_positions, OutputArray h_positions, OutputArray h_votes = noArray());
00890 
00891     void release();
00892 
00893 protected:
00894     virtual void setTemplateImpl(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, Point templCenter) = 0;
00895     virtual void detectImpl(const GpuMat& edges, const GpuMat& dx, const GpuMat& dy, GpuMat& positions) = 0;
00896     virtual void releaseImpl() = 0;
00897 
00898 private:
00899     GpuMat edges_;
00900     CannyBuf cannyBuf_;
00901 };
00902 
00904 
00907 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev);
00909 CV_EXPORTS void meanStdDev(const GpuMat& mtx, Scalar& mean, Scalar& stddev, GpuMat& buf);
00910 
00914 CV_EXPORTS double norm(const GpuMat& src1, int normType=NORM_L2);
00915 
00919 CV_EXPORTS double norm(const GpuMat& src1, int normType, GpuMat& buf);
00920 
00924 CV_EXPORTS double norm(const GpuMat& src1, const GpuMat& src2, int normType=NORM_L2);
00925 
00928 CV_EXPORTS Scalar sum(const GpuMat& src);
00929 
00932 CV_EXPORTS Scalar sum(const GpuMat& src, GpuMat& buf);
00933 
00936 CV_EXPORTS Scalar absSum(const GpuMat& src);
00937 
00940 CV_EXPORTS Scalar absSum(const GpuMat& src, GpuMat& buf);
00941 
00944 CV_EXPORTS Scalar sqrSum(const GpuMat& src);
00945 
00948 CV_EXPORTS Scalar sqrSum(const GpuMat& src, GpuMat& buf);
00949 
00951 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal=0, const GpuMat& mask=GpuMat());
00952 
00954 CV_EXPORTS void minMax(const GpuMat& src, double* minVal, double* maxVal, const GpuMat& mask, GpuMat& buf);
00955 
00957 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal=0, Point* minLoc=0, Point* maxLoc=0,
00958                           const GpuMat& mask=GpuMat());
00959 
00961 CV_EXPORTS void minMaxLoc(const GpuMat& src, double* minVal, double* maxVal, Point* minLoc, Point* maxLoc,
00962                           const GpuMat& mask, GpuMat& valbuf, GpuMat& locbuf);
00963 
00965 CV_EXPORTS int countNonZero(const GpuMat& src);
00966 
00968 CV_EXPORTS int countNonZero(const GpuMat& src, GpuMat& buf);
00969 
00971 CV_EXPORTS void reduce(const GpuMat& mtx, GpuMat& vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null());
00972 
00973 
00975 
00976 CV_EXPORTS void transformPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
00977                                 GpuMat& dst, Stream& stream = Stream::Null());
00978 
00979 CV_EXPORTS void projectPoints(const GpuMat& src, const Mat& rvec, const Mat& tvec,
00980                               const Mat& camera_mat, const Mat& dist_coef, GpuMat& dst,
00981                               Stream& stream = Stream::Null());
00982 
00983 CV_EXPORTS void solvePnPRansac(const Mat& object, const Mat& image, const Mat& camera_mat,
00984                                const Mat& dist_coef, Mat& rvec, Mat& tvec, bool use_extrinsic_guess=false,
00985                                int num_iters=100, float max_dist=8.0, int min_inlier_count=100,
00986                                std::vector<int>* inliers=NULL);
00987 
00989 
00991 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels,
00992                          GpuMat& buf, Stream& stream = Stream::Null());
00993 
00995 CV_EXPORTS void graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& topLeft, GpuMat& topRight,
00996                          GpuMat& bottom, GpuMat& bottomLeft, GpuMat& bottomRight,
00997                          GpuMat& labels,
00998                          GpuMat& buf, Stream& stream = Stream::Null());
00999 
01001 CV_EXPORTS void connectivityMask(const GpuMat& image, GpuMat& mask, const cv::Scalar& lo, const cv::Scalar& hi, Stream& stream = Stream::Null());
01002 
01004 CV_EXPORTS void labelComponents(const GpuMat& mask, GpuMat& components, int flags = 0, Stream& stream = Stream::Null());
01005 
01007 
01009 CV_EXPORTS void evenLevels(GpuMat& levels, int nLevels, int lowerLevel, int upperLevel);
01013 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
01014 CV_EXPORTS void histEven(const GpuMat& src, GpuMat& hist, GpuMat& buf, int histSize, int lowerLevel, int upperLevel, Stream& stream = Stream::Null());
01019 CV_EXPORTS void histEven(const GpuMat& src, GpuMat hist[4], int histSize[4], int lowerLevel[4], int upperLevel[4], Stream& stream = Stream::Null());
01020 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());
01025 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, Stream& stream = Stream::Null());
01026 CV_EXPORTS void histRange(const GpuMat& src, GpuMat& hist, const GpuMat& levels, GpuMat& buf, Stream& stream = Stream::Null());
01032 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], Stream& stream = Stream::Null());
01033 CV_EXPORTS void histRange(const GpuMat& src, GpuMat hist[4], const GpuMat levels[4], GpuMat& buf, Stream& stream = Stream::Null());
01034 
01037 CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, Stream& stream = Stream::Null());
01038 CV_EXPORTS void calcHist(const GpuMat& src, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null());
01039 
01041 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null());
01042 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, Stream& stream = Stream::Null());
01043 CV_EXPORTS void equalizeHist(const GpuMat& src, GpuMat& dst, GpuMat& hist, GpuMat& buf, Stream& stream = Stream::Null());
01044 
01046 
01047 class CV_EXPORTS StereoBM_GPU
01048 {
01049 public:
01050     enum { BASIC_PRESET = 0, PREFILTER_XSOBEL = 1 };
01051 
01052     enum { DEFAULT_NDISP = 64, DEFAULT_WINSZ = 19 };
01053 
01055     StereoBM_GPU();
01057     StereoBM_GPU(int preset, int ndisparities = DEFAULT_NDISP, int winSize = DEFAULT_WINSZ);
01058 
01061     void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
01062 
01064     // if current GPU will be faster than CPU in this algorithm.
01065     // It queries current active device.
01066     static bool checkIfGpuCallReasonable();
01067 
01068     int preset;
01069     int ndisp;
01070     int winSize;
01071 
01072     // If avergeTexThreshold  == 0 => post procesing is disabled
01073     // If avergeTexThreshold != 0 then disparity is set 0 in each point (x,y) where for left image
01074     // SumOfHorizontalGradiensInWindow(x, y, winSize) < (winSize * winSize) * avergeTexThreshold
01075     // i.e. input left image is low textured.
01076     float avergeTexThreshold;
01077 
01078 private:
01079     GpuMat minSSD, leBuf, riBuf;
01080 };
01081 
01083 // "Efficient Belief Propagation for Early Vision"
01084 // P.Felzenszwalb
01085 
01086 class CV_EXPORTS StereoBeliefPropagation
01087 {
01088 public:
01089     enum { DEFAULT_NDISP  = 64 };
01090     enum { DEFAULT_ITERS  = 5  };
01091     enum { DEFAULT_LEVELS = 5  };
01092 
01093     static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels);
01094 
01096     explicit StereoBeliefPropagation(int ndisp  = DEFAULT_NDISP,
01097                                      int iters  = DEFAULT_ITERS,
01098                                      int levels = DEFAULT_LEVELS,
01099                                      int msg_type = CV_32F);
01100 
01107     StereoBeliefPropagation(int ndisp, int iters, int levels,
01108         float max_data_term, float data_weight,
01109         float max_disc_term, float disc_single_jump,
01110         int msg_type = CV_32F);
01111 
01114     void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
01115 
01116 
01118     void operator()(const GpuMat& data, GpuMat& disparity, Stream& stream = Stream::Null());
01119 
01120     int ndisp;
01121 
01122     int iters;
01123     int levels;
01124 
01125     float max_data_term;
01126     float data_weight;
01127     float max_disc_term;
01128     float disc_single_jump;
01129 
01130     int msg_type;
01131 private:
01132     GpuMat u, d, l, r, u2, d2, l2, r2;
01133     std::vector<GpuMat> datas;
01134     GpuMat out;
01135 };
01136 
01138 // "A Constant-Space Belief Propagation Algorithm for Stereo Matching"
01139 // Qingxiong Yang, Liang Wang, Narendra Ahuja
01140 // http://vision.ai.uiuc.edu/~qyang6/
01141 
01142 class CV_EXPORTS StereoConstantSpaceBP
01143 {
01144 public:
01145     enum { DEFAULT_NDISP    = 128 };
01146     enum { DEFAULT_ITERS    = 8   };
01147     enum { DEFAULT_LEVELS   = 4   };
01148     enum { DEFAULT_NR_PLANE = 4   };
01149 
01150     static void estimateRecommendedParams(int width, int height, int& ndisp, int& iters, int& levels, int& nr_plane);
01151 
01153     explicit StereoConstantSpaceBP(int ndisp    = DEFAULT_NDISP,
01154                                    int iters    = DEFAULT_ITERS,
01155                                    int levels   = DEFAULT_LEVELS,
01156                                    int nr_plane = DEFAULT_NR_PLANE,
01157                                    int msg_type = CV_32F);
01158 
01162     StereoConstantSpaceBP(int ndisp, int iters, int levels, int nr_plane,
01163         float max_data_term, float data_weight, float max_disc_term, float disc_single_jump,
01164         int min_disp_th = 0,
01165         int msg_type = CV_32F);
01166 
01169     void operator()(const GpuMat& left, const GpuMat& right, GpuMat& disparity, Stream& stream = Stream::Null());
01170 
01171     int ndisp;
01172 
01173     int iters;
01174     int levels;
01175 
01176     int nr_plane;
01177 
01178     float max_data_term;
01179     float data_weight;
01180     float max_disc_term;
01181     float disc_single_jump;
01182 
01183     int min_disp_th;
01184 
01185     int msg_type;
01186 
01187     bool use_local_init_data_cost;
01188 private:
01189     GpuMat messages_buffers;
01190 
01191     GpuMat temp;
01192     GpuMat out;
01193 };
01194 
01196 // Disparity map refinement using joint bilateral filtering given a single color image.
01197 // Qingxiong Yang, Liang Wang, Narendra Ahuja
01198 // http://vision.ai.uiuc.edu/~qyang6/
01199 
01200 class CV_EXPORTS DisparityBilateralFilter
01201 {
01202 public:
01203     enum { DEFAULT_NDISP  = 64 };
01204     enum { DEFAULT_RADIUS = 3 };
01205     enum { DEFAULT_ITERS  = 1 };
01206 
01208     explicit DisparityBilateralFilter(int ndisp = DEFAULT_NDISP, int radius = DEFAULT_RADIUS, int iters = DEFAULT_ITERS);
01209 
01213     DisparityBilateralFilter(int ndisp, int radius, int iters, float edge_threshold, float max_disc_threshold, float sigma_range);
01214 
01217     void operator()(const GpuMat& disparity, const GpuMat& image, GpuMat& dst, Stream& stream = Stream::Null());
01218 
01219 private:
01220     int ndisp;
01221     int radius;
01222     int iters;
01223 
01224     float edge_threshold;
01225     float max_disc_threshold;
01226     float sigma_range;
01227 
01228     GpuMat table_color;
01229     GpuMat table_space;
01230 };
01231 
01232 
01234 struct CV_EXPORTS HOGConfidence
01235 {
01236    double scale;
01237    vector<Point> locations;
01238    vector<double> confidences;
01239    vector<double> part_scores[4];
01240 };
01241 
01242 struct CV_EXPORTS HOGDescriptor
01243 {
01244     enum { DEFAULT_WIN_SIGMA = -1 };
01245     enum { DEFAULT_NLEVELS = 64 };
01246     enum { DESCR_FORMAT_ROW_BY_ROW, DESCR_FORMAT_COL_BY_COL };
01247 
01248     HOGDescriptor(Size win_size=Size(64, 128), Size block_size=Size(16, 16),
01249                   Size block_stride=Size(8, 8), Size cell_size=Size(8, 8),
01250                   int nbins=9, double win_sigma=DEFAULT_WIN_SIGMA,
01251                   double threshold_L2hys=0.2, bool gamma_correction=true,
01252                   int nlevels=DEFAULT_NLEVELS);
01253 
01254     size_t getDescriptorSize() const;
01255     size_t getBlockHistogramSize() const;
01256 
01257     void setSVMDetector(const vector<float>& detector);
01258 
01259     static vector<float> getDefaultPeopleDetector();
01260     static vector<float> getPeopleDetector48x96();
01261     static vector<float> getPeopleDetector64x128();
01262 
01263     void detect(const GpuMat& img, vector<Point>& found_locations,
01264                 double hit_threshold=0, Size win_stride=Size(),
01265                 Size padding=Size());
01266 
01267     void detectMultiScale(const GpuMat& img, vector<Rect>& found_locations,
01268                           double hit_threshold=0, Size win_stride=Size(),
01269                           Size padding=Size(), double scale0=1.05,
01270                           int group_threshold=2);
01271 
01272     void computeConfidence(const GpuMat& img, vector<Point>& hits, double hit_threshold,
01273                                                 Size win_stride, Size padding, vector<Point>& locations, vector<double>& confidences);
01274 
01275     void computeConfidenceMultiScale(const GpuMat& img, vector<Rect>& found_locations,
01276                                                                     double hit_threshold, Size win_stride, Size padding,
01277                                                                     vector<HOGConfidence> &conf_out, int group_threshold);
01278 
01279     void getDescriptors(const GpuMat& img, Size win_stride,
01280                         GpuMat& descriptors,
01281                         int descr_format=DESCR_FORMAT_COL_BY_COL);
01282 
01283     Size win_size;
01284     Size block_size;
01285     Size block_stride;
01286     Size cell_size;
01287     int nbins;
01288     double win_sigma;
01289     double threshold_L2hys;
01290     bool gamma_correction;
01291     int nlevels;
01292 
01293 protected:
01294     void computeBlockHistograms(const GpuMat& img);
01295     void computeGradient(const GpuMat& img, GpuMat& grad, GpuMat& qangle);
01296 
01297     double getWinSigma() const;
01298     bool checkDetectorSize() const;
01299 
01300     static int numPartsWithin(int size, int part_size, int stride);
01301     static Size numPartsWithin(Size size, Size part_size, Size stride);
01302 
01303     // Coefficients of the separating plane
01304     float free_coef;
01305     GpuMat detector;
01306 
01307     // Results of the last classification step
01308     GpuMat labels, labels_buf;
01309     Mat labels_host;
01310 
01311     // Results of the last histogram evaluation step
01312     GpuMat block_hists, block_hists_buf;
01313 
01314     // Gradients conputation results
01315     GpuMat grad, qangle, grad_buf, qangle_buf;
01316 
01317     // returns subbuffer with required size, reallocates buffer if nessesary.
01318     static GpuMat getBuffer(const Size& sz, int type, GpuMat& buf);
01319     static GpuMat getBuffer(int rows, int cols, int type, GpuMat& buf);
01320 
01321     std::vector<GpuMat> image_scales;
01322 };
01323 
01324 
01326 
01327 class CV_EXPORTS BruteForceMatcher_GPU_base
01328 {
01329 public:
01330     enum DistType {L1Dist = 0, L2Dist, HammingDist};
01331 
01332     explicit BruteForceMatcher_GPU_base(DistType distType = L2Dist);
01333 
01334     // Add descriptors to train descriptor collection
01335     void add(const std::vector<GpuMat>& descCollection);
01336 
01337     // Get train descriptors collection
01338     const std::vector<GpuMat>& getTrainDescriptors() const;
01339 
01340     // Clear train descriptors collection
01341     void clear();
01342 
01343     // Return true if there are not train descriptors in collection
01344     bool empty() const;
01345 
01346     // Return true if the matcher supports mask in match methods
01347     bool isMaskSupported() const;
01348 
01349     // Find one best match for each query descriptor
01350     void matchSingle(const GpuMat& query, const GpuMat& train,
01351         GpuMat& trainIdx, GpuMat& distance,
01352         const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
01353 
01354     // Download trainIdx and distance and convert it to CPU vector with DMatch
01355     static void matchDownload(const GpuMat& trainIdx, const GpuMat& distance, std::vector<DMatch>& matches);
01356     // Convert trainIdx and distance to vector with DMatch
01357     static void matchConvert(const Mat& trainIdx, const Mat& distance, std::vector<DMatch>& matches);
01358 
01359     // Find one best match for each query descriptor
01360     void match(const GpuMat& query, const GpuMat& train, std::vector<DMatch>& matches, const GpuMat& mask = GpuMat());
01361 
01362     // Make gpu collection of trains and masks in suitable format for matchCollection function
01363     void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection, const std::vector<GpuMat>& masks = std::vector<GpuMat>());
01364 
01365     // Find one best match from train collection for each query descriptor
01366     void matchCollection(const GpuMat& query, const GpuMat& trainCollection,
01367         GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
01368         const GpuMat& masks = GpuMat(), Stream& stream = Stream::Null());
01369 
01370     // Download trainIdx, imgIdx and distance and convert it to vector with DMatch
01371     static void matchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, std::vector<DMatch>& matches);
01372     // Convert trainIdx, imgIdx and distance to vector with DMatch
01373     static void matchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, std::vector<DMatch>& matches);
01374 
01375     // Find one best match from train collection for each query descriptor.
01376     void match(const GpuMat& query, std::vector<DMatch>& matches, const std::vector<GpuMat>& masks = std::vector<GpuMat>());
01377 
01378     // Find k best matches for each query descriptor (in increasing order of distances)
01379     void knnMatchSingle(const GpuMat& query, const GpuMat& train,
01380         GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k,
01381         const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
01382 
01383     // Download trainIdx and distance and convert it to vector with DMatch
01384     // compactResult is used when mask is not empty. If compactResult is false matches
01385     // vector will have the same size as queryDescriptors rows. If compactResult is true
01386     // matches vector will not contain matches for fully masked out query descriptors.
01387     static void knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance,
01388         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01389     // Convert trainIdx and distance to vector with DMatch
01390     static void knnMatchConvert(const Mat& trainIdx, const Mat& distance,
01391         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01392 
01393     // Find k best matches for each query descriptor (in increasing order of distances).
01394     // compactResult is used when mask is not empty. If compactResult is false matches
01395     // vector will have the same size as queryDescriptors rows. If compactResult is true
01396     // matches vector will not contain matches for fully masked out query descriptors.
01397     void knnMatch(const GpuMat& query, const GpuMat& train,
01398         std::vector< std::vector<DMatch> >& matches, int k, const GpuMat& mask = GpuMat(),
01399         bool compactResult = false);
01400 
01401     // Find k best matches from train collection for each query descriptor (in increasing order of distances)
01402     void knnMatch2Collection(const GpuMat& query, const GpuMat& trainCollection,
01403         GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance,
01404         const GpuMat& maskCollection = GpuMat(), Stream& stream = Stream::Null());
01405 
01406     // Download trainIdx and distance and convert it to vector with DMatch
01407     // compactResult is used when mask is not empty. If compactResult is false matches
01408     // vector will have the same size as queryDescriptors rows. If compactResult is true
01409     // matches vector will not contain matches for fully masked out query descriptors.
01410     static void knnMatch2Download(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance,
01411         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01412     // Convert trainIdx and distance to vector with DMatch
01413     static void knnMatch2Convert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance,
01414         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01415 
01416     // Find k best matches  for each query descriptor (in increasing order of distances).
01417     // compactResult is used when mask is not empty. If compactResult is false matches
01418     // vector will have the same size as queryDescriptors rows. If compactResult is true
01419     // matches vector will not contain matches for fully masked out query descriptors.
01420     void knnMatch(const GpuMat& query, std::vector< std::vector<DMatch> >& matches, int k,
01421         const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
01422 
01423     // Find best matches for each query descriptor which have distance less than maxDistance.
01424     // nMatches.at<int>(0, queryIdx) will contain matches count for queryIdx.
01425     // carefully nMatches can be greater than trainIdx.cols - it means that matcher didn't find all matches,
01426     // because it didn't have enough memory.
01427     // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nTrain / 100), 10),
01428     // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
01429     // Matches doesn't sorted.
01430     void radiusMatchSingle(const GpuMat& query, const GpuMat& train,
01431         GpuMat& trainIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance,
01432         const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null());
01433 
01434     // Download trainIdx, nMatches and distance and convert it to vector with DMatch.
01435     // matches will be sorted in increasing order of distances.
01436     // compactResult is used when mask is not empty. If compactResult is false matches
01437     // vector will have the same size as queryDescriptors rows. If compactResult is true
01438     // matches vector will not contain matches for fully masked out query descriptors.
01439     static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, const GpuMat& nMatches,
01440         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01441     // Convert trainIdx, nMatches and distance to vector with DMatch.
01442     static void radiusMatchConvert(const Mat& trainIdx, const Mat& distance, const Mat& nMatches,
01443         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01444 
01445     // Find best matches for each query descriptor which have distance less than maxDistance
01446     // in increasing order of distances).
01447     void radiusMatch(const GpuMat& query, const GpuMat& train,
01448         std::vector< std::vector<DMatch> >& matches, float maxDistance,
01449         const GpuMat& mask = GpuMat(), bool compactResult = false);
01450 
01451     // Find best matches for each query descriptor which have distance less than maxDistance.
01452     // If trainIdx is empty, then trainIdx and distance will be created with size nQuery x max((nQuery / 100), 10),
01453     // otherwize user can pass own allocated trainIdx and distance with size nQuery x nMaxMatches
01454     // Matches doesn't sorted.
01455     void radiusMatchCollection(const GpuMat& query, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance,
01456         const std::vector<GpuMat>& masks = std::vector<GpuMat>(), Stream& stream = Stream::Null());
01457 
01458     // Download trainIdx, imgIdx, nMatches and distance and convert it to vector with DMatch.
01459     // matches will be sorted in increasing order of distances.
01460     // compactResult is used when mask is not empty. If compactResult is false matches
01461     // vector will have the same size as queryDescriptors rows. If compactResult is true
01462     // matches vector will not contain matches for fully masked out query descriptors.
01463     static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, const GpuMat& nMatches,
01464         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01465     // Convert trainIdx, nMatches and distance to vector with DMatch.
01466     static void radiusMatchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, const Mat& nMatches,
01467         std::vector< std::vector<DMatch> >& matches, bool compactResult = false);
01468 
01469     // Find best matches from train collection for each query descriptor which have distance less than
01470     // maxDistance (in increasing order of distances).
01471     void radiusMatch(const GpuMat& query, std::vector< std::vector<DMatch> >& matches, float maxDistance,
01472         const std::vector<GpuMat>& masks = std::vector<GpuMat>(), bool compactResult = false);
01473 
01474     DistType distType;
01475 
01476 private:
01477     std::vector<GpuMat> trainDescCollection;
01478 };
01479 
01480 template <class Distance>
01481 class CV_EXPORTS BruteForceMatcher_GPU;
01482 
01483 template <typename T>
01484 class CV_EXPORTS BruteForceMatcher_GPU< L1<T> > : public BruteForceMatcher_GPU_base
01485 {
01486 public:
01487     explicit BruteForceMatcher_GPU() : BruteForceMatcher_GPU_base(L1Dist) {}
01488     explicit BruteForceMatcher_GPU(L1<T> /*d*/) : BruteForceMatcher_GPU_base(L1Dist) {}
01489 };
01490 template <typename T>
01491 class CV_EXPORTS BruteForceMatcher_GPU< L2<T> > : public BruteForceMatcher_GPU_base
01492 {
01493 public:
01494     explicit BruteForceMatcher_GPU() : BruteForceMatcher_GPU_base(L2Dist) {}
01495     explicit BruteForceMatcher_GPU(L2<T> /*d*/) : BruteForceMatcher_GPU_base(L2Dist) {}
01496 };
01497 template <> class CV_EXPORTS BruteForceMatcher_GPU< Hamming > : public BruteForceMatcher_GPU_base
01498 {
01499 public:
01500     explicit BruteForceMatcher_GPU() : BruteForceMatcher_GPU_base(HammingDist) {}
01501     explicit BruteForceMatcher_GPU(Hamming /*d*/) : BruteForceMatcher_GPU_base(HammingDist) {}
01502 };
01503 
01505 // The cascade classifier class for object detection: supports old haar and new lbp xlm formats and nvbin for haar cascades olny.
01506 class CV_EXPORTS CascadeClassifier_GPU
01507 {
01508 public:
01509     CascadeClassifier_GPU();
01510     CascadeClassifier_GPU(const std::string& filename);
01511     ~CascadeClassifier_GPU();
01512 
01513     bool empty() const;
01514     bool load(const std::string& filename);
01515     void release();
01516 
01517     /* returns number of detected objects */
01518     int detectMultiScale(const GpuMat& image, GpuMat& objectsBuf, double scaleFactor = 1.1, int minNeighbors = 4, Size minSize = Size());
01519 
01520     bool findLargestObject;
01521     bool visualizeInPlace;
01522 
01523     Size getClassifierSize() const;
01524 
01525 private:
01526 
01527     struct CascadeClassifierImpl;
01528     CascadeClassifierImpl* impl;
01529     struct HaarCascade;
01530     struct LbpCascade;
01531     friend class CascadeClassifier_GPU_LBP;
01532 };
01533 
01535 
01536 class CV_EXPORTS SURF_GPU
01537 {
01538 public:
01539     enum KeypointLayout
01540     {
01541         X_ROW = 0,
01542         Y_ROW,
01543         LAPLACIAN_ROW,
01544         OCTAVE_ROW,
01545         SIZE_ROW,
01546         ANGLE_ROW,
01547         HESSIAN_ROW,
01548         ROWS_COUNT
01549     };
01550 
01552     SURF_GPU();
01554     explicit SURF_GPU(double _hessianThreshold, int _nOctaves=4,
01555          int _nOctaveLayers=2, bool _extended=false, float _keypointsRatio=0.01f, bool _upright = false);
01556 
01558     int descriptorSize() const;
01559 
01561     void uploadKeypoints(const vector<KeyPoint>& keypoints, GpuMat& keypointsGPU);
01563     void downloadKeypoints(const GpuMat& keypointsGPU, vector<KeyPoint>& keypoints);
01564 
01566     void downloadDescriptors(const GpuMat& descriptorsGPU, vector<float>& descriptors);
01567 
01578     void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints);
01581     void operator()(const GpuMat& img, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors,
01582         bool useProvidedKeypoints = false);
01583 
01584     void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
01585     void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors,
01586         bool useProvidedKeypoints = false);
01587 
01588     void operator()(const GpuMat& img, const GpuMat& mask, std::vector<KeyPoint>& keypoints, std::vector<float>& descriptors,
01589         bool useProvidedKeypoints = false);
01590 
01591     void releaseMemory();
01592 
01593     // SURF parameters
01594     double hessianThreshold;
01595     int nOctaves;
01596     int nOctaveLayers;
01597     bool extended;
01598     bool upright;
01599 
01601     float keypointsRatio;
01602 
01603     GpuMat sum, mask1, maskSum, intBuffer;
01604 
01605     GpuMat det, trace;
01606 
01607     GpuMat maxPosBuffer;
01608 };
01609 
01611 
01612 class CV_EXPORTS FAST_GPU
01613 {
01614 public:
01615     enum
01616     {
01617         LOCATION_ROW = 0,
01618         RESPONSE_ROW,
01619         ROWS_COUNT
01620     };
01621 
01622     // all features have same size
01623     static const int FEATURE_SIZE = 7;
01624 
01625     explicit FAST_GPU(int threshold, bool nonmaxSupression = true, double keypointsRatio = 0.05);
01626 
01629     void operator ()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints);
01630     void operator ()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
01631 
01633     void downloadKeypoints(const GpuMat& d_keypoints, std::vector<KeyPoint>& keypoints);
01634 
01636     void convertKeypoints(const Mat& h_keypoints, std::vector<KeyPoint>& keypoints);
01637 
01639     void release();
01640 
01641     bool nonmaxSupression;
01642 
01643     int threshold;
01644 
01646     double keypointsRatio;
01647 
01650     int calcKeyPointsLocation(const GpuMat& image, const GpuMat& mask);
01651 
01655     int getKeyPoints(GpuMat& keypoints);
01656 
01657 private:
01658     GpuMat kpLoc_;
01659     int count_;
01660 
01661     GpuMat score_;
01662 
01663     GpuMat d_keypoints_;
01664 };
01665 
01667 
01668 class CV_EXPORTS ORB_GPU
01669 {
01670 public:
01671     enum
01672     {
01673         X_ROW = 0,
01674         Y_ROW,
01675         RESPONSE_ROW,
01676         ANGLE_ROW,
01677         OCTAVE_ROW,
01678         SIZE_ROW,
01679         ROWS_COUNT
01680     };
01681 
01682     enum
01683     {
01684         DEFAULT_FAST_THRESHOLD = 20
01685     };
01686 
01688     explicit ORB_GPU(int nFeatures = 500, float scaleFactor = 1.2f, int nLevels = 8, int edgeThreshold = 31,
01689                      int firstLevel = 0, int WTA_K = 2, int scoreType = 0, int patchSize = 31);
01690 
01695     void operator()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints);
01696     void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints);
01697 
01703     void operator()(const GpuMat& image, const GpuMat& mask, std::vector<KeyPoint>& keypoints, GpuMat& descriptors);
01704     void operator()(const GpuMat& image, const GpuMat& mask, GpuMat& keypoints, GpuMat& descriptors);
01705 
01707     void downloadKeyPoints(GpuMat& d_keypoints, std::vector<KeyPoint>& keypoints);
01708 
01710     void convertKeyPoints(Mat& d_keypoints, std::vector<KeyPoint>& keypoints);
01711 
01713     inline int descriptorSize() const { return kBytes; }
01714 
01715     inline void setFastParams(int threshold, bool nonmaxSupression = true)
01716     {
01717         fastDetector_.threshold = threshold;
01718         fastDetector_.nonmaxSupression = nonmaxSupression;
01719     }
01720 
01722     void release();
01723 
01725     bool blurForDescriptor;
01726 
01727 private:
01728     enum { kBytes = 32 };
01729 
01730     void buildScalePyramids(const GpuMat& image, const GpuMat& mask);
01731 
01732     void computeKeyPointsPyramid();
01733 
01734     void computeDescriptors(GpuMat& descriptors);
01735 
01736     void mergeKeyPoints(GpuMat& keypoints);
01737 
01738     int nFeatures_;
01739     float scaleFactor_;
01740     int nLevels_;
01741     int edgeThreshold_;
01742     int firstLevel_;
01743     int WTA_K_;
01744     int scoreType_;
01745     int patchSize_;
01746 
01747     // The number of desired features per scale
01748     std::vector<size_t> n_features_per_level_;
01749 
01750     // Points to compute BRIEF descriptors from
01751     GpuMat pattern_;
01752 
01753     std::vector<GpuMat> imagePyr_;
01754     std::vector<GpuMat> maskPyr_;
01755 
01756     GpuMat buf_;
01757 
01758     std::vector<GpuMat> keyPointsPyr_;
01759     std::vector<int> keyPointsCount_;
01760 
01761     FAST_GPU fastDetector_;
01762 
01763     Ptr<FilterEngine_GPU> blurFilter;
01764 
01765     GpuMat d_keypoints_;
01766 };
01767 
01769 
01770 class CV_EXPORTS BroxOpticalFlow
01771 {
01772 public:
01773     BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_) :
01774         alpha(alpha_), gamma(gamma_), scale_factor(scale_factor_),
01775         inner_iterations(inner_iterations_), outer_iterations(outer_iterations_), solver_iterations(solver_iterations_)
01776     {
01777     }
01778 
01784     void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null());
01785 
01787     float alpha;
01788 
01790     float gamma;
01791 
01793     float scale_factor;
01794 
01796     int inner_iterations;
01797 
01799     int outer_iterations;
01800 
01802     int solver_iterations;
01803 
01804     GpuMat buf;
01805 };
01806 
01807 class CV_EXPORTS GoodFeaturesToTrackDetector_GPU
01808 {
01809 public:
01810     explicit GoodFeaturesToTrackDetector_GPU(int maxCorners = 1000, double qualityLevel = 0.01, double minDistance = 0.0,
01811         int blockSize = 3, bool useHarrisDetector = false, double harrisK = 0.04);
01812 
01814     void operator ()(const GpuMat& image, GpuMat& corners, const GpuMat& mask = GpuMat());
01815 
01816     int maxCorners;
01817     double qualityLevel;
01818     double minDistance;
01819 
01820     int blockSize;
01821     bool useHarrisDetector;
01822     double harrisK;
01823 
01824     void releaseMemory()
01825     {
01826         Dx_.release();
01827         Dy_.release();
01828         buf_.release();
01829         eig_.release();
01830         minMaxbuf_.release();
01831         tmpCorners_.release();
01832     }
01833 
01834 private:
01835     GpuMat Dx_;
01836     GpuMat Dy_;
01837     GpuMat buf_;
01838     GpuMat eig_;
01839     GpuMat minMaxbuf_;
01840     GpuMat tmpCorners_;
01841 };
01842 
01843 inline GoodFeaturesToTrackDetector_GPU::GoodFeaturesToTrackDetector_GPU(int maxCorners_, double qualityLevel_, double minDistance_,
01844         int blockSize_, bool useHarrisDetector_, double harrisK_)
01845 {
01846     maxCorners = maxCorners_;
01847     qualityLevel = qualityLevel_;
01848     minDistance = minDistance_;
01849     blockSize = blockSize_;
01850     useHarrisDetector = useHarrisDetector_;
01851     harrisK = harrisK_;
01852 }
01853 
01854 
01855 class CV_EXPORTS PyrLKOpticalFlow
01856 {
01857 public:
01858     PyrLKOpticalFlow()
01859     {
01860         winSize = Size(21, 21);
01861         maxLevel = 3;
01862         iters = 30;
01863         derivLambda = 0.5;
01864         useInitialFlow = false;
01865         minEigThreshold = 1e-4f;
01866         getMinEigenVals = false;
01867         isDeviceArch11_ = !DeviceInfo().supports(FEATURE_SET_COMPUTE_12);
01868     }
01869 
01870     void sparse(const GpuMat& prevImg, const GpuMat& nextImg, const GpuMat& prevPts, GpuMat& nextPts,
01871         GpuMat& status, GpuMat* err = 0);
01872 
01873     void dense(const GpuMat& prevImg, const GpuMat& nextImg, GpuMat& u, GpuMat& v, GpuMat* err = 0);
01874 
01875     Size winSize;
01876     int maxLevel;
01877     int iters;
01878     double derivLambda;
01879     bool useInitialFlow;
01880     float minEigThreshold;
01881     bool getMinEigenVals;
01882 
01883     void releaseMemory()
01884     {
01885         dx_calcBuf_.release();
01886         dy_calcBuf_.release();
01887 
01888         prevPyr_.clear();
01889         nextPyr_.clear();
01890 
01891         dx_buf_.release();
01892         dy_buf_.release();
01893 
01894         uPyr_.clear();
01895         vPyr_.clear();
01896     }
01897 
01898 private:
01899     void calcSharrDeriv(const GpuMat& src, GpuMat& dx, GpuMat& dy);
01900 
01901     void buildImagePyramid(const GpuMat& img0, vector<GpuMat>& pyr, bool withBorder);
01902 
01903     GpuMat dx_calcBuf_;
01904     GpuMat dy_calcBuf_;
01905 
01906     vector<GpuMat> prevPyr_;
01907     vector<GpuMat> nextPyr_;
01908 
01909     GpuMat dx_buf_;
01910     GpuMat dy_buf_;
01911 
01912     vector<GpuMat> uPyr_;
01913     vector<GpuMat> vPyr_;
01914 
01915     bool isDeviceArch11_;
01916 };
01917 
01918 
01919 class CV_EXPORTS FarnebackOpticalFlow
01920 {
01921 public:
01922     FarnebackOpticalFlow()
01923     {
01924         numLevels = 5;
01925         pyrScale = 0.5;
01926         fastPyramids = false;
01927         winSize = 13;
01928         numIters = 10;
01929         polyN = 5;
01930         polySigma = 1.1;
01931         flags = 0;
01932         isDeviceArch11_ = !DeviceInfo().supports(FEATURE_SET_COMPUTE_12);
01933     }
01934 
01935     int numLevels;
01936     double pyrScale;
01937     bool fastPyramids;
01938     int winSize;
01939     int numIters;
01940     int polyN;
01941     double polySigma;
01942     int flags;
01943 
01944     void operator ()(const GpuMat &frame0, const GpuMat &frame1, GpuMat &flowx, GpuMat &flowy, Stream &s = Stream::Null());
01945 
01946     void releaseMemory()
01947     {
01948         frames_[0].release();
01949         frames_[1].release();
01950         pyrLevel_[0].release();
01951         pyrLevel_[1].release();
01952         M_.release();
01953         bufM_.release();
01954         R_[0].release();
01955         R_[1].release();
01956         blurredFrame_[0].release();
01957         blurredFrame_[1].release();
01958         pyramid0_.clear();
01959         pyramid1_.clear();
01960     }
01961 
01962 private:
01963     void prepareGaussian(
01964             int n, double sigma, float *g, float *xg, float *xxg,
01965             double &ig11, double &ig03, double &ig33, double &ig55);
01966 
01967     void setPolynomialExpansionConsts(int n, double sigma);
01968 
01969     void updateFlow_boxFilter(
01970             const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat &flowy,
01971             GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]);
01972 
01973     void updateFlow_gaussianBlur(
01974             const GpuMat& R0, const GpuMat& R1, GpuMat& flowx, GpuMat& flowy,
01975             GpuMat& M, GpuMat &bufM, int blockSize, bool updateMatrices, Stream streams[]);
01976 
01977     GpuMat frames_[2];
01978     GpuMat pyrLevel_[2], M_, bufM_, R_[2], blurredFrame_[2];
01979     std::vector<GpuMat> pyramid0_, pyramid1_;
01980 
01981     bool isDeviceArch11_;
01982 };
01983 
01984 
01999 CV_EXPORTS void interpolateFrames(const GpuMat& frame0, const GpuMat& frame1,
02000                                   const GpuMat& fu, const GpuMat& fv,
02001                                   const GpuMat& bu, const GpuMat& bv,
02002                                   float pos, GpuMat& newFrame, GpuMat& buf,
02003                                   Stream& stream = Stream::Null());
02004 
02005 CV_EXPORTS void createOpticalFlowNeedleMap(const GpuMat& u, const GpuMat& v, GpuMat& vertex, GpuMat& colors);
02006 
02007 
02009 
02010 // Foreground Object Detection from Videos Containing Complex Background.
02011 // Liyuan Li, Weimin Huang, Irene Y.H. Gu, and Qi Tian.
02012 // ACM MM2003 9p
02013 class CV_EXPORTS FGDStatModel
02014 {
02015 public:
02016     struct CV_EXPORTS Params
02017     {
02018         int Lc;  // Quantized levels per 'color' component. Power of two, typically 32, 64 or 128.
02019         int N1c; // Number of color vectors used to model normal background color variation at a given pixel.
02020         int N2c; // Number of color vectors retained at given pixel.  Must be > N1c, typically ~ 5/3 of N1c.
02021         // Used to allow the first N1c vectors to adapt over time to changing background.
02022 
02023         int Lcc;  // Quantized levels per 'color co-occurrence' component.  Power of two, typically 16, 32 or 64.
02024         int N1cc; // Number of color co-occurrence vectors used to model normal background color variation at a given pixel.
02025         int N2cc; // Number of color co-occurrence vectors retained at given pixel.  Must be > N1cc, typically ~ 5/3 of N1cc.
02026         // Used to allow the first N1cc vectors to adapt over time to changing background.
02027 
02028         bool is_obj_without_holes; // If TRUE we ignore holes within foreground blobs. Defaults to TRUE.
02029         int perform_morphing;     // Number of erode-dilate-erode foreground-blob cleanup iterations.
02030         // These erase one-pixel junk blobs and merge almost-touching blobs. Default value is 1.
02031 
02032         float alpha1; // How quickly we forget old background pixel values seen. Typically set to 0.1.
02033         float alpha2; // "Controls speed of feature learning". Depends on T. Typical value circa 0.005.
02034         float alpha3; // Alternate to alpha2, used (e.g.) for quicker initial convergence. Typical value 0.1.
02035 
02036         float delta;   // Affects color and color co-occurrence quantization, typically set to 2.
02037         float T;       // A percentage value which determines when new features can be recognized as new background. (Typically 0.9).
02038         float minArea; // Discard foreground blobs whose bounding box is smaller than this threshold.
02039 
02040         // default Params
02041         Params();
02042     };
02043 
02044     // out_cn - channels count in output result (can be 3 or 4)
02045     // 4-channels require more memory, but a bit faster
02046     explicit FGDStatModel(int out_cn = 3);
02047     explicit FGDStatModel(const cv::gpu::GpuMat& firstFrame, const Params& params = Params(), int out_cn = 3);
02048 
02049     ~FGDStatModel();
02050 
02051     void create(const cv::gpu::GpuMat& firstFrame, const Params& params = Params());
02052     void release();
02053 
02054     int update(const cv::gpu::GpuMat& curFrame);
02055 
02056     //8UC3 or 8UC4 reference background image
02057     cv::gpu::GpuMat background;
02058 
02059     //8UC1 foreground image
02060     cv::gpu::GpuMat foreground;
02061 
02062     std::vector< std::vector<cv::Point> > foreground_regions;
02063 
02064 private:
02065     FGDStatModel(const FGDStatModel&);
02066     FGDStatModel& operator=(const FGDStatModel&);
02067 
02068     class Impl;
02069     std::auto_ptr<Impl> impl_;
02070 };
02071 
02081 class CV_EXPORTS MOG_GPU
02082 {
02083 public:
02085     MOG_GPU(int nmixtures = -1);
02086 
02088     void initialize(Size frameSize, int frameType);
02089 
02091     void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = 0.0f, Stream& stream = Stream::Null());
02092 
02094     void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
02095 
02097     void release();
02098 
02099     int history;
02100     float varThreshold;
02101     float backgroundRatio;
02102     float noiseSigma;
02103 
02104 private:
02105     int nmixtures_;
02106 
02107     Size frameSize_;
02108     int frameType_;
02109     int nframes_;
02110 
02111     GpuMat weight_;
02112     GpuMat sortKey_;
02113     GpuMat mean_;
02114     GpuMat var_;
02115 };
02116 
02124 class CV_EXPORTS MOG2_GPU
02125 {
02126 public:
02128     MOG2_GPU(int nmixtures = -1);
02129 
02131     void initialize(Size frameSize, int frameType);
02132 
02134     void operator()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
02135 
02137     void getBackgroundImage(GpuMat& backgroundImage, Stream& stream = Stream::Null()) const;
02138 
02140     void release();
02141 
02142     // parameters
02143     // you should call initialize after parameters changes
02144 
02145     int history;
02146 
02149     float varThreshold;
02150     // threshold on the squared Mahalanobis distance to decide if it is well described
02151     // by the background model or not. Related to Cthr from the paper.
02152     // This does not influence the update of the background. A typical value could be 4 sigma
02153     // and that is varThreshold=4*4=16; Corresponds to Tb in the paper.
02154 
02156     // less important parameters - things you might change but be carefull
02158 
02159     float backgroundRatio;
02160     // corresponds to fTB=1-cf from the paper
02161     // TB - threshold when the component becomes significant enough to be included into
02162     // the background model. It is the TB=1-cf from the paper. So I use cf=0.1 => TB=0.
02163     // For alpha=0.001 it means that the mode should exist for approximately 105 frames before
02164     // it is considered foreground
02165     // float noiseSigma;
02166     float varThresholdGen;
02167 
02168     //correspondts to Tg - threshold on the squared Mahalan. dist. to decide
02169     //when a sample is close to the existing components. If it is not close
02170     //to any a new component will be generated. I use 3 sigma => Tg=3*3=9.
02171     //Smaller Tg leads to more generated components and higher Tg might make
02172     //lead to small number of components but they can grow too large
02173     float fVarInit;
02174     float fVarMin;
02175     float fVarMax;
02176 
02177     //initial variance  for the newly generated components.
02178     //It will will influence the speed of adaptation. A good guess should be made.
02179     //A simple way is to estimate the typical standard deviation from the images.
02180     //I used here 10 as a reasonable value
02181     // min and max can be used to further control the variance
02182     float fCT; //CT - complexity reduction prior
02183     //this is related to the number of samples needed to accept that a component
02184     //actually exists. We use CT=0.05 of all the samples. By setting CT=0 you get
02185     //the standard Stauffer&Grimson algorithm (maybe not exact but very similar)
02186 
02187     //shadow detection parameters
02188     bool bShadowDetection; //default 1 - do shadow detection
02189     unsigned char nShadowDetection; //do shadow detection - insert this value as the detection result - 127 default value
02190     float fTau;
02191     // Tau - shadow threshold. The shadow is detected if the pixel is darker
02192     //version of the background. Tau is a threshold on how much darker the shadow can be.
02193     //Tau= 0.5 means that if pixel is more than 2 times darker then it is not shadow
02194     //See: Prati,Mikic,Trivedi,Cucchiarra,"Detecting Moving Shadows...",IEEE PAMI,2003.
02195 
02196 private:
02197     int nmixtures_;
02198 
02199     Size frameSize_;
02200     int frameType_;
02201     int nframes_;
02202 
02203     GpuMat weight_;
02204     GpuMat variance_;
02205     GpuMat mean_;
02206 
02207     GpuMat bgmodelUsedModes_; //keep track of number of modes per pixel
02208 };
02209 
02216 class CV_EXPORTS VIBE_GPU
02217 {
02218 public:
02220     explicit VIBE_GPU(unsigned long rngSeed = 1234567);
02221 
02223     void initialize(const GpuMat& firstFrame, Stream& stream = Stream::Null());
02224 
02226     void operator()(const GpuMat& frame, GpuMat& fgmask, Stream& stream = Stream::Null());
02227 
02229     void release();
02230 
02231     int nbSamples;         // number of samples per pixel
02232     int reqMatches;        // #_min
02233     int radius;            // R
02234     int subsamplingFactor; // amount of random subsampling
02235 
02236 private:
02237     Size frameSize_;
02238 
02239     unsigned long rngSeed_;
02240     GpuMat randStates_;
02241 
02242     GpuMat samples_;
02243 };
02244 
02252 class CV_EXPORTS GMG_GPU
02253 {
02254 public:
02255     GMG_GPU();
02256 
02263     void initialize(Size frameSize, float min = 0.0f, float max = 255.0f);
02264 
02272     void operator ()(const GpuMat& frame, GpuMat& fgmask, float learningRate = -1.0f, Stream& stream = Stream::Null());
02273 
02275     void release();
02276 
02278     int maxFeatures;
02279 
02281     float learningRate;
02282 
02284     int numInitializationFrames;
02285 
02287     int quantizationLevels;
02288 
02290     float backgroundPrior;
02291 
02293     float decisionThreshold;
02294 
02296     int smoothingRadius;
02297 
02299     bool updateBackgroundModel;
02300 
02301 private:
02302     float maxVal_, minVal_;
02303 
02304     Size frameSize_;
02305 
02306     int frameNum_;
02307 
02308     GpuMat nfeatures_;
02309     GpuMat colors_;
02310     GpuMat weights_;
02311 
02312     Ptr<FilterEngine_GPU> boxFilter_;
02313     GpuMat buf_;
02314 };
02315 
02317 
02318 // Works only under Windows
02319 // Supports olny H264 video codec and AVI files
02320 class CV_EXPORTS VideoWriter_GPU
02321 {
02322 public:
02323     struct EncoderParams;
02324 
02325     // Callbacks for video encoder, use it if you want to work with raw video stream
02326     class EncoderCallBack;
02327 
02328     enum SurfaceFormat
02329     {
02330         SF_UYVY = 0,
02331         SF_YUY2,
02332         SF_YV12,
02333         SF_NV12,
02334         SF_IYUV,
02335         SF_BGR,
02336         SF_GRAY = SF_BGR
02337     };
02338 
02339     VideoWriter_GPU();
02340     VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
02341     VideoWriter_GPU(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
02342     VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
02343     VideoWriter_GPU(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
02344     ~VideoWriter_GPU();
02345 
02346     // all methods throws cv::Exception if error occurs
02347     void open(const std::string& fileName, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
02348     void open(const std::string& fileName, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
02349     void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, SurfaceFormat format = SF_BGR);
02350     void open(const cv::Ptr<EncoderCallBack>& encoderCallback, cv::Size frameSize, double fps, const EncoderParams& params, SurfaceFormat format = SF_BGR);
02351 
02352     bool isOpened() const;
02353     void close();
02354 
02355     void write(const cv::gpu::GpuMat& image, bool lastFrame = false);
02356 
02357     struct CV_EXPORTS EncoderParams
02358     {
02359         int       P_Interval;      //    NVVE_P_INTERVAL,
02360         int       IDR_Period;      //    NVVE_IDR_PERIOD,
02361         int       DynamicGOP;      //    NVVE_DYNAMIC_GOP,
02362         int       RCType;          //    NVVE_RC_TYPE,
02363         int       AvgBitrate;      //    NVVE_AVG_BITRATE,
02364         int       PeakBitrate;     //    NVVE_PEAK_BITRATE,
02365         int       QP_Level_Intra;  //    NVVE_QP_LEVEL_INTRA,
02366         int       QP_Level_InterP; //    NVVE_QP_LEVEL_INTER_P,
02367         int       QP_Level_InterB; //    NVVE_QP_LEVEL_INTER_B,
02368         int       DeblockMode;     //    NVVE_DEBLOCK_MODE,
02369         int       ProfileLevel;    //    NVVE_PROFILE_LEVEL,
02370         int       ForceIntra;      //    NVVE_FORCE_INTRA,
02371         int       ForceIDR;        //    NVVE_FORCE_IDR,
02372         int       ClearStat;       //    NVVE_CLEAR_STAT,
02373         int       DIMode;          //    NVVE_SET_DEINTERLACE,
02374         int       Presets;         //    NVVE_PRESETS,
02375         int       DisableCabac;    //    NVVE_DISABLE_CABAC,
02376         int       NaluFramingType; //    NVVE_CONFIGURE_NALU_FRAMING_TYPE
02377         int       DisableSPSPPS;   //    NVVE_DISABLE_SPS_PPS
02378 
02379         EncoderParams();
02380         explicit EncoderParams(const std::string& configFile);
02381 
02382         void load(const std::string& configFile);
02383         void save(const std::string& configFile) const;
02384     };
02385 
02386     EncoderParams getParams() const;
02387 
02388     class CV_EXPORTS EncoderCallBack
02389     {
02390     public:
02391         enum PicType
02392         {
02393             IFRAME = 1,
02394             PFRAME = 2,
02395             BFRAME = 3
02396         };
02397 
02398         virtual ~EncoderCallBack() {}
02399 
02400         // callback function to signal the start of bitstream that is to be encoded
02401         // must return pointer to buffer
02402         virtual uchar* acquireBitStream(int* bufferSize) = 0;
02403 
02404         // callback function to signal that the encoded bitstream is ready to be written to file
02405         virtual void releaseBitStream(unsigned char* data, int size) = 0;
02406 
02407         // callback function to signal that the encoding operation on the frame has started
02408         virtual void onBeginFrame(int frameNumber, PicType picType) = 0;
02409 
02410         // callback function signals that the encoding operation on the frame has finished
02411         virtual void onEndFrame(int frameNumber, PicType picType) = 0;
02412     };
02413 
02414 private:
02415     VideoWriter_GPU(const VideoWriter_GPU&);
02416     VideoWriter_GPU& operator=(const VideoWriter_GPU&);
02417 
02418     class Impl;
02419     std::auto_ptr<Impl> impl_;
02420 };
02421 
02422 
02424 
02425 namespace detail
02426 {
02427     class FrameQueue;
02428     class VideoParser;
02429 }
02430 
02431 class CV_EXPORTS VideoReader_GPU
02432 {
02433 public:
02434     enum Codec
02435     {
02436         MPEG1 = 0,
02437         MPEG2,
02438         MPEG4,
02439         VC1,
02440         H264,
02441         JPEG,
02442         H264_SVC,
02443         H264_MVC,
02444 
02445         Uncompressed_YUV420 = (('I'<<24)|('Y'<<16)|('U'<<8)|('V')),   // Y,U,V (4:2:0)
02446         Uncompressed_YV12   = (('Y'<<24)|('V'<<16)|('1'<<8)|('2')),   // Y,V,U (4:2:0)
02447         Uncompressed_NV12   = (('N'<<24)|('V'<<16)|('1'<<8)|('2')),   // Y,UV  (4:2:0)
02448         Uncompressed_YUYV   = (('Y'<<24)|('U'<<16)|('Y'<<8)|('V')),   // YUYV/YUY2 (4:2:2)
02449         Uncompressed_UYVY   = (('U'<<24)|('Y'<<16)|('V'<<8)|('Y')),   // UYVY (4:2:2)
02450     };
02451 
02452     enum ChromaFormat
02453     {
02454         Monochrome=0,
02455         YUV420,
02456         YUV422,
02457         YUV444,
02458     };
02459 
02460     struct FormatInfo
02461     {
02462         Codec codec;
02463         ChromaFormat chromaFormat;
02464         int width;
02465         int height;
02466     };
02467 
02468     class VideoSource;
02469 
02470     VideoReader_GPU();
02471     explicit VideoReader_GPU(const std::string& filename);
02472     explicit VideoReader_GPU(const cv::Ptr<VideoSource>& source);
02473 
02474     ~VideoReader_GPU();
02475 
02476     void open(const std::string& filename);
02477     void open(const cv::Ptr<VideoSource>& source);
02478     bool isOpened() const;
02479 
02480     void close();
02481 
02482     bool read(GpuMat& image);
02483 
02484     FormatInfo format() const;
02485     void dumpFormat(std::ostream& st);
02486 
02487     class CV_EXPORTS VideoSource
02488     {
02489     public:
02490         VideoSource() : frameQueue_(0), videoParser_(0) {}
02491         virtual ~VideoSource() {}
02492 
02493         virtual FormatInfo format() const = 0;
02494         virtual void start() = 0;
02495         virtual void stop() = 0;
02496         virtual bool isStarted() const = 0;
02497         virtual bool hasError() const = 0;
02498 
02499         void setFrameQueue(detail::FrameQueue* frameQueue) { frameQueue_ = frameQueue; }
02500         void setVideoParser(detail::VideoParser* videoParser) { videoParser_ = videoParser; }
02501 
02502     protected:
02503         bool parseVideoData(const uchar* data, size_t size, bool endOfStream = false);
02504 
02505     private:
02506         VideoSource(const VideoSource&);
02507         VideoSource& operator =(const VideoSource&);
02508 
02509         detail::FrameQueue* frameQueue_;
02510         detail::VideoParser* videoParser_;
02511     };
02512 
02513 private:
02514     VideoReader_GPU(const VideoReader_GPU&);
02515     VideoReader_GPU& operator =(const VideoReader_GPU&);
02516 
02517     class Impl;
02518     std::auto_ptr<Impl> impl_;
02519 };
02520 
02522 CV_EXPORTS void compactPoints(GpuMat &points0, GpuMat &points1, const GpuMat &mask);
02523 
02524 CV_EXPORTS void calcWobbleSuppressionMaps(
02525         int left, int idx, int right, Size size, const Mat &ml, const Mat &mr,
02526         GpuMat &mapx, GpuMat &mapy);
02527 
02528 } // namespace gpu
02529 
02530 } // namespace cv
02531 
02532 #endif /* __OPENCV_GPU_HPP__ */