2024-07-08
한어Русский языкEnglishFrançaisIndonesianSanskrit日本語DeutschPortuguêsΕλληνικάespañolItalianoSuomalainenLatina
OpenCVfilter2D
The convolution function is a very powerful tool for applying various linear filters to images. This function is able to process each pixel in the image and modify the characteristics of the image by convolving it with the specified convolution kernel (or filter). The following is aboutfilter2D
Function details:
In OpenCV,filter2D
The prototype of the function is as follows:
void cv::filter2D(InputArray src, OutputArray dst, int ddepth, InputArray kernel,
Point anchor = Point(-1,-1), double delta = 0,
int borderType = BORDER_DEFAULT);
src
Have the same size and number of channels.dst
Previously added to the filtered pixel.BORDER_CONSTANT
、BORDER_REPLICATE
、BORDER_REFLECT
wait.filter2D
The function actually performs a convolution operation (although technically, it computes a correlation rather than a strict convolution, since there is no flipping of the kernel involved). The convolution operation involves "sliding" the kernel over the input image and multiplying the corresponding elements of each submatrix that is the same size as the kernel, and then adding the results. This process generates a new pixel value that is placed at the corresponding position in the output image. This process is repeated as the kernel slides over the entire input image until the full output image is generated.
By changing the convolution kernel,filter2D
The function can achieve a variety of image processing effects, including but not limited to:
filter2D
The function itself does not directly provide the generation of Gaussian kernels, but it can be done throughgetGaussianKernel
The function generates a Gaussian kernel and usesfilter2D
Perform Gaussian filtering.The following is a usefilter2D
Sample code for mean filtering using the function (Python version):
#include