Thursday, April 29, 2010

My first Program

Like all the Programming Language books start with the Hello-World Program, I start my blog with a program in OpenCV to display an image..

Program:


#include < cv.h >
#include
< highgui.h >

using namespace std;

int main(int argc, char** argv)
{

    if(argc < 1 || argv[1] ==NULL)
    {
        return -1;
    }

    //Function which loads the image into an IplImage object
    IplImage* img = cvLoadImage(argv[1]);

    //Creates a window object to hold the image
    cvNamedWindow("My Picture");

    //show the image
    cvShowImage("My Picture",img);

    //Wait for some key to be pressed indefinitely
    while(1)
    {
     char c = cvWaitKey();
     //if escape character is pressed, break out of the loop
     if( c == 27 ) break;
    }

     //Release IplImage object
    cvReleaseImage( &img );

    cvDestroyWindow("My Picture");

    return(EXIT_SUCCESS);
}

Output:


No comments:

Post a Comment

Give ur thoughts!