8 Kasım 2010 Pazartesi

helloworld application for OpenCV

Below is given a code snippet which loads an image in your computer with the function cvLoadImage and displays it in a new window.

[code]
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
#include <iostream>
using namespace std;

int _tmain(int argc, _TCHAR* argv[])
{
        IplImage *img = cvLoadImage("C:\\work\\kn.jpg",1); //if the image is opening as a gray image rather than the image you want please make sure that the address of the image is true. You can check whether the image path is true or not by checking if the pointer *img is null or not.
if(img == NULL)
{
cout << "error" << endl;
}
        cvNamedWindow("Image:",CV_WINDOW_AUTOSIZE );
        cvShowImage("Image:",img);

        cvWaitKey();
        cvDestroyWindow("Image:");
        cvReleaseImage(&img);

        return 0;
}
[/code]

Hiç yorum yok:

Yorum Gönder