The first program for OpenCV  

Posted by shashank in

Due to midsems, for a few days I was unable to touch OpenCV. Hence just to open and display an image I took me quite some time. The following program may serve as a brush up in case such a thing happens again:

#include
#include
#include
#include
#include


int main(void){
IplImage *img =0;
img=cvLoadImage("Moon.jpg");
if(img == 0){
fprintf(stderr,"Cannot Load File.");
getchar();
return(1);
}

cvNamedWindow("image",CV_WINDOW_AUTOSIZE);
cvShowImage("image",img);
cvWaitKey(0);
cvDestroyWindow("image");
cvReleaseImage(&img);
return 0;
}


To the reader it will be obvious the exe file compiled should co-exist with a file named "Moon.jpg" in order for the same to be displayed. The header files are not visible due to html. To read the same the source code of this page can be viewed and you can search for "include".


One important function that deserves a mention for beginning with OpenCV programming is:
cvCreateImage(CvSize size, int depth, int channels)

This entry was posted on Thursday, October 8, 2009 at 12:45 AM and is filed under . You can follow any responses to this entry through the comments feed .

0 comments

Post a Comment