Hi, I am learning c++. I believe I have an easy to answer question.
I have an opencv program which simply takes a video and shows it. It takes the video as an argument with argv[1]. It compiles without an error. I can successfully run the program in the command line:
C: prog.exe test.avi // it runs!
prog.exe and test.avi are in the same directory.
But when I click on the prog.exe Windows 7 OS tells that it stopped working and prog.exe stops. I believe that it has to do with taking argument as an input. What should I do if I want to run the prog.exe by clicking in order for it to take test.avi as an argument?
I am using code::blocks as an editor btw.
I don't know whether you need it but here is the code:
#include "highgui.h"
int main( int argc, char** argv )
{
cvNamedWindow( "Example2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( argv[1] );
/*
Takes a video as an argument and initializes it to the beginning of the video.
*/
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
/*
Takes frames from the video. And iterates the CvCapture structure one frame forward.
cvLoadImage allocates some memory, but this function uses memory already allocated by cvCreateFileCapture
*/
if( !frame ) break;
cvShowImage( "Example2", frame );
/*
*/
char c = cvWaitKey(33);
/*
Waits for a keystroke for 33 ms, if a key is pressed during that time, the ASCII value of the key is passed to 'c'
*/
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
/*
Free all the memory associated with the CvCapture data structure.
*/
cvDestroyWindow( "Example2" );
}
If you're gonna use an argument, you have to first check if it was actually passed (using argc).
You can open a program with a file as a parameter by dragging the file onto your program icon.