Question

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


int main(int argc, char* argv[]){
    cvNamedWindow("Window1", CV_WINDOW_AUTOSIZE);
    IplImage* image = 0;
    ->->image = cvLoadImage(argv[1]);<-<-
    if(!image) printf("Unable to load image!");
    cvShowImage("Window1", image);
    char c = cvWaitKey(0);
    cvReleaseImage(&image);
    cvDestroyWindow("Window1");
    return 0;
}

If I replace the indicated line with cvLoadImage("247.png") I get a blank window and image remains equal to zero

If I run the exe and give it 247.png as an argument, it's just dandy. If I put the "247.png" right into the code and build and run it Visual Studio 2008, it fails. If I build and run from the command prompt, it works.

Why is this? I'm a little bit weary of moving forwards without getting this down.

Was it helpful?

Solution

Under Project->Properties->Configuration Properties->Debugging there is a field "Working Directory". Set that to the directory you want to execute in and that should fix the problem.

OTHER TIPS

Are you certain "247.png" is in the current working directory when you have the name hardcoded?

Run the program under something like Process Monitor to see what file is really being opened (or what file I/O errors there might be).

After your edit to add more information to the question (the problem occurs when run from VS2008) this is almost certainly your problem. The current directory that VS starts the program under is not the directory that has the "247.png" file.

Can you check to see what your cwd is?

You can #include <direct.h> and use the _getcwd function to see what it is. That will probably point you to the culprit.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top