i have a little problem according "displaying a video with opencv". The code is written in c++ with visual studio 2008.
here is the code:
int main( int argc, char** argv )
{
cvNamedWindow( "xample2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( "Micro-dance_2_.avi" );
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "xample2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "xample2" );
}
when debugging, the programm launches and i can see the command window and a grey window (wher the video should be displayed i suppose) for a few milliseconds. Then both windows close.
the output from debug window in visual shows the following:
.. . (a lot of loaded and unloaded dlls) . . .
The program '[3684] 2aufg4).exe: Native' has exited with code 0 (0x0).
i dont know what i am doing wrong...
i would appreciate your help a lot!
as allways thank you guys
You need to check the return of cvCreateFileCapture()
and make sure it loaded the file successfully:
#include <cv.h>
#include <highgui.h>
int main(int argc, char** argv)
{
cvNamedWindow("xample2", CV_WINDOW_AUTOSIZE);
CvCapture* capture = cvCreateFileCapture( "Micro-dance_2_.avi" );
if (!capture)
{
std::cout << "!!! cvCreateFileCapture didn't found the file !!!\n";
return -1;
}
IplImage* frame;
while (1)
{
frame = cvQueryFrame(capture);
if(!frame)
break;
cvShowImage("xample2", frame);
char c = cvWaitKey(33);
if (c == 27)
break;
}
cvReleaseCapture(&capture);
cvDestroyWindow("xample2");
}
Try this
int main( int argc, char** argv )
{
cvNamedWindow( "xample2", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( "Micro-dance_2_.avi" );
IplImage* frame;
if(!cvQueryFrame( capture )){
std::cout << "Could not open file\n";
return -1;
}
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "xample2", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow( "xample2" );
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.