/samples/cvcropimageroi.cpp

http://opencvx.googlecode.com/ · C++ · 57 lines · 50 code · 7 blank · 0 comment · 4 complexity · 27c2893d9e82bd1024f7093be49dc6e2 MD5 · raw file

  1. #ifdef _MSC_VER
  2. #pragma warning(disable:4996)
  3. #pragma comment(lib, "cv.lib")
  4. #pragma comment(lib, "cxcore.lib")
  5. #pragma comment(lib, "cvaux.lib")
  6. #pragma comment(lib, "highgui.lib")
  7. #endif
  8. #include <stdio.h>
  9. #include "cv.h"
  10. #include "highgui.h"
  11. #include "cvcropimageroi.h"
  12. int main( int argc, char** argv )
  13. {
  14. IplImage* img = NULL, *crop = NULL;
  15. int x = 0, y = 0, width = 1, height = 1;
  16. float angle = 0, shear_x = 0, shear_y = 0;
  17. if( argc < 2 )
  18. {
  19. fprintf( stderr, "Usage: cvcropimageroi <img> <x y width height angle shear_x shear_y>\n" );
  20. return 1;
  21. }
  22. img = cvLoadImage( argv[1] );
  23. if( argc >= 6 )
  24. {
  25. x = atoi( argv[2] );
  26. y = atoi( argv[3] );
  27. width = atoi( argv[4] );
  28. height = atoi( argv[5] );
  29. }
  30. if( argc >= 7 )
  31. {
  32. angle = atof( argv[6] );
  33. }
  34. if( argc >= 9 )
  35. {
  36. shear_x = atof( argv[7] );
  37. shear_y = atof( argv[8] );
  38. }
  39. crop = cvCreateImage( cvSize(width,height), img->depth, img->nChannels);
  40. cvCropImageROI( img, crop, cvRect32f(x,y,width,height,angle), cvPoint2D32f(shear_x,shear_y) );
  41. cvNamedWindow( "Image", CV_WINDOW_AUTOSIZE );
  42. cvShowImage( "Image", img );
  43. cvNamedWindow( "Crop", CV_WINDOW_AUTOSIZE );
  44. cvShowImage( "Crop", crop );
  45. cvWaitKey( 0 );
  46. cvDestroyWindow( "Image" );
  47. cvDestroyWindow( "Crop" );
  48. cvReleaseImage( &crop );
  49. return 0;
  50. }