Guest User

Untitled

a guest
Jul 16th, 2018
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. C++ main.cpp:
  2.  
  3. ```
  4. #include <opencv2/core/core.hpp>
  5. #include <opencv2/imgcodecs.hpp>
  6. #include <opencv2/highgui/highgui.hpp>
  7. #include <iostream>
  8. #include <string>
  9.  
  10. using namespace cv;
  11. using namespace std;
  12.  
  13. int main(int argc, char** argv) {
  14. string imageName("./images.jpeg"); // by default
  15. if (argc > 1) {
  16. imageName = argv[1];
  17. }
  18.  
  19. Mat image;
  20. image = imread(imageName.c_str(), IMREAD_COLOR);
  21. if (image.empty()) {
  22. cout << "Could not open or find the image" << std::endl ;
  23. return -1;
  24. }
  25. cout << "Initial image dimension: " << image.cols << " X " << image.rows << endl;
  26.  
  27. namedWindow( "Display window", WINDOW_AUTOSIZE );
  28. imshow( "Display window", image );
  29. waitKey(0);
  30.  
  31. const int cropSize = 128;
  32. const int offsetW = (image.cols - cropSize) / 2;
  33. const int offsetH = (image.rows - cropSize) / 2;
  34. const Rect roi(offsetW, offsetH, cropSize, cropSize);
  35. image = image(roi).clone();
  36. cout << "Cropped image dimension: " << image.cols << " X " << image.rows << endl;
  37.  
  38. imshow( "Display window", image );
  39. waitKey(0);
  40. return 0;
  41. }
  42. ```
  43.  
  44. Compile:
  45.  
  46. ```
  47. g++ -std=c++11 main.cpp `pkg-config --libs --cflags opencv` -o main
  48. ```
Add Comment
Please, Sign In to add comment