嗨所以我写了这段代码来捕获文件中的视频
#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);
}
每次我运行它时,都会收到以下错误:
CaptureVideo.cpp:在函数'int main(int,char **)'中:
CaptureVideo.cpp:13:28:错误:在'char'之前预期的primary-expression
非常感谢任何帮助。
答案 0 :(得分:12)
这是C ++问题,所以你应该使用C ++接口。
原始代码中的错误:
char const*
中的cvCaptureFromAVI
。ShowImage
仅在WaitKey后面有效。isOpened
。我已经更正了您的代码并将其放入C ++接口,因此它现在是一个合适的C ++代码。我的重写与你的程序一样逐行。
//#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
}