Thursday, June 04, 2015

Loading and Displaying Images using OpenCV

Posted by Md.Hanif Ali on Thursday, June 04, 2015 in | 1 comment

Read image file and display

The code shows the procedures to import an image from file using the Opencv library.For this, open the C++ IDE ( like Qt Creator, Visual Studio C++, Codeblocks etc) and create a new project. The IDE has to be configured for running the opencv functions. 


#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
int main( int argc, char** argv )
    Mat src;
    src = imread("c:/open/me.jpg", CV_LOAD_IMAGE_COLOR);   // open colour image

    if(! )                              // Check input image
        std::cout <<  "No image found" << std::endl ;
        return -1;

    namedWindow( "Window", WINDOW_AUTOSIZE );// Create a window for display.
    imshow( "Window", src );                   // Show our image inside it.

    waitKey(0);                                          // Waiting for a keystroke to keep the screen visible
    return 0;


Read image file and display

1 comment: