import org.opencv.core.*;
import org.opencv.highgui.HighGui;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
class PyramidsRun {
String window_name = "Pyramids Demo";
public void run(String[] args) {
System.out.println("\n" +
图像缩放演示 +
"------------------ \n" +
* [i] -> 放大 +
* [o] -> 缩小 +
* [ESC] -> 关闭程序);
String filename = ((args.length > 0) ? args[0] : "../data/chicky_512.png");
Mat src = Imgcodecs.imread(filename);
if( src.empty() ) {
System.out.println("打开图像失败!");
System.out.println("程序参数:[图像名称 -- 默认 ../data/chicky_512.png] \n");
System.exit(-1);
}
while (true){
HighGui.imshow( window_name, src );
char c = (char) HighGui.waitKey(0);
c = Character.toLowerCase(c);
if( c == 27 ){
break;
}else if( c == 'i'){
Imgproc.pyrUp( src, src, new Size( src.cols()*2, src.rows()*2 ) );
System.out.println( "** 放大:图像 x 2" );
}else if( c == 'o'){
Imgproc.pyrDown( src, src, new Size( src.cols()/2, src.rows()/2 ) );
System.out.println( "** 缩小:图像 / 2" );
}
}
System.exit(0);
}
}
public class Pyramids {
public static void main(String[] args) {
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
new PyramidsRun().run(args);
}
}