views:

545

answers:

5

I've recently installed OpenCV2.0 under Visual Studio 2008 professional edition, built the libraries, dll-s and got everything working but when I run the first example program:

#include “highgui.h”
int main( int argc, char** argv ) {
IplImage* img = cvLoadImage( argv[1] );
cvNamedWindow( “Example1”, CV_WINDOW_AUTOSIZE );
cvShowImage( “Example1”, img );
cvWaitKey(0);
cvReleaseImage( &img );
cvDestroyWindow( “Example1” );
}

It goes straight into Debug mode with the following exception : Unhandled exception at 0x7855b9f0 in HelloOpenCV.exe: 0xC0000005: Access violation reading location 0x00000000.

It also switches to a "loadsave.cpp" file and it points to the line:

return (IplImage*)cv::imread_(filename, iscolor, cv::LOAD_IMAGE );

At the stack point : > highgui200.dll!cvLoadImage(const char * filename=0x00000000, int iscolor=1) Line 474 + 0x13 bytes C++

I also made a printscreen with the visual studio debugging window link text

I presume it has something to do with misplaced dependencies , problems with the dll-s. If anyone has an idea of what I could do to fix this please answer and I will be forever grateful.

Thanks, Alex

A: 

This isn't a direct answer, but I would try asking on the OpenCV Yahoo Group. It's quite active, and someone there is bound to know. Anytime I've ever asked a question there it's been replied to in a few hours.

Ben S
+3  A: 

Did you specify a valid file in your command-line parameters for argv[1], i.e. the filename of the image to be read?

Jacob
A: 

i think your command line argument is not proper

make sure for validity of command line arguments.

Ashish
+1  A: 

You need to verify that you have enough command line arguments. You should add something like this to the start of main():

if (argc < 2)
{
    fputs("Usage: prog filename\n", stderr);
    exit(1);
}
else if (argc > 2)
{
    fputs("ignoring extra parameters\n", stdout);
}

You could also modify your code to use each command line option in turn (if you do this, you would want to remove the warning about extra parameters in my above example):

int arg;
for (arg = 1; arg < argc; ++arg)
{
    IplImage* img = cvLoadImage( argv[arg] );

    ... the rest of your code ...
}

Finally, since it appears from your screen capture that you are starting your executable within the debugger, you will need to modify your properties in order to add the command line arguments. Within your project's properties, you want to choose the Debugging tab and then add the file to "Command Arguments".

R Samuel Klatchko
A: 

As other answers have indicated, the program is running with no command line arguments. You should do what R Samuel Klatchko said so your program works properly when run with out them.

But beyond that, to help you debug with proper arguments you can specify the command line arguments you want passed in to the program when the debugger is started in the VS project's Property Page on the "Debugging" 'tab'. It's the "Command Arguments" setting.

Michael Burr