Created
July 16, 2018 22:27
-
-
Save 1duo/c868f0bccf0d1f6cd8b36086ba295e04 to your computer and use it in GitHub Desktop.
Revisions
-
1duo created this gist
Jul 16, 2018 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,48 @@ C++ main.cpp: ``` #include <opencv2/core/core.hpp> #include <opencv2/imgcodecs.hpp> #include <opencv2/highgui/highgui.hpp> #include <iostream> #include <string> using namespace cv; using namespace std; int main(int argc, char** argv) { string imageName("./images.jpeg"); // by default if (argc > 1) { imageName = argv[1]; } Mat image; image = imread(imageName.c_str(), IMREAD_COLOR); if (image.empty()) { cout << "Could not open or find the image" << std::endl ; return -1; } cout << "Initial image dimension: " << image.cols << " X " << image.rows << endl; namedWindow( "Display window", WINDOW_AUTOSIZE ); imshow( "Display window", image ); waitKey(0); const int cropSize = 128; const int offsetW = (image.cols - cropSize) / 2; const int offsetH = (image.rows - cropSize) / 2; const Rect roi(offsetW, offsetH, cropSize, cropSize); image = image(roi).clone(); cout << "Cropped image dimension: " << image.cols << " X " << image.rows << endl; imshow( "Display window", image ); waitKey(0); return 0; } ``` Compile: ``` g++ -std=c++11 main.cpp `pkg-config --libs --cflags opencv` -o main ```