March 2019
Intermediate to advanced
532 pages
13h 2m
English
OpenCV provides the cv2.filter2D() function in order to apply an arbitrary kernel to an image, convolving the image with the provided kernel. In order to see how this function works, we should first build the kernel that we will use later. In this case, a 5 x 5 kernel will be used, as shown in the following code:
kernel_averaging_5_5 = np.array([[0.04, 0.04, 0.04, 0.04, 0.04], [0.04, 0.04, 0.04, 0.04, 0.04], [0.04, 0.04, 0.04, 0.04, 0.04],[0.04, 0.04, 0.04, 0.04, 0.04], [0.04, 0.04, 0.04, 0.04, 0.04]])
This corresponds to a 5 x 5 averaging kernel. Additionally, you can also create the kernel like this:
kernel_averaging_5_5 = np.ones((5, 5), np.float32) / 25
Then we apply the kernel to the source image by applying ...