diff --git a/modules/gpu/doc/data_structures.rst b/modules/gpu/doc/data_structures.rst index 33577df6b..375b99845 100644 --- a/modules/gpu/doc/data_structures.rst +++ b/modules/gpu/doc/data_structures.rst @@ -68,9 +68,9 @@ Structure similar to :ocv:class:`gpu::DevMem2D_` but containing only a pointer a -gpu::PtrElemStrp\_ +gpu::PtrElemStep\_ ------------------ -.. ocv:class:: gpu::PtrElemStrp\_ +.. ocv:class:: gpu::PtrElemStep\_ Structure similar to :ocv:class:`gpu::DevMem2D_` but containing only a pointer and a row step in elements. Width and height fields are excluded due to performance reasons. This class can only be constructed if ``sizeof(T)`` is a multiple of 256. The structure is intended for internal use or for users who write device code. :: @@ -123,7 +123,6 @@ Beware that the latter limitation may lead to overloaded matrix operators that c void upload(const CudaMem& m, Stream& stream); //! downloads data from device to host memory. Blocking calls. - operator Mat() const; void download(cv::Mat& m) const; //! download async diff --git a/modules/gpu/doc/feature_detection_and_description.rst b/modules/gpu/doc/feature_detection_and_description.rst index fce0b05b9..47c0f3625 100644 --- a/modules/gpu/doc/feature_detection_and_description.rst +++ b/modules/gpu/doc/feature_detection_and_description.rst @@ -124,7 +124,7 @@ Brute-force descriptor matcher. For each descriptor in the first set, this match // Return true if the matcher supports mask in match methods. bool isMaskSupported() const; - void matchSingle(const GpuMat& queryDescs, const GpuMat& trainDescs, + void matchSingle(const GpuMat& query, const GpuMat& train, GpuMat& trainIdx, GpuMat& distance, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()); @@ -133,14 +133,13 @@ Brute-force descriptor matcher. For each descriptor in the first set, this match static void matchConvert(const Mat& trainIdx, const Mat& distance, std::vector& matches); - void match(const GpuMat& queryDescs, const GpuMat& trainDescs, + void match(const GpuMat& query, const GpuMat& train, std::vector& matches, const GpuMat& mask = GpuMat()); void makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection, const vector& masks = std::vector()); - void matchCollection(const GpuMat& queryDescs, - const GpuMat& trainCollection, + void matchCollection(const GpuMat& query, const GpuMat& trainCollection, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, const GpuMat& maskCollection, Stream& stream = Stream::Null()); @@ -149,50 +148,58 @@ Brute-force descriptor matcher. For each descriptor in the first set, this match static void matchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, std::vector& matches); - void match(const GpuMat& queryDescs, std::vector& matches, + void match(const GpuMat& query, std::vector& matches, const std::vector& masks = std::vector()); - void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, + void knnMatchSingle(const GpuMat& query, const GpuMat& train, GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()); - static void knnMatchDownload(const GpuMat& trainIdx, - const GpuMat& distance, std::vector< std::vector >& matches, - bool compactResult = false); - static void knnMatchConvert(const Mat& trainIdx, - const Mat& distance, std::vector< std::vector >& matches, - bool compactResult = false); + static void knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, + std::vector< std::vector >& matches, bool compactResult = false); + static void knnMatchConvert(const Mat& trainIdx, const Mat& distance, + std::vector< std::vector >& matches, bool compactResult = false); - void knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, + void knnMatch(const GpuMat& query, const GpuMat& train, std::vector< std::vector >& matches, int k, const GpuMat& mask = GpuMat(), bool compactResult = false); - void knnMatch(const GpuMat& queryDescs, - std::vector< std::vector >& matches, int knn, + void knnMatch2Collection(const GpuMat& query, const GpuMat& trainCollection, + GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, + const GpuMat& maskCollection = GpuMat(), Stream& stream = Stream::Null()); + + static void knnMatch2Download(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, + std::vector< std::vector >& matches, bool compactResult = false); + static void knnMatch2Convert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, + std::vector< std::vector >& matches, bool compactResult = false); + + void knnMatch(const GpuMat& query, std::vector< std::vector >& matches, int k, const std::vector& masks = std::vector(), - bool compactResult = false ); - - void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, - GpuMat& trainIdx, GpuMat& nMatches, GpuMat& distance, - float maxDistance, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()); - - static void radiusMatchDownload(const GpuMat& trainIdx, - const GpuMat& nMatches, const GpuMat& distance, - std::vector< std::vector >& matches, - bool compactResult = false); - static void radiusMatchConvert(const Mat& trainIdx, - const Mat& nMatches, const Mat& distance, - std::vector< std::vector >& matches, bool compactResult = false); - void radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, + void radiusMatchSingle(const GpuMat& query, const GpuMat& train, + GpuMat& trainIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance, + const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()); + + static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, const GpuMat& nMatches, + std::vector< std::vector >& matches, bool compactResult = false); + static void radiusMatchConvert(const Mat& trainIdx, const Mat& distance, const Mat& nMatches, + std::vector< std::vector >& matches, bool compactResult = false); + + void radiusMatch(const GpuMat& query, const GpuMat& train, std::vector< std::vector >& matches, float maxDistance, const GpuMat& mask = GpuMat(), bool compactResult = false); - void radiusMatch(const GpuMat& queryDescs, - std::vector< std::vector >& matches, float maxDistance, - const std::vector& masks = std::vector(), - bool compactResult = false); + void radiusMatchCollection(const GpuMat& query, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance, + const std::vector& masks = std::vector(), Stream& stream = Stream::Null()); + + static void radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, const GpuMat& nMatches, + std::vector< std::vector >& matches, bool compactResult = false); + static void radiusMatchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, const Mat& nMatches, + std::vector< std::vector >& matches, bool compactResult = false); + + void radiusMatch(const GpuMat& query, std::vector< std::vector >& matches, float maxDistance, + const std::vector& masks = std::vector(), bool compactResult = false); private: std::vector trainDescCollection; @@ -209,65 +216,23 @@ gpu::BruteForceMatcher_GPU::match ------------------------------------- Finds the best match for each descriptor from a query set with train descriptors. -.. ocv:function:: void gpu::BruteForceMatcher_GPU::match(const GpuMat& queryDescs, const GpuMat& trainDescs, std::vector& matches, const GpuMat& mask = GpuMat()) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::match(const GpuMat& query, const GpuMat& train, std::vector& matches, const GpuMat& mask = GpuMat()) -.. ocv:function:: void gpu::BruteForceMatcher_GPU::match(const GpuMat& queryDescs, std::vector& matches, const std::vector& masks = std::vector()) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::matchSingle(const GpuMat& query, const GpuMat& train, GpuMat& trainIdx, GpuMat& distance, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()) + +.. ocv:function:: void gpu::BruteForceMatcher_GPU::match(const GpuMat& query, std::vector& matches, const std::vector& masks = std::vector()) + +.. ocv:function:: void gpu::BruteForceMatcher_GPU::matchCollection(const GpuMat& query, const GpuMat& trainCollection, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, const GpuMat& masks, Stream& stream = Stream::Null()) .. seealso:: :ocv:func:`DescriptorMatcher::match` -gpu::BruteForceMatcher_GPU::matchSingle -------------------------------------------- -Finds the best match for each query descriptor. - -.. ocv:function:: void gpu::BruteForceMatcher_GPU::matchSingle(const GpuMat& queryDescs, const GpuMat& trainDescs, GpuMat& trainIdx, GpuMat& distance, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()) - - :param queryDescs: Query set of descriptors. - - :param trainDescs: Training set of descriptors. It is not added to train descriptors collection stored in the class object. - - :param trainIdx: Output matrix that contains the best train index for each query. - - :param distance: Output matrix that contains the best distance for each query. - - :param mask: Mask specifying permissible matches between the input query and train matrices of descriptors. - - :param stream: Stream for the asynchronous version. - -Results are stored in the GPU memory. - - - -gpu::BruteForceMatcher_GPU::matchCollection ------------------------------------------------ -Finds the best match for each query descriptor from train collection. - -.. ocv:function:: void gpu::BruteForceMatcher_GPU::matchCollection(const GpuMat& queryDescs, const GpuMat& trainCollection, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, const GpuMat& maskCollection, Stream& stream = Stream::Null()) - - :param queryDescs: Query set of descriptors. - - :param trainCollection: :ocv:class:`gpu::GpuMat` containing train collection. It can be obtained from the collection of train descriptors that was set using the ``add`` method by :ocv:func:`gpu::BruteForceMatcher_GPU::makeGpuCollection`. Or it may contain a user-defined collection. This is a one-row matrix where each element is ``DevMem2D`` pointing out to a matrix of train descriptors. - - :param trainIdx: Output matrix that contains the best train index for each query. - - :param imgIdx: Output matrix that contains image train index for each query. - - :param distance: Output matrix that contains the best distance for each query. - - :param maskCollection: ``GpuMat`` containing a set of masks. It can be obtained from ``std::vector`` by :ocv:func:`gpu::BruteForceMatcher_GPU::makeGpuCollection` or it may contain a user-defined mask set. This is an empty matrix or one-row matrix where each element is a ``PtrStep`` that points to one mask. - - :param stream: Stream for the asynchronous version. - -Results are stored in the GPU memory. - - - gpu::BruteForceMatcher_GPU::makeGpuCollection ------------------------------------------------- Performs a GPU collection of train descriptors and masks in a suitable format for the :ocv:func:`gpu::BruteForceMatcher_GPU::matchCollection` function. -.. ocv:function:: void gpu::BruteForceMatcher_GPU::makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection, const vector&masks = std::vector()) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::makeGpuCollection(GpuMat& trainCollection, GpuMat& maskCollection, const vector& masks = std::vector()) @@ -295,21 +260,17 @@ gpu::BruteForceMatcher_GPU::knnMatch ---------------------------------------- Finds the k best matches for each descriptor from a query set with train descriptors. -.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, std::vector< std::vector >&matches, int k, const GpuMat& mask = GpuMat(), bool compactResult = false) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch(const GpuMat& query, const GpuMat& train, std::vector< std::vector >&matches, int k, const GpuMat& mask = GpuMat(), bool compactResult = false) -.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch(const GpuMat& queryDescs, std::vector< std::vector >&matches, int k, const std::vector&masks = std::vector(), bool compactResult = false ) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatchSingle(const GpuMat& query, const GpuMat& train, GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()) -.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, GpuMat& trainIdx, GpuMat& distance, GpuMat& allDist, int k, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch(const GpuMat& query, std::vector< std::vector >&matches, int k, const std::vector&masks = std::vector(), bool compactResult = false ) - :param queryDescs: Query set of descriptors. +.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch2Collection(const GpuMat& query, const GpuMat& trainCollection, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, const GpuMat& maskCollection = GpuMat(), Stream& stream = Stream::Null()) - :param trainDescs: Training set of descriptors. It is not be added to train descriptors collection stored in the class object. + :param query: Query set of descriptors. - :param trainIdx: Output matrix that contains the best train index for each query. - - :param distance: Output matrix that contains the best distance for each query. - - :param allDist: Output matrix that contains all distances between each query descriptors and each train descriptor. + :param train: Training set of descriptors. It is not be added to train descriptors collection stored in the class object. :param k: Number of the best matches per each query descriptor (or less if it is not possible). @@ -329,20 +290,24 @@ The third variant of the method stores the results in GPU memory. gpu::BruteForceMatcher_GPU::knnMatchDownload ------------------------------------------------ -Downloads matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::knnMatch` to vector with :ocv:class:`DMatch`. +Downloads matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::knnMatchSingle` or :ocv:func:`gpu::BruteForceMatcher_GPU::knnMatch2Collection` to vector with :ocv:class:`DMatch`. .. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, std::vector< std::vector >&matches, bool compactResult = false) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch2Download(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, std::vector< std::vector >& matches, bool compactResult = false) + If ``compactResult`` is ``true`` , the ``matches`` vector does not contain matches for fully masked-out query descriptors. gpu::BruteForceMatcher_GPU::knnMatchConvert ------------------------------------------------ -Converts matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::knnMatch` to CPU vector with :ocv:class:`DMatch`. +Converts matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::knnMatchSingle` or :ocv:func:`gpu::BruteForceMatcher_GPU::knnMatch2Collection` to CPU vector with :ocv:class:`DMatch`. .. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatchConvert(const Mat& trainIdx, const Mat& distance, std::vector< std::vector >&matches, bool compactResult = false) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::knnMatch2Convert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, std::vector< std::vector >& matches, bool compactResult = false) + If ``compactResult`` is ``true`` , the ``matches`` vector does not contain matches for fully masked-out query descriptors. @@ -351,21 +316,17 @@ gpu::BruteForceMatcher_GPU::radiusMatch ------------------------------------------- For each query descriptor, finds the best matches with a distance less than a given threshold. -.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, std::vector< std::vector >&matches, float maxDistance, const GpuMat& mask = GpuMat(), bool compactResult = false) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatch(const GpuMat& query, const GpuMat& train, std::vector< std::vector >&matches, float maxDistance, const GpuMat& mask = GpuMat(), bool compactResult = false) -.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatch(const GpuMat& queryDescs, std::vector< std::vector >&matches, float maxDistance, const std::vector&masks = std::vector(), bool compactResult = false) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchSingle(const GpuMat& query, const GpuMat& train, GpuMat& trainIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()) -.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatch(const GpuMat& queryDescs, const GpuMat& trainDescs, GpuMat& trainIdx, GpuMat& nMatches, GpuMat& distance, float maxDistance, const GpuMat& mask = GpuMat(), Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatch(const GpuMat& query, std::vector< std::vector >&matches, float maxDistance, const std::vector& masks = std::vector(), bool compactResult = false) - :param queryDescs: Query set of descriptors. +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchCollection(const GpuMat& query, GpuMat& trainIdx, GpuMat& imgIdx, GpuMat& distance, GpuMat& nMatches, float maxDistance, const std::vector& masks = std::vector(), Stream& stream = Stream::Null()) - :param trainDescs: Training set of descriptors. It is not added to train descriptors collection stored in the class object. + :param query: Query set of descriptors. - :param trainIdx: Output matrix that contains the best train index for each query. - - :param nMatches: Output matrix that contains the number of matching descriptors for each query. - - :param distance: Output matrix that contains the best distance for each query. + :param train: Training set of descriptors. It is not added to train descriptors collection stored in the class object. :param maxDistance: Distance threshold. @@ -387,9 +348,11 @@ The third variant of the method stores the results in GPU memory and does not st gpu::BruteForceMatcher_GPU::radiusMatchDownload --------------------------------------------------- -Downloads matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::radiusMatch` to vector with :ocv:class:`DMatch`. +Downloads matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::radiusMatchSingle` or :ocv:func:`gpu::BruteForceMatcher_GPU::radiusMatchCollection` to vector with :ocv:class:`DMatch`. -.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& nMatches, const GpuMat& distance, std::vector< std::vector >&matches, bool compactResult = false) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& distance, const GpuMat& nMatches, std::vector< std::vector >&matches, bool compactResult = false) + +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchDownload(const GpuMat& trainIdx, const GpuMat& imgIdx, const GpuMat& distance, const GpuMat& nMatches, std::vector< std::vector >& matches, bool compactResult = false); If ``compactResult`` is ``true`` , the ``matches`` vector does not contain matches for fully masked-out query descriptors. @@ -398,9 +361,11 @@ If ``compactResult`` is ``true`` , the ``matches`` vector does not contain match gpu::BruteForceMatcher_GPU::radiusMatchConvert --------------------------------------------------- -Converts matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::radiusMatch` to vector with :ocv:class:`DMatch`. +Converts matrices obtained via :ocv:func:`gpu::BruteForceMatcher_GPU::radiusMatchSingle` or :ocv:func:`gpu::BruteForceMatcher_GPU::radiusMatchCollection` to vector with :ocv:class:`DMatch`. -.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchConvert(const Mat& trainIdx, const Mat& nMatches, const Mat& distance, std::vector< std::vector >&matches, bool compactResult = false) +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchConvert(const Mat& trainIdx, const Mat& distance, const Mat& nMatches, std::vector< std::vector >&matches, bool compactResult = false) + +.. ocv:function:: void gpu::BruteForceMatcher_GPU::radiusMatchConvert(const Mat& trainIdx, const Mat& imgIdx, const Mat& distance, const Mat& nMatches, std::vector< std::vector >& matches, bool compactResult = false) If ``compactResult`` is ``true`` , the ``matches`` vector does not contain matches for fully masked-out query descriptors. diff --git a/modules/gpu/doc/gpu.rst b/modules/gpu/doc/gpu.rst index d21656b87..b21e2abac 100644 --- a/modules/gpu/doc/gpu.rst +++ b/modules/gpu/doc/gpu.rst @@ -16,3 +16,4 @@ gpu. GPU-accelerated Computer Vision feature_detection_and_description image_filtering camera_calibration_and_3d_reconstruction + video diff --git a/modules/gpu/doc/image_processing.rst b/modules/gpu/doc/image_processing.rst index ffb4239b3..2d069481e 100644 --- a/modules/gpu/doc/image_processing.rst +++ b/modules/gpu/doc/image_processing.rst @@ -328,15 +328,23 @@ gpu::remap -------------- Applies a generic geometrical transformation to an image. -.. ocv:function:: void gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap) +.. ocv:function:: void gpu::remap(const GpuMat& src, GpuMat& dst, const GpuMat& xmap, const GpuMat& ymap, int interpolation, int borderMode = BORDER_CONSTANT, const Scalar& borderValue = Scalar(), Stream& stream = Stream::Null() - :param src: Source image. Only ``CV_8UC1`` and ``CV_8UC3`` source types are supported. + :param src: Source image. :param dst: Destination image with the size the same as ``xmap`` and the type the same as ``src`` . :param xmap: X values. Only ``CV_32FC1`` type is supported. :param ymap: Y values. Only ``CV_32FC1`` type is supported. + + :param interpolation: Interpolation method (see :ocv:func:`resize` ). ``INTER_NEAREST`` , ``INTER_LINEAR`` and ``INTER_CUBIC`` are supported for now. + + :param borderMode: Pixel extrapolation method (see :ocv:func:`borderInterpolate` ). ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now. + + :param borderValue: Value used in case of a constant border. By default, it is 0. + + :param stream: Stream for the asynchronous version. The function transforms the source image using the specified map: @@ -400,7 +408,7 @@ Resizes an image. .. ocv:function:: void gpu::resize(const GpuMat& src, GpuMat& dst, Size dsize, double fx=0, double fy=0, int interpolation = INTER_LINEAR, Stream& stream = Stream::Null()) - :param src: Source image. ``CV_8UC1`` and ``CV_8UC4`` types are supported. + :param src: Source image. :param dst: Destination image with the same type as ``src`` . The size is ``dsize`` (when it is non-zero) or the size is computed from ``src.size()`` , ``fx`` , and ``fy`` . @@ -423,7 +431,7 @@ Resizes an image. \texttt{(double)dsize.height/src.rows} - :param interpolation: Interpolation method. Only ``INTER_NEAREST`` and ``INTER_LINEAR`` are supported. + :param interpolation: Interpolation method. ``INTER_NEAREST`` , ``INTER_LINEAR`` and ``INTER_CUBIC`` are supported for now. :param stream: Stream for the asynchronous version. @@ -503,9 +511,9 @@ Rotates an image around the origin (0,0) and then shifts it. gpu::copyMakeBorder ----------------------- -Copies a 2D array to a larger destination array and pads borders with the given constant. +Forms a border around an image. -.. ocv:function:: void gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, const Scalar& value = Scalar(), Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::copyMakeBorder(const GpuMat& src, GpuMat& dst, int top, int bottom, int left, int right, int borderType, const Scalar& value = Scalar(), Stream& stream = Stream::Null()) :param src: Source image. ``CV_8UC1`` , ``CV_8UC4`` , ``CV_32SC1`` , and ``CV_32FC1`` types are supported. @@ -519,6 +527,8 @@ Copies a 2D array to a larger destination array and pads borders with the given :param right: Number of pixels in each direction from the source image rectangle to extrapolate. For example: ``top=1, bottom=1, left=1, right=1`` mean that 1 pixel-wide border needs to be built. + :param borderType: Border type. See :ocv:func:`borderInterpolate` for details. ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now. + :param value: Border value. :param stream: Stream for the asynchronous version. @@ -685,43 +695,17 @@ Builds spherical warping maps. -gpu::downsample -------------------- -Downsamples image by rejecting even rows and columns. - -.. ocv:function:: void gpu::downsample(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) - - :param src: Source image. - - :param dst: Destination image. Will have ``Size((src.cols+1)/2, (src.rows+1)/2)`` size and the same type as ``src`` . - - :param stream: Stream for the asynchronous version. - - - -gpu::upsample -------------------- -Upsamples the source image by injecting even zero rows and columns. - -.. ocv:function:: void gpu::upsample(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) - - :param src: Source image. - - :param dst: Destination image. Will have ``Size(src.cols*2, src.rows*2)`` size and the same type as ``src`` . - - :param stream: Stream for the asynchronous version. - - - gpu::pyrDown ------------------- Smoothes an image and downsamples it. -.. ocv:function:: void gpu::pyrDown(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::pyrDown(const GpuMat& src, GpuMat& dst, int borderType = BORDER_DEFAULT, Stream& stream = Stream::Null()) :param src: Source image. :param dst: Destination image. Will have ``Size((src.cols+1)/2, (src.rows+1)/2)`` size and the same type as ``src`` . + + :param borderType: Pixel extrapolation method (see :ocv:func:`borderInterpolate` ). ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now. :param stream: Stream for the asynchronous version. @@ -733,11 +717,13 @@ gpu::pyrUp ------------------- Upsamples an image and then smoothes it. -.. ocv:function:: void gpu::pyrUp(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::pyrUp(const GpuMat& src, GpuMat& dst, int borderType = BORDER_DEFAULT, Stream& stream = Stream::Null()) :param src: Source image. :param dst: Destination image. Will have ``Size(src.cols*2, src.rows*2)`` size and the same type as ``src`` . + + :param borderType: Pixel extrapolation method (see :ocv:func:`borderInterpolate` ). ``BORDER_REFLECT101`` , ``BORDER_REPLICATE`` , ``BORDER_CONSTANT`` , ``BORDER_REFLECT`` and ``BORDER_WRAP`` are supported for now. :param stream: Stream for the asynchronous version. diff --git a/modules/gpu/doc/initalization_and_information.rst b/modules/gpu/doc/initalization_and_information.rst index 24df72924..a3f730472 100644 --- a/modules/gpu/doc/initalization_and_information.rst +++ b/modules/gpu/doc/initalization_and_information.rst @@ -60,6 +60,7 @@ Class providing GPU computing features. :: FEATURE_SET_COMPUTE_20, FEATURE_SET_COMPUTE_21, GLOBAL_ATOMICS, + SHARED_ATOMICS, NATIVE_DOUBLE }; diff --git a/modules/gpu/doc/matrix_reductions.rst b/modules/gpu/doc/matrix_reductions.rst index cbd5ce0f6..965dce46e 100644 --- a/modules/gpu/doc/matrix_reductions.rst +++ b/modules/gpu/doc/matrix_reductions.rst @@ -156,3 +156,33 @@ Counts non-zero matrix elements. The function does not work with ``CV_64F`` images on GPUs with the compute capability < 1.3. .. seealso:: :ocv:func:`countNonZero` + + + +gpu::reduce +------ +Reduces a matrix to a vector. + +.. ocv:function:: void gpu::reduce(const GpuMat& mtx, GpuMat& vec, int dim, int reduceOp, int dtype = -1, Stream& stream = Stream::Null()) + + :param mtx: Source 2D matrix. + + :param vec: Destination vector. Its size and type is defined by ``dim`` and ``dtype`` parameters. + + :param dim: Dimension index along which the matrix is reduced. 0 means that the matrix is reduced to a single row. 1 means that the matrix is reduced to a single column. + + :param reduceOp: Reduction operation that could be one of the following: + + * **CV_REDUCE_SUM** The output is the sum of all rows/columns of the matrix. + + * **CV_REDUCE_AVG** The output is the mean vector of all rows/columns of the matrix. + + * **CV_REDUCE_MAX** The output is the maximum (column/row-wise) of all rows/columns of the matrix. + + * **CV_REDUCE_MIN** The output is the minimum (column/row-wise) of all rows/columns of the matrix. + + :param dtype: When it is negative, the destination vector will have the same type as the source matrix. Otherwise, its type will be ``CV_MAKE_TYPE(CV_MAT_DEPTH(dtype), mtx.channels())`` . + +The function ``reduce`` reduces the matrix to a vector by treating the matrix rows/columns as a set of 1D vectors and performing the specified operation on the vectors until a single row/column is obtained. For example, the function can be used to compute horizontal and vertical projections of a raster image. In case of ``CV_REDUCE_SUM`` and ``CV_REDUCE_AVG`` , the output may have a larger element bit-depth to preserve accuracy. And multi-channel arrays are also supported in these two reduction modes. + +.. seealso:: :ocv:func:`reduce` diff --git a/modules/gpu/doc/operations_on_matrices.rst b/modules/gpu/doc/operations_on_matrices.rst index 56fda87cb..3d91ab767 100644 --- a/modules/gpu/doc/operations_on_matrices.rst +++ b/modules/gpu/doc/operations_on_matrices.rst @@ -5,6 +5,42 @@ Operations on Matrices +gpu::gemm +------------------ +Performs generalized matrix multiplication. + +.. ocv:function:: void gemm(const GpuMat& src1, const GpuMat& src2, double alpha, const GpuMat& src3, double beta, GpuMat& dst, int flags = 0, Stream& stream = Stream::Null()) + + :param src1: First multiplied input matrix that should have ``CV_32FC1`` , ``CV_64FC1`` , ``CV_32FC2`` , or ``CV_64FC2`` type. + + :param src2: Second multiplied input matrix of the same type as ``src1`` . + + :param alpha: Weight of the matrix product. + + :param src3: Third optional delta matrix added to the matrix product. It should have the same type as ``src1`` and ``src2`` . + + :param beta: Weight of ``src3`` . + + :param dst: Destination matrix. It has the proper size and the same type as input matrices. + + :param flags: Operation flags: + + * **GEMM_1_T** transpose ``src1`` + * **GEMM_2_T** transpose ``src2`` + * **GEMM_3_T** transpose ``src3`` + + :param stream: Stream for the asynchronous version. + +The function performs generalized matrix multiplication similar to the ``gemm`` functions in BLAS level 3. For example, ``gemm(src1, src2, alpha, src3, beta, dst, GEMM_1_T + GEMM_3_T)`` corresponds to + +.. math:: + + \texttt{dst} = \texttt{alpha} \cdot \texttt{src1} ^T \cdot \texttt{src2} + \texttt{beta} \cdot \texttt{src3} ^T + +.. seealso:: :ocv:func:`gemm` + + + gpu::transpose ------------------ Transposes a matrix. diff --git a/modules/gpu/doc/per_element_operations.rst b/modules/gpu/doc/per_element_operations.rst index 00e534298..527b97de9 100644 --- a/modules/gpu/doc/per_element_operations.rst +++ b/modules/gpu/doc/per_element_operations.rst @@ -9,15 +9,19 @@ gpu::add ------------ Computes a matrix-matrix or matrix-scalar sum. -.. ocv:function:: void gpu::add(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::add(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()) -.. ocv:function:: void gpu::add(const GpuMat& src1, const Scalar& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::add(const GpuMat& src1, const Scalar& src2, GpuMat& dst, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()) - :param src1: First source matrix. ``CV_8UC1`` , ``CV_8UC4`` , ``CV_32SC1`` , and ``CV_32FC1`` matrices are supported for now. Version with scalar supports only ``CV_32FC1`` and ``CV_32FC2`` matrices. + :param src1: First source matrix. - :param src2: Second source matrix or a scalar to be added to ``src1`` . + :param src2: Second source matrix or a scalar to be added to ``src1`` . Matrix should have the same size and type as ``src1`` . - :param dst: Destination matrix with the same size and type as ``src1`` . + :param dst: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``src1`` depth. + + :param mask: Optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. + + :param dtype: Optional depth of the output array. :param stream: Stream for the asynchronous version. @@ -29,15 +33,19 @@ gpu::subtract ----------------- Computes a matrix-matrix or matrix-scalar difference. -.. ocv:function:: void gpu::subtract(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::subtract(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()) -.. ocv:function:: void gpu::subtract(const GpuMat& src1, const Scalar& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::subtract(const GpuMat& src1, const Scalar& src2, GpuMat& dst, const GpuMat& mask = GpuMat(), int dtype = -1, Stream& stream = Stream::Null()) - :param src1: First source matrix. ``CV_8UC1`` , ``CV_8UC4`` , ``CV_32SC1`` , and ``CV_32FC1`` matrices are supported for now. Version with scalar supports only ``CV_32FC1`` and ``CV_32FC2`` matrices. + :param src1: First source matrix. - :param src2: Second source matrix or a scalar to be subtracted from ``src1`` . + :param src2: Second source matrix or a scalar to be added to ``src1`` . Matrix should have the same size and type as ``src1`` . - :param dst: Destination matrix with the same size and type as ``src1`` . + :param dst: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``src1`` depth. + + :param mask: Optional operation mask, 8-bit single channel array, that specifies elements of the destination array to be changed. + + :param dtype: Optional depth of the output array. :param stream: Stream for the asynchronous version. @@ -49,15 +57,19 @@ gpu::multiply ----------------- Computes a matrix-matrix or matrix-scalar per-element product. -.. ocv:function:: void gpu::multiply(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::multiply(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) -.. ocv:function:: void gpu::multiply(const GpuMat& src1, const Scalar& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::multiply(const GpuMat& src1, const Scalar& src2, GpuMat& dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) - :param src1: First source matrix. ``CV_8UC1`` , ``CV_8UC4`` , ``CV_32SC1`` , and ``CV_32FC1`` matrices are supported for now. Version with scalar supports only ``CV_32FC1`` matrices. + :param src1: First source matrix. :param src2: Second source matrix or a scalar to be multiplied by ``src1`` elements. - :param dst: Destination matrix with the same size and type as ``src1`` . + :param dst: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``src1`` depth. + + :param scale: Optional scale factor. + + :param dtype: Optional depth of the output array. :param stream: Stream for the asynchronous version. @@ -67,17 +79,23 @@ Computes a matrix-matrix or matrix-scalar per-element product. gpu::divide --------------- -Computes a matrix-matrix or matrix-scalar sum. +Computes a matrix-matrix or matrix-scalar division. -.. ocv:function:: void gpu::divide(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::divide(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) -.. ocv:function:: void gpu::divide(const GpuMat& src1, const Scalar& src2, GpuMat& dst, Stream& stream = Stream::Null()) +.. ocv:function:: void gpu::divide(const GpuMat& src1, const Scalar& src2, GpuMat& dst, double scale = 1, int dtype = -1, Stream& stream = Stream::Null()) - :param src1: First source matrix. ``CV_8UC1`` , ``CV_8UC4`` , ``CV_32SC1`` , and ``CV_32FC1`` matrices are supported for now. Version with scalar supports only ``CV_32FC1`` matrices. +.. ocv:function:: void gpu::divide(double src1, const GpuMat& src2, GpuMat& dst, int dtype = -1, Stream& stream = Stream::Null()) + + :param src1: First source matrix or a scalar. :param src2: Second source matrix or a scalar. The ``src1`` elements are divided by it. - :param dst: Destination matrix with the same size and type as ``src1`` . + :param dst: Destination matrix that has the same size and number of channels as the input array(s). The depth is defined by ``dtype`` or ``src1`` depth. + + :param scale: Optional scale factor. + + :param dtype: Optional depth of the output array. :param stream: Stream for the asynchronous version. @@ -87,6 +105,42 @@ This function, in contrast to :ocv:func:`divide`, uses a round-down rounding mod +addWeighted +--------------- +Computes the weighted sum of two arrays. + +.. ocv:function:: void gpu::addWeighted(const GpuMat& src1, double alpha, const GpuMat& src2, double beta, double gamma, GpuMat& dst, int dtype = -1, Stream& stream = Stream::Null()); + + :param src1: First source array. + + :param alpha: Weight for the first array elements. + + :param src2: Second source array of the same size and channel number as ``src1`` . + + :param beta: Weight for the second array elements. + + :param dst: Destination array that has the same size and number of channels as the input arrays. + + :param gamma: Scalar added to each sum. + + :param dtype: Optional depth of the destination array. When both input arrays have the same depth, ``dtype`` can be set to ``-1``, which will be equivalent to ``src1.depth()``. + + :param stream: Stream for the asynchronous version. + +The function ``addWeighted`` calculates the weighted sum of two arrays as follows: + +.. math:: + + \texttt{dst} (I)= \texttt{saturate} ( \texttt{src1} (I)* \texttt{alpha} + \texttt{src2} (I)* \texttt{beta} + \texttt{gamma} ) + +where ``I`` is a multi-dimensional index of array elements. In case of multi-channel arrays, each channel is processed independently. + +.. seealso:: :ocv:func:`addWeighted` + + + + + gpu::exp ------------ Computes an exponent of each matrix element. @@ -151,7 +205,7 @@ Computes per-element absolute difference of two matrices (or of a matrix and sca .. ocv:function:: void gpu::absdiff(const GpuMat& src1, const Scalar& src2, GpuMat& dst, Stream& stream = Stream::Null()) - :param src1: First source matrix. ``CV_8UC1`` , ``CV_8UC4`` , ``CV_32SC1`` and ``CV_32FC1`` matrices are supported for now. Version with scalar supports only ``CV_32FC1`` matrices. + :param src1: First source matrix. :param src2: Second source matrix or a scalar to be added to ``src1`` . @@ -169,11 +223,11 @@ Compares elements of two matrices. .. ocv:function:: void gpu::compare(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, int cmpop, Stream& stream = Stream::Null()) - :param src1: First source matrix. ``CV_8UC4`` and ``CV_32FC1`` matrices are supported for now. + :param src1: First source matrix. - :param src2: Second source matrix with the same size and type as ``a`` . + :param src2: Second source matrix with the same size and type as ``src1`` . - :param dst: Destination matrix with the same size as ``a`` and the ``CV_8UC1`` type. + :param dst: Destination matrix with the same size as ``src1`` and the ``CV_8UC1`` type. :param cmpop: Flag specifying the relation between the elements to be checked: diff --git a/modules/gpu/doc/video.rst b/modules/gpu/doc/video.rst new file mode 100644 index 000000000..b6c3dd1fe --- /dev/null +++ b/modules/gpu/doc/video.rst @@ -0,0 +1,76 @@ +Video Analysis +============== + +.. highlight:: cpp + + +gpu::BroxOpticalFlow +-------------------- +.. ocv:class:: gpu::BroxOpticalFlow + +Class computing the optical flow for two images using Brox et al Optical Flow algorithm ([Brox2004]_). :: + + class BroxOpticalFlow + { + public: + BroxOpticalFlow(float alpha_, float gamma_, float scale_factor_, int inner_iterations_, int outer_iterations_, int solver_iterations_); + + //! Compute optical flow + //! frame0 - source frame (supports only CV_32FC1 type) + //! frame1 - frame to track (with the same size and type as frame0) + //! u - flow horizontal component (along x axis) + //! v - flow vertical component (along y axis) + void operator ()(const GpuMat& frame0, const GpuMat& frame1, GpuMat& u, GpuMat& v, Stream& stream = Stream::Null()); + + //! flow smoothness + float alpha; + + //! gradient constancy importance + float gamma; + + //! pyramid scale factor + float scale_factor; + + //! number of lagged non-linearity iterations (inner loop) + int inner_iterations; + + //! number of warping iterations (number of pyramid levels) + int outer_iterations; + + //! number of linear system solver iterations + int solver_iterations; + + GpuMat buf; + }; + + + +gpu::interpolateFrames +---------------------- +Interpolate frames (images) using provided optical flow (displacement field). + +.. ocv:function:: void gpu::interpolateFrames(const GpuMat& frame0, const GpuMat& frame1, const GpuMat& fu, const GpuMat& fv, const GpuMat& bu, const GpuMat& bv, float pos, GpuMat& newFrame, GpuMat& buf, Stream& stream = Stream::Null()) + + :param frame0: First frame (32-bit floating point images, single channel). + + :param frame1: Second frame. Must have the same type and size as ``frame0`` . + + :param fu: Forward horizontal displacement. + + :param fv: Forward vertical displacement. + + :param bu: Backward horizontal displacement. + + :param bv: Backward vertical displacement. + + :param pos: New frame position. + + :param newFrame: Output image. + + :param buf: Temporary buffer, will have width x 6*height size, CV_32FC1 type and contain 6 GpuMat: occlusion masks for first frame, occlusion masks for second, interpolated forward horizontal flow, interpolated forward vertical flow, interpolated backward horizontal flow, interpolated backward vertical flow. + + :param stream: Stream for the asynchronous version. + + + +.. [Brox2004] T. Brox, A. Bruhn, N. Papenberg, J. Weickert. *High accuracy optical flow estimation based on a theory for warping*. ECCV 2004. diff --git a/modules/gpu/include/opencv2/gpu/gpu.hpp b/modules/gpu/include/opencv2/gpu/gpu.hpp index 90acd9d2f..953a72be1 100644 --- a/modules/gpu/include/opencv2/gpu/gpu.hpp +++ b/modules/gpu/include/opencv2/gpu/gpu.hpp @@ -598,7 +598,6 @@ CV_EXPORTS void pow(const GpuMat& src, double power, GpuMat& dst, Stream& stream CV_EXPORTS void log(const GpuMat& a, GpuMat& b, Stream& stream = Stream::Null()); //! compares elements of two arrays (c = a b) -//! supports CV_8UC4, CV_32FC1 types CV_EXPORTS void compare(const GpuMat& a, const GpuMat& b, GpuMat& c, int cmpop, Stream& stream = Stream::Null()); //! performs per-elements bit-wise inversion