Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
128 lines (103 loc) · 3.35 KB

File metadata and controls

128 lines (103 loc) · 3.35 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package opencvtutorial;
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.core.Size;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.scijava.nativelib.NativeLoader;
class SmoothingRun {
/// Global Variables
int DELAY_CAPTION = 1500;
int DELAY_BLUR = 100;
int MAX_KERNEL_LENGTH = 31;
Mat src = new Mat(), dst = new Mat();
String windowName = "Filter Demo 1";
public void run(String[] args) {
String filename = ((args.length > 0) ? args[0] : "data/lena.jpg");
src = Imgcodecs.imread(filename, Imgcodecs.IMREAD_COLOR);
if (src.empty()) {
System.out.println("Error opening image");
System.out.println("Usage: ./opencvtutorial.Smoothing [image_name -- default data/lena.jpg] \n");
System.exit(-1);
}
if (displayCaption("Original Image") != 0) {
System.exit(0);
}
dst = src.clone();
if (displayDst(DELAY_CAPTION) != 0) {
System.exit(0);
}
/// Applying Homogeneous blur
if (displayCaption("Homogeneous Blur") != 0) {
System.exit(0);
}
// ! [blur]
for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
Imgproc.blur(src, dst, new Size(i, i), new Point(-1, -1));
displayDst(DELAY_BLUR);
}
// ! [blur]
/// Applying Gaussian blur
if (displayCaption("Gaussian Blur") != 0) {
System.exit(0);
}
// ! [gaussianblur]
for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
Imgproc.GaussianBlur(src, dst, new Size(i, i), 0, 0);
displayDst(DELAY_BLUR);
}
// ! [gaussianblur]
/// Applying Median blur
if (displayCaption("Median Blur") != 0) {
System.exit(0);
}
// ! [medianblur]
for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
Imgproc.medianBlur(src, dst, i);
displayDst(DELAY_BLUR);
}
// ! [medianblur]
/// Applying Bilateral Filter
if (displayCaption("Bilateral Blur") != 0) {
System.exit(0);
}
// ![bilateralfilter]
for (int i = 1; i < MAX_KERNEL_LENGTH; i = i + 2) {
Imgproc.bilateralFilter(src, dst, i, i * 2, i / 2);
displayDst(DELAY_BLUR);
}
// ![bilateralfilter]
/// Done
displayCaption("Done!");
System.exit(0);
}
int displayCaption(String caption) {
dst = Mat.zeros(src.size(), src.type());
Imgproc.putText(dst, caption, new Point(src.cols() / 4, src.rows() / 2), Imgproc.FONT_HERSHEY_COMPLEX, 1,
new Scalar(255, 255, 255));
return displayDst(DELAY_CAPTION);
}
int displayDst(int delay) {
HighGui.imshow(windowName, dst);
int c = HighGui.waitKey(delay);
if (c >= 0) {
return -1;
}
return 0;
}
}
public class Smoothing {
static {
try {
// Load the native OpenCV library
NativeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (Exception e) {
}
}
public static void main(String[] args) {
new SmoothingRun().run(args);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.