[英]reading video from file opencv
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:在函数'int main(int,char **)'中:
CaptureVideo.cpp:13:28: error: expected primary-expression before 'char'
CaptureVideo.cpp:13:28:错误:在'char'之前预期的primary-expression
Any help will be much appreciated. 任何帮助都感激不尽。
This is C++ question, so you should use the C++ interface. 这是C ++问题,所以你应该使用C ++接口。
The errors in your original code: 原始代码中的错误:
char const*
in cvCaptureFromAVI
. cvCaptureFromAVI
删除char const*
。 ShowImage
only works if it is followed by WaitKey. ShowImage
只有在ShowImage
才有效。 isOpened
instead. isOpened
。 I have corrected your code and put it into the C++ interface, so it is a proper C++ code now. 我已经更正了你的代码并将其放入C ++接口,所以它现在是一个合适的C ++代码。 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
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.