Read Image and Show them in OpenCV, nothing else
OpenCV API is very easy to manipulate image.
1. Read image from image file
2. Show the image in a window
- We use inread() to read an image to matrix which is called Mat in OpenCV
Mat mat = inread()
- Use inshow() to show image in OpenCV
/*
/Users/cat/myfile/bitbucket/opencv/loadimage.cpp
-----------------------------------------------------------------------
Wed Nov 28 16:03:20 2018
-----------------------------------------------------------------------
open an image only
-----------------------------------------------------------------------
Compile: runopencv loadimage.cpp => loadimage
Script: $b/runopencv.sh
-----------------------------------------------------------------------
*/
int main(int argc, char** argv) {
// Read the image file
String path = "/Users/cat/myfile/bitbucket/image/dog1.jpeg";
Mat image = imread(path);
// Check for failure
if (image.empty()) {
cout << "Could not open or find the image" << endl;
cout << "Image path=" << path << endl;
cin.get(); //wait for any key press
return -1;
}
String imageTitle = "Big dog"; //Name of the window
namedWindow(imageTitle); // Create a window
imshow(imageTitle, image); // Show our image inside the created window.
waitKey(0); // Wait for any keystroke in the window
destroyWindow(imageTitle); //destroy the created window
return 0;
}