Reputation: 133
Hi So I have written this code to capture a video from file
#include <stdio.h>
#include <cv.h>
#include "highgui.h"
#include <iostream>
//using namespace cv
int main(int argc, char** argv)
{
CvCapture* capture=0;
IplImage* frame=0;
capture = cvCaptureFromAVI(char const* filename); // read AVI video
if( !capture )
throw "Error when reading steam_avi";
cvNamedWindow( "w", 1);
for( ; ; )
{
frame = cvQueryFrame( capture );
if(!frame)
break;
cvShowImage("w", frame);
}
cvWaitKey(0); // key press to close window
cvDestroyWindow("w");
cvReleaseImage(&frame);
}
Everytime I run it, I get the following error:
CaptureVideo.cpp: In function ‘int main(int, char**)’:
CaptureVideo.cpp:13:28: error: expected primary-expression before ‘char’
Any help will be much appreciated.
Upvotes: 8
Views: 52681
Reputation: 12544
This is C++ question, so you should use the C++ interface.
The errors in your original code:
char const*
in cvCaptureFromAVI
.ShowImage
only works if it is followed by WaitKey.isOpened
instead.I have corrected your code and put it into the C++ interface, so it is a proper C++ code now. My rewrite does line-by-line the same as your program did.
//#include <stdio.h>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
//#include <iostream>
using namespace cv;
using std::string;
int main(int argc, char** argv)
{
string filename = "yourfile.avi";
VideoCapture capture(filename);
Mat frame;
if( !capture.isOpened() )
throw "Error when reading steam_avi";
namedWindow( "w", 1);
for( ; ; )
{
capture >> frame;
if(frame.empty())
break;
imshow("w", frame);
waitKey(20); // waits to display frame
}
waitKey(0); // key press to close window
// releases and window destroy are automatic in C++ interface
}
Upvotes: 18