views:

240

answers:

2

I want to know exaclty what this program does:

#include <iostream>
#include <cv.h>
#include <cxcore.h>
#include <highgui.h>
using namespace std;
int main(int argc, char* argv[])
{
printf("Hello world\n");
IplImage *img = cvLoadImage("C:/Program Files/OpenCV/samples/c/lena.jpg");
// Create a window
cvNamedWindow( "result",
CV_WINDOW_AUTOSIZE // allow window to resize to fit image true size
);
cvShowImage( "result", img ); // Show image in window already created
// Wait for a keystroke. If a positive argument is given, it will wait for
// that number of milliseconds and then continue. If 0 is given, the
// program will wait indefinitely for a keypress.
cvWaitKey(0);
// Clean up (not really necessary, but good programming practice)
cvReleaseImage( &img );
cvDestroyWindow("result");
system("PAUSE");
return EXIT_SUCCESS;
}

The reason i'm asking is because I think that a picture is supposed to pop up when I run the program but instead for me, a grey box pops up.

Can someone please shed some light on this problem of mine? Thanks in advance.

+1  A: 

It loads an image

Shows the image

then wait for anykey (0)

On anykey press

frees the memory used and return EXIT_SUCCESS

It should work correctly, probably that the path isn't right

try to copy your image in your working folder and execute from there while removing the full path in your image address

"lena.jpg"

Also another option would be to try backward slashes

"C:\\Program Files\\OpenCV\\samples\\c\\lena.jpg"

EDIT *

You should run the diagnosis tests included with openCV

they are located in the opencv\bin directory and should be able to check if your installation is correct or not

Eric
I tried both the things that you have said but none of them work. I still get a grey box when I run the program.
Omar
A: 
virgoptrex