Blurring in OpenCV is achieved by using a sliding window on the image. This sliding window is essentially a matrix and is often called a kernel. You do not have to worry about implementing that, OpenCV does that. It has support for Gaussian blur and others.
C++ code OpenCV blur image:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
// OpenCV Blur Image. talkera.org/opencv
#include
#include
#include
#include
using namespace cv;
int main( int argc, char** argv )
{
char* imageName = argv[1];
Mat image;
image = imread( imageName, 1 );
if( argc != 2 || !image.data )
{
printf( " No image data \n " );
return -1;
}
blur(image,image,Size(10,10));
namedWindow( imageName, CV_WINDOW_AUTOSIZE );
imshow( imageName, image );
waitKey(0);
return 0;
}
|
Python code to blur image opencv
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
|
# Blur image with Opencv. talkera.org/opencv
import cv2
import numpy as np
from matplotlib import pyplot as plt
img = cv2.imread('cat.jpg')
kernel = np.ones((5,5),np.float32)/25
dst = cv2.filter2D(img,-1,kernel)
plt.subplot(121),plt.imshow(img),plt.title('Original')
plt.xticks([]), plt.yticks([])
plt.subplot(122),plt.imshow(dst),plt.title('Averaging')
plt.xticks([]), plt.yticks([])
plt.show()
|