-
Notifications
You must be signed in to change notification settings - Fork 0
/
'
86 lines (61 loc) · 2.17 KB
/
'
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
//header files
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
//#include <iostream>
#include <stdio.h>
//using namespaces
using namespace cv;
//using namespace std;
int main()
{
//create two empty windows
namedWindow("Original Image", CV_WINDOW_AUTOSIZE);
namedWindow("Smoothed Image", CV_WINDOW_AUTOSIZE);
namedWindow("Gaussian Smooth", CV_WINDOW_AUTOSIZE);
//Load an image from file
Mat src = imread("test.jpg");
//show the loaded image
imshow("Original Image", src);
Mat dst, gdst;
char zBuffer[35];
for(int i=1;i<31;i=i+2)
{
//copy the text to the "zBuffer"
snprintf(zBuffer, 35, "Kernel Size: %d x %d",i,i);
//smooth the image in the "src" and save it to "dst"
blur(src, dst, Size(i,i));
//smooth the image using Gaussian kernel in the "src" and save it to "dst"
GaussianBlur(src, gdst, Size(i,i),0,0, BORDER_REPLICATE);
//put the text in the "zBuffer" to the "dst"image
putText(dst, zBuffer, Point(src.cols/4, src.rows/8), CV_FONT_HERSHEY_COMPLEX,1,Scalar(255,255,255));
//show the blurred image with the text
imshow("Smoothed Image", dst);
putText(gdst, zBuffer, Point(src.cols/4, src.rows/8), CV_FONT_HERSHEY_COMPLEX,1,Scalar(255,255,255));
//show the Gaussian Smooth image
imshow("Gaussian Smooth", dst);
//wait for 2 seconds
int c = waitKey(2000);
//if the "esc" key is pressed during the wait, return
if(c==27)
{
return 0;
}
}
//make the "dst" image, black
dst = Mat::zeros(src.size(), src.type());
//make the "dst" image, black
gdst = Mat::zeros(src.size(), src.type());
//copy the text to the "zBuffer"
snprintf(zBuffer, 35, "Press any key to Exit");
//put the text in the "zBuffer" to the "dst" image
putText(dst, zBuffer, Point(src.cols/4, src.rows/2), CV_FONT_HERSHEY_COMPLEX,1,Scalar(255,255,255));
//show the black image with the text
imshow("Smoothed Image", dst);
//put the text in the "zBuffer" to the "dst" image
putText(gdst, zBuffer, Point(src.cols/4, src.rows/2), CV_FONT_HERSHEY_COMPLEX,1,Scalar(255,255,255));
//show the image where gaussian blur is applied
imshow("Gaussian Smooth", gdst);
//wait for a key press infinitely
waitKey(0);
return 0;
}