Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/samples/java/tutorial_code/ImgProc/Pyramids/Pyramids.java
16344 views
1
import org.opencv.core.*;
2
import org.opencv.highgui.HighGui;
3
import org.opencv.imgcodecs.Imgcodecs;
4
import org.opencv.imgproc.Imgproc;
5
6
class PyramidsRun {
7
8
String window_name = "Pyramids Demo";
9
10
public void run(String[] args) {
11
/// General instructions
12
System.out.println("\n" +
13
" Zoom In-Out demo \n" +
14
"------------------ \n" +
15
" * [i] -> Zoom [i]n \n" +
16
" * [o] -> Zoom [o]ut \n" +
17
" * [ESC] -> Close program \n");
18
19
//! [load]
20
String filename = ((args.length > 0) ? args[0] : "../data/chicky_512.png");
21
22
// Load the image
23
Mat src = Imgcodecs.imread(filename);
24
25
// Check if image is loaded fine
26
if( src.empty() ) {
27
System.out.println("Error opening image!");
28
System.out.println("Program Arguments: [image_name -- default ../data/chicky_512.png] \n");
29
System.exit(-1);
30
}
31
//! [load]
32
33
//! [loop]
34
while (true){
35
//! [show_image]
36
HighGui.imshow( window_name, src );
37
//! [show_image]
38
char c = (char) HighGui.waitKey(0);
39
c = Character.toLowerCase(c);
40
41
if( c == 27 ){
42
break;
43
//![pyrup]
44
}else if( c == 'i'){
45
Imgproc.pyrUp( src, src, new Size( src.cols()*2, src.rows()*2 ) );
46
System.out.println( "** Zoom In: Image x 2" );
47
//![pyrup]
48
//![pyrdown]
49
}else if( c == 'o'){
50
Imgproc.pyrDown( src, src, new Size( src.cols()/2, src.rows()/2 ) );
51
System.out.println( "** Zoom Out: Image / 2" );
52
//![pyrdown]
53
}
54
}
55
//! [loop]
56
57
System.exit(0);
58
}
59
}
60
61
public class Pyramids {
62
public static void main(String[] args) {
63
// Load the native library.
64
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
65
new PyramidsRun().run(args);
66
}
67
}
68
69