Saturday, June 25, 2016

Blurring Image Using OpenCV

Posted by Md. Hanif Ali Sohag on Saturday, June 25, 2016 in | No comments
Blurring an image
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:
Blurring an Image


0 comments:

Post a Comment