Functions and classes described in this section are used to perform various linear or non-linear filtering operations on 2D images.
Note
gpu::
BaseRowFilter_GPU
¶Base class for linear or non-linear filters that processes rows of 2D arrays. Such filters are used for the “horizontal” filtering passes in separable filters.
class BaseRowFilter_GPU
{
public:
BaseRowFilter_GPU(int ksize_, int anchor_);
virtual ~BaseRowFilter_GPU() {}
virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
int ksize, anchor;
};
Note
This class does not allocate memory for a destination image. Usually this class is used inside gpu::FilterEngine_GPU
.
gpu::
BaseColumnFilter_GPU
¶Base class for linear or non-linear filters that processes columns of 2D arrays. Such filters are used for the “vertical” filtering passes in separable filters.
class BaseColumnFilter_GPU
{
public:
BaseColumnFilter_GPU(int ksize_, int anchor_);
virtual ~BaseColumnFilter_GPU() {}
virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
int ksize, anchor;
};
Note
This class does not allocate memory for a destination image. Usually this class is used inside gpu::FilterEngine_GPU
.
gpu::
BaseFilter_GPU
¶Base class for non-separable 2D filters.
class CV_EXPORTS BaseFilter_GPU
{
public:
BaseFilter_GPU(const Size& ksize_, const Point& anchor_);
virtual ~BaseFilter_GPU() {}
virtual void operator()(const GpuMat& src, GpuMat& dst, Stream& stream = Stream::Null()) = 0;
Size ksize;
Point anchor;
};
Note
This class does not allocate memory for a destination image. Usually this class is used inside gpu::FilterEngine_GPU
.
gpu::
FilterEngine_GPU
¶Base class for the Filter Engine.
class CV_EXPORTS FilterEngine_GPU
{
public:
virtual ~FilterEngine_GPU() {}
virtual void apply(const GpuMat& src, GpuMat& dst,
Rect roi = Rect(0,0,-1,-1), Stream& stream = Stream::Null()) = 0;
};
The class can be used to apply an arbitrary filtering operation to an image. It contains all the necessary intermediate buffers. Pointers to the initialized FilterEngine_GPU
instances are returned by various create*Filter_GPU
functions (see below), and they are used inside high-level functions such as gpu::filter2D()
, gpu::erode()
, gpu::Sobel()
, and others.
By using FilterEngine_GPU
instead of functions you can avoid unnecessary memory allocation for intermediate buffers and get better performance:
while (...)
{
gpu::GpuMat src = getImg();
gpu::GpuMat dst;
// Allocate and release buffers at each iterations
gpu::GaussianBlur(src, dst, ksize, sigma1);
}
// Allocate buffers only once
cv::Ptr<gpu::FilterEngine_GPU> filter =
gpu::createGaussianFilter_GPU(CV_8UC4, ksize, sigma1);
while (...)
{
gpu::GpuMat src = getImg();
gpu::GpuMat dst;
filter->apply(src, dst, cv::Rect(0, 0, src.cols, src.rows));
}
// Release buffers only once
filter.release();
FilterEngine_GPU
can process a rectangular sub-region of an image. By default, if roi == Rect(0,0,-1,-1)
, FilterEngine_GPU
processes the inner region of an image ( Rect(anchor.x, anchor.y, src_size.width - ksize.width, src_size.height - ksize.height)
) because some filters do not check whether indices are outside the image for better performance. See below to understand which filters support processing the whole image and which do not and identify image type limitations.
Note
The GPU filters do not support the in-place mode.
See also
gpu::BaseRowFilter_GPU
, gpu::BaseColumnFilter_GPU
, gpu::BaseFilter_GPU
, gpu::createFilter2D_GPU()
, gpu::createSeparableFilter_GPU()
, gpu::createBoxFilter_GPU()
, gpu::createMorphologyFilter_GPU()
, gpu::createLinearFilter_GPU()
, gpu::createSeparableLinearFilter_GPU()
, gpu::createDerivFilter_GPU()
, gpu::createGaussianFilter_GPU()
Creates a non-separable filter engine with the specified filter.
Ptr<FilterEngine_GPU> gpu::
createFilter2D_GPU
(const Ptr<BaseFilter_GPU>& filter2D, int srcType, int dstType)¶Parameters: |
|
---|
Usually this function is used inside such high-level functions as gpu::createLinearFilter_GPU()
, gpu::createBoxFilter_GPU()
.
Creates a separable filter engine with the specified filters.
Ptr<FilterEngine_GPU> gpu::
createSeparableFilter_GPU
(const Ptr<BaseRowFilter_GPU>& rowFilter, const Ptr<BaseColumnFilter_GPU>& columnFilter, int srcType, int bufType, int dstType)¶Parameters: |
|
---|
Usually this function is used inside such high-level functions as gpu::createSeparableLinearFilter_GPU()
.
Creates a horizontal 1D box filter.
Ptr<BaseRowFilter_GPU> gpu::
getRowSumFilter_GPU
(int srcType, int sumType, int ksize, int anchor=-1)¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
Creates a vertical 1D box filter.
Ptr<BaseColumnFilter_GPU> gpu::
getColumnSumFilter_GPU
(int sumType, int dstType, int ksize, int anchor=-1)¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
Creates a normalized 2D box filter.
Ptr<FilterEngine_GPU> gpu::
createBoxFilter_GPU
(int srcType, int dstType, const Size& ksize, const Point& anchor=Point(-1,-1))¶
Ptr<BaseFilter_GPU> gpu::
getBoxFilter_GPU
(int srcType, int dstType, const Size& ksize, Point anchor=Point(-1, -1))¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Smooths the image using the normalized box filter.
void gpu::
boxFilter
(const GpuMat& src, GpuMat& dst, int ddepth, Size ksize, Point anchor=Point(-1,-1), Stream& stream=Stream::Null())¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Acts as a synonym for the normalized box filter.
void gpu::
blur
(const GpuMat& src, GpuMat& dst, Size ksize, Point anchor=Point(-1,-1), Stream& stream=Stream::Null())¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Creates a 2D morphological filter.
Ptr<FilterEngine_GPU> gpu::
createMorphologyFilter_GPU
(int op, int type, const Mat& kernel, const Point& anchor=Point(-1,-1), int iterations=1)¶
Ptr<BaseFilter_GPU> gpu::
getMorphologyFilter_GPU
(int op, int type, const Mat& kernel, const Size& ksize, Point anchor=Point(-1,-1))¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Erodes an image by using a specific structuring element.
void gpu::
erode
(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor=Point(-1, -1), int iterations=1 )¶
void gpu::
erode
(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf, Point anchor=Point(-1, -1), int iterations=1, Stream& stream=Stream::Null() )¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Dilates an image by using a specific structuring element.
void gpu::
dilate
(const GpuMat& src, GpuMat& dst, const Mat& kernel, Point anchor=Point(-1, -1), int iterations=1 )¶
void gpu::
dilate
(const GpuMat& src, GpuMat& dst, const Mat& kernel, GpuMat& buf, Point anchor=Point(-1, -1), int iterations=1, Stream& stream=Stream::Null() )¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Applies an advanced morphological operation to an image.
void gpu::
morphologyEx
(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, Point anchor=Point(-1, -1), int iterations=1 )¶
void gpu::
morphologyEx
(const GpuMat& src, GpuMat& dst, int op, const Mat& kernel, GpuMat& buf1, GpuMat& buf2, Point anchor=Point(-1, -1), int iterations=1, Stream& stream=Stream::Null() )¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Creates a non-separable linear filter.
Ptr<FilterEngine_GPU> gpu::
createLinearFilter_GPU
(int srcType, int dstType, const Mat& kernel, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT)¶Parameters: |
|
---|
See also
Applies the non-separable 2D linear filter to an image.
void gpu::
filter2D
(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernel, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT, Stream& stream=Stream::Null())¶Parameters: |
|
---|
See also
Applies the Laplacian operator to an image.
void gpu::
Laplacian
(const GpuMat& src, GpuMat& dst, int ddepth, int ksize=1, double scale=1, int borderType=BORDER_DEFAULT, Stream& stream=Stream::Null())¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
See also
Creates a primitive row filter with the specified kernel.
Ptr<BaseRowFilter_GPU> gpu::
getLinearRowFilter_GPU
(int srcType, int bufType, const Mat& rowKernel, int anchor=-1, int borderType=BORDER_DEFAULT )¶Parameters: |
|
---|
There are two versions of the algorithm: NPP and OpenCV.
- NPP version is called when
srcType == CV_8UC1
orsrcType == CV_8UC4
andbufType == srcType
. Otherwise, the OpenCV version is called. NPP supports onlyBORDER_CONSTANT
border type and does not check indices outside the image.- OpenCV version supports only
CV_32F
buffer depth andBORDER_REFLECT101
,BORDER_REPLICATE
, andBORDER_CONSTANT
border types. It checks indices outside the image.
See also
Creates a primitive column filter with the specified kernel.
Ptr<BaseColumnFilter_GPU> gpu::
getLinearColumnFilter_GPU
(int bufType, int dstType, const Mat& columnKernel, int anchor=-1, int borderType=BORDER_DEFAULT )¶Parameters: |
|
---|
There are two versions of the algorithm: NPP and OpenCV.
- NPP version is called when
dstType == CV_8UC1
ordstType == CV_8UC4
andbufType == dstType
. Otherwise, the OpenCV version is called. NPP supports onlyBORDER_CONSTANT
border type and does not check indices outside the image.- OpenCV version supports only
CV_32F
buffer depth andBORDER_REFLECT101
,BORDER_REPLICATE
, andBORDER_CONSTANT
border types. It checks indices outside image.
Creates a separable linear filter engine.
Ptr<FilterEngine_GPU> gpu::
createSeparableLinearFilter_GPU
(int srcType, int dstType, const Mat& rowKernel, const Mat& columnKernel, const Point& anchor=Point(-1,-1), int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1)¶Parameters: |
|
---|
Applies a separable 2D linear filter to an image.
void gpu::
sepFilter2D
(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY, Point anchor=Point(-1,-1), int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1 )¶
void gpu::
sepFilter2D
(const GpuMat& src, GpuMat& dst, int ddepth, const Mat& kernelX, const Mat& kernelY, GpuMat& buf, Point anchor=Point(-1,-1), int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1, Stream& stream=Stream::Null() )¶Parameters: |
|
---|
Creates a filter engine for the generalized Sobel operator.
Ptr<FilterEngine_GPU> gpu::
createDerivFilter_GPU
(int srcType, int dstType, int dx, int dy, int ksize, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1)¶Parameters: |
|
---|
Applies the generalized Sobel operator to an image.
void gpu::
Sobel
(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, int ksize=3, double scale=1, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1 )¶
void gpu::
Sobel
(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, int ksize=3, double scale=1, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1, Stream& stream=Stream::Null() )¶Parameters: |
|
---|
Calculates the first x- or y- image derivative using the Scharr operator.
void gpu::
Scharr
(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, double scale=1, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1 )¶
void gpu::
Scharr
(const GpuMat& src, GpuMat& dst, int ddepth, int dx, int dy, GpuMat& buf, double scale=1, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1, Stream& stream=Stream::Null() )¶Parameters: |
|
---|
Creates a Gaussian filter engine.
Ptr<FilterEngine_GPU> gpu::
createGaussianFilter_GPU
(int type, Size ksize, double sigma1, double sigma2=0, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1 )¶Parameters: |
|
---|
Smooths an image using the Gaussian filter.
void gpu::
GaussianBlur
(const GpuMat& src, GpuMat& dst, Size ksize, double sigma1, double sigma2=0, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1 )¶
void gpu::
GaussianBlur
(const GpuMat& src, GpuMat& dst, Size ksize, GpuMat& buf, double sigma1, double sigma2=0, int rowBorderType=BORDER_DEFAULT, int columnBorderType=-1, Stream& stream=Stream::Null() )¶Parameters: |
|
---|
Creates the maximum filter.
Ptr<BaseFilter_GPU> gpu::
getMaxFilter_GPU
(int srcType, int dstType, const Size& ksize, Point anchor=Point(-1,-1))¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.
Creates the minimum filter.
Ptr<BaseFilter_GPU> gpu::
getMinFilter_GPU
(int srcType, int dstType, const Size& ksize, Point anchor=Point(-1,-1))¶Parameters: |
|
---|
Note
This filter does not check out-of-border accesses, so only a proper sub-matrix of a bigger matrix has to be passed to it.