Life2Coding
Blurring Image Using OpenCV

Blurring an image

In blurring, we simple blur an image. An image looks sharper or more detailed if we are able to perceive all the objects and their shapes correctly in it. For example. An image with a face looks clear when we are able to identify eyes, ears, nose, lips, forehead e.t.c very clear. This shape of an object is due to its edges. So in blurring, we simply reduce the edge content and makes the transition from one color to the other very smooth.

In this tutorial, you will learn how to blur an image using image processing.

Code:

#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
Mat image, image_blurred;
int slider = 5;
void on_trackbar(int, void *) {
 
slider = slider % 2 == 0 ? slider + 1 : slider;
 
GaussianBlur(image, image_blurred, Size(slider, slider),0);
 
imshow("Blurred image", image_blurred);
 
}
 
int main() {
 
image = imread("c://test//baboon.jpg");
 
namedWindow("Original image");
namedWindow("Blurred image");
imshow("Original image", image);
GaussianBlur(image, image_blurred, Size(slider, slider), 0);
 
imshow("Blurred image", image_blurred);
createTrackbar("Kernel Size", "Blurred image", &slider, 41, on_trackbar);
 
while (char(waitKey(1) != 'q')) {}
return 0;
}

Output:

blur Blurring Image Using OpenCV

life2coding_icon [] Blurring Image Using OpenCV

One thought on “Blurring Image Using OpenCV

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.