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
94 lines (77 loc) · 2.59 KB

File metadata and controls

94 lines (77 loc) · 2.59 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
package opencvtutorial;
/**
* @file Filter2D_demo.java
* @brief Sample code that shows how to implement your own linear filters by using filter2D function
*/
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
import org.opencv.core.Point;
import org.opencv.core.Scalar;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.scijava.nativelib.NativeLoader;
class Filter2D_DemoRun {
public void run(String[] args) {
// Declare variables
Mat src, dst = new Mat();
Mat kernel = new Mat();
Point anchor;
double delta;
int ddepth;
int kernel_size;
String window_name = "filter2D Demo";
// ! [load]
String imageName = ((args.length > 0) ? args[0] : "data/lena.jpg");
// Load an image
src = Imgcodecs.imread(imageName, Imgcodecs.IMREAD_COLOR);
// Check if image is loaded fine
if (src.empty()) {
System.out.println("Error opening image!");
System.out.println("Program Arguments: [image_name -- default ../data/lena.jpg] \n");
System.exit(-1);
}
// ! [load]
// ! [init_arguments]
// Initialize arguments for the filter
anchor = new Point(-1, -1);
delta = 0.0;
ddepth = -1;
// ! [init_arguments]
// Loop - Will filter the image with different kernel sizes each 0.5 seconds
int ind = 0;
while (true) {
// ! [update_kernel]
// Update kernel size for a normalized box filter
kernel_size = 3 + 2 * (ind % 5);
Mat ones = Mat.ones(kernel_size, kernel_size, CvType.CV_32F);
Core.multiply(ones, new Scalar(1 / (double) (kernel_size * kernel_size)), kernel);
// ! [update_kernel]
// ! [apply_filter]
// Apply filter
Imgproc.filter2D(src, dst, ddepth, kernel, anchor, delta, Core.BORDER_DEFAULT);
// ! [apply_filter]
HighGui.imshow(window_name, dst);
int c = HighGui.waitKey(500);
// Press 'ESC' to exit the program
if (c == 27) {
break;
}
ind++;
}
System.exit(0);
}
}
public class Filter2DDemo {
static {
try {
// Load the native OpenCV library
NativeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (Exception e) {
}
}
public static void main(String[] args) {
new Filter2D_DemoRun().run(args);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.