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
86 lines (70 loc) · 2.4 KB

File metadata and controls

86 lines (70 loc) · 2.4 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
package opencvtutorial;
/**
* @file opencvtutorial.LaplaceDemo.java
* @brief Sample code showing how to detect edges using the Laplace operator
*/
import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;
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 LaplaceDemoRun {
public void run(String[] args) {
// ! [variables]
// Declare the variables we are going to use
Mat src, src_gray = new Mat(), dst = new Mat();
int kernel_size = 3;
int scale = 1;
int delta = 0;
int ddepth = CvType.CV_16S;
String window_name = "Laplace Demo";
// ! [variables]
// ! [load]
String imageName = ((args.length > 0) ? args[0] : "data/lena.jpg");
src = Imgcodecs.imread(imageName, Imgcodecs.IMREAD_COLOR); // Load an image
// 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]
// ! [reduce_noise]
// Reduce noise by blurring with a Gaussian filter ( kernel size = 3 )
Imgproc.GaussianBlur(src, src, new Size(3, 3), 0, 0, Core.BORDER_DEFAULT);
// ! [reduce_noise]
// ! [convert_to_gray]
// Convert the image to grayscale
Imgproc.cvtColor(src, src_gray, Imgproc.COLOR_RGB2GRAY);
// ! [convert_to_gray]
/// Apply Laplace function
Mat abs_dst = new Mat();
// ! [laplacian]
Imgproc.Laplacian(src_gray, dst, ddepth, kernel_size, scale, delta, Core.BORDER_DEFAULT);
// ! [laplacian]
// ! [convert]
// converting back to CV_8U
Core.convertScaleAbs(dst, abs_dst);
// ! [convert]
// ! [display]
HighGui.imshow(window_name, abs_dst);
HighGui.waitKey(0);
// ! [display]
System.exit(0);
}
}
public class LaplaceDemo {
static {
try {
// Load the native OpenCV library
NativeLoader.loadLibrary(Core.NATIVE_LIBRARY_NAME);
} catch (Exception e) {
}
}
public static void main(String[] args) {
new LaplaceDemoRun().run(args);
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.