parent
f7d85bfed8
commit
08515281b9
6 changed files with 298 additions and 121 deletions
@ -1,73 +0,0 @@ |
||||
/**
|
||||
* @file Pyramids.cpp |
||||
* @brief Sample code of image pyramids (pyrDown and pyrUp) |
||||
* @author OpenCV team |
||||
*/ |
||||
|
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/imgcodecs.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
|
||||
using namespace cv; |
||||
|
||||
/// Global variables
|
||||
Mat src, dst, tmp; |
||||
|
||||
const char* window_name = "Pyramids Demo"; |
||||
|
||||
|
||||
/**
|
||||
* @function main |
||||
*/ |
||||
int main( void ) |
||||
{ |
||||
/// General instructions
|
||||
printf( "\n Zoom In-Out demo \n " ); |
||||
printf( "------------------ \n" ); |
||||
printf( " * [u] -> Zoom in \n" ); |
||||
printf( " * [d] -> Zoom out \n" ); |
||||
printf( " * [ESC] -> Close program \n \n" ); |
||||
|
||||
//![load]
|
||||
src = imread( "../data/chicky_512.png" ); // Loads the test image
|
||||
if( src.empty() ) |
||||
{ printf(" No data! -- Exiting the program \n"); |
||||
return -1; } |
||||
//![load]
|
||||
|
||||
tmp = src; |
||||
dst = tmp; |
||||
|
||||
//![create_window]
|
||||
imshow( window_name, dst ); |
||||
//![create_window]
|
||||
|
||||
//![infinite_loop]
|
||||
for(;;) |
||||
{ |
||||
char c = (char)waitKey(0); |
||||
|
||||
if( c == 27 ) |
||||
{ break; } |
||||
//![pyrup]
|
||||
if( c == 'u' ) |
||||
{ pyrUp( tmp, dst, Size( tmp.cols*2, tmp.rows*2 ) ); |
||||
printf( "** Zoom In: Image x 2 \n" ); |
||||
} |
||||
//![pyrup]
|
||||
//![pyrdown]
|
||||
else if( c == 'd' ) |
||||
{ pyrDown( tmp, dst, Size( tmp.cols/2, tmp.rows/2 ) ); |
||||
printf( "** Zoom Out: Image / 2 \n" ); |
||||
} |
||||
//![pyrdown]
|
||||
imshow( window_name, dst ); |
||||
|
||||
//![update_tmp]
|
||||
tmp = dst; |
||||
//![update_tmp]
|
||||
} |
||||
//![infinite_loop]
|
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,69 @@ |
||||
/**
|
||||
* @file Pyramids.cpp |
||||
* @brief Sample code of image pyramids (pyrDown and pyrUp) |
||||
* @author OpenCV team |
||||
*/ |
||||
|
||||
#include "iostream" |
||||
#include "opencv2/imgproc.hpp" |
||||
#include "opencv2/imgcodecs.hpp" |
||||
#include "opencv2/highgui.hpp" |
||||
|
||||
using namespace std; |
||||
using namespace cv; |
||||
|
||||
const char* window_name = "Pyramids Demo"; |
||||
|
||||
/**
|
||||
* @function main |
||||
*/ |
||||
int main( int argc, char** argv ) |
||||
{ |
||||
/// General instructions
|
||||
cout << "\n Zoom In-Out demo \n " |
||||
"------------------ \n" |
||||
" * [i] -> Zoom in \n" |
||||
" * [o] -> Zoom out \n" |
||||
" * [ESC] -> Close program \n" << endl; |
||||
|
||||
//![load]
|
||||
const char* filename = argc >=2 ? argv[1] : "../data/chicky_512.png"; |
||||
|
||||
// Loads an image
|
||||
Mat src = imread( filename ); |
||||
|
||||
// Check if image is loaded fine
|
||||
if(src.empty()){ |
||||
printf(" Error opening image\n"); |
||||
printf(" Program Arguments: [image_name -- default ../data/chicky_512.png] \n"); |
||||
return -1; |
||||
} |
||||
//![load]
|
||||
|
||||
//![loop]
|
||||
for(;;) |
||||
{ |
||||
//![show_image]
|
||||
imshow( window_name, src ); |
||||
//![show_image]
|
||||
char c = (char)waitKey(0); |
||||
|
||||
if( c == 27 ) |
||||
{ break; } |
||||
//![pyrup]
|
||||
else if( c == 'i' ) |
||||
{ pyrUp( src, src, Size( src.cols*2, src.rows*2 ) ); |
||||
printf( "** Zoom In: Image x 2 \n" ); |
||||
} |
||||
//![pyrup]
|
||||
//![pyrdown]
|
||||
else if( c == 'o' ) |
||||
{ pyrDown( src, src, Size( src.cols/2, src.rows/2 ) ); |
||||
printf( "** Zoom Out: Image / 2 \n" ); |
||||
} |
||||
//![pyrdown]
|
||||
} |
||||
//![loop]
|
||||
|
||||
return 0; |
||||
} |
@ -0,0 +1,67 @@ |
||||
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) { |
||||
/// General instructions
|
||||
System.out.println("\n" + |
||||
" Zoom In-Out demo \n" + |
||||
"------------------ \n" + |
||||
" * [i] -> Zoom [i]n \n" + |
||||
" * [o] -> Zoom [o]ut \n" + |
||||
" * [ESC] -> Close program \n"); |
||||
|
||||
//! [load]
|
||||
String filename = ((args.length > 0) ? args[0] : "../data/chicky_512.png"); |
||||
|
||||
// Load the image
|
||||
Mat src = Imgcodecs.imread(filename); |
||||
|
||||
// Check if image is loaded fine
|
||||
if( src.empty() ) { |
||||
System.out.println("Error opening image!"); |
||||
System.out.println("Program Arguments: [image_name -- default ../data/chicky_512.png] \n"); |
||||
System.exit(-1); |
||||
} |
||||
//! [load]
|
||||
|
||||
//! [loop]
|
||||
while (true){ |
||||
//! [show_image]
|
||||
HighGui.imshow( window_name, src ); |
||||
//! [show_image]
|
||||
char c = (char) HighGui.waitKey(0); |
||||
c = Character.toLowerCase(c); |
||||
|
||||
if( c == 27 ){ |
||||
break; |
||||
//![pyrup]
|
||||
}else if( c == 'i'){ |
||||
Imgproc.pyrUp( src, src, new Size( src.cols()*2, src.rows()*2 ) ); |
||||
System.out.println( "** Zoom In: Image x 2" ); |
||||
//![pyrup]
|
||||
//![pyrdown]
|
||||
}else if( c == 'o'){ |
||||
Imgproc.pyrDown( src, src, new Size( src.cols()/2, src.rows()/2 ) ); |
||||
System.out.println( "** Zoom Out: Image / 2" ); |
||||
//![pyrdown]
|
||||
} |
||||
} |
||||
//! [loop]
|
||||
|
||||
System.exit(0); |
||||
} |
||||
} |
||||
|
||||
public class Pyramids { |
||||
public static void main(String[] args) { |
||||
// Load the native library.
|
||||
System.loadLibrary(Core.NATIVE_LIBRARY_NAME); |
||||
new PyramidsRun().run(args); |
||||
} |
||||
} |
@ -0,0 +1,51 @@ |
||||
import sys |
||||
import cv2 |
||||
|
||||
|
||||
def main(argv): |
||||
print(""" |
||||
Zoom In-Out demo |
||||
------------------ |
||||
* [i] -> Zoom [i]n |
||||
* [o] -> Zoom [o]ut |
||||
* [ESC] -> Close program |
||||
""") |
||||
## [load] |
||||
filename = argv[0] if len(argv) > 0 else "../data/chicky_512.png" |
||||
|
||||
# Load the image |
||||
src = cv2.imread(filename) |
||||
|
||||
# Check if image is loaded fine |
||||
if src is None: |
||||
print ('Error opening image!') |
||||
print ('Usage: pyramids.py [image_name -- default ../data/chicky_512.png] \n') |
||||
return -1 |
||||
## [load] |
||||
## [loop] |
||||
while 1: |
||||
rows, cols, _channels = map(int, src.shape) |
||||
## [show_image] |
||||
cv2.imshow('Pyramids Demo', src) |
||||
## [show_image] |
||||
k = cv2.waitKey(0) |
||||
|
||||
if k == 27: |
||||
break |
||||
## [pyrup] |
||||
elif chr(k) == 'i': |
||||
src = cv2.pyrUp(src, dstsize=(2 * cols, 2 * rows)) |
||||
print ('** Zoom In: Image x 2') |
||||
## [pyrup] |
||||
## [pyrdown] |
||||
elif chr(k) == 'o': |
||||
src = cv2.pyrDown(src, dstsize=(cols // 2, rows // 2)) |
||||
print ('** Zoom Out: Image / 2') |
||||
## [pyrdown] |
||||
## [loop] |
||||
|
||||
cv2.destroyAllWindows() |
||||
return 0 |
||||
|
||||
if __name__ == "__main__": |
||||
main(sys.argv[1:]) |
Loading…
Reference in new issue