The first line is to update the kernel_size to odd values in the range: . The second line actually builds the kernel by setting its value to a matrix filled with and normalizing it by dividing it between the number of elements.

After setting the kernel, we can generate the filter by using the function filter2D:

filter2D(src,dst,ddepth,kernel,anchor,delta,BORDER_DEFAULT);

The arguments denote:

src: Source image

dst: Destination image

ddepth: The depth of dst. A negative value (such as ) indicates that the depth is the same as the source.

kernel: The kernel to be scanned through the image

anchor: The position of the anchor relative to its kernel. The location Point(-1, -1) indicates the center by default.

delta: A value to be added to each pixel during the convolution. By default it is

BORDER_DEFAULT: We let this value by default (more details in the following tutorial)

Our program will effectuate a while loop, each 500 ms the kernel size of our filter will be updated in the range indicated.

After compiling the code above, you can execute it giving as argument the path of an image. The result should be a window that shows an image blurred by a normalized filter. Each 0.5 seconds the kernel size should change, as can be seen in the series of snapshots below: