[纯小白学习OpenCV系列]官方例程01:Load and Display an Image

时间:2023-03-08 16:35:48
[纯小白学习OpenCV系列]官方例程01:Load and Display an Image

Version: OpenCV 2.4.9

IDE    : VS2010

OS     : Windows

-----------------------------------------------------------------------------------

[纯小白学习OpenCV系列]官方例程01:Load and Display an Image

Goal
In this tutorial you will learn how to:
• Load an image (using imread)
• Create a named OpenCV window (using namedWindow)
• Display an image in an OpenCV window (using imshow)

Source Code

 #include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream> using namespace cv;
using namespace std; int main( int argc, char** argv )
{
if( argc != )
{
cout <<" Usage: display_image ImageToLoadAndDisplay" << endl;
return -;
} Mat image;
image = imread(argv[], CV_LOAD_IMAGE_COLOR); // Read the file if(! image.data ) // Check for invalid input
{
cout << "Could not open or find the image" << std::endl ;
return -;
} namedWindow( "Display window", WINDOW_AUTOSIZE );// Create a window for display.
imshow( "Display window", image ); // Show our image inside it. waitKey(); // Wait for a keystroke in the window
return ;
}