[英]How to extract Frames from AVI video
Hey peeps so far i manage OpenCV to play a video.avi but what should i do now to extract frames...? 嘿,到目前为止,我管理OpenCV播放video.avi,但现在我应该怎么做才能提取帧...?
below is the code i written so far that got my video playing: 以下是到目前为止我编写的能够播放视频的代码:
#include<opencv\cv.h>
#include<opencv\highgui.h>
#include<opencv\ml.h>
#include<opencv\cxcore.h>
int main( int argc, char** argv ) {
cvNamedWindow( "DisplayVideo", CV_WINDOW_AUTOSIZE );
CvCapture* capture = cvCreateFileCapture( argv[1] );
IplImage* frame;
while(1) {
frame = cvQueryFrame( capture );
if( !frame ) break;
cvShowImage( "DisplayVideo", frame );
char c = cvWaitKey(33);
if( c == 27 ) break;
}
cvReleaseCapture( &capture );
cvDestroyWindow("DisplayVideo" );
}
frame
is the frame you are extracting. frame
是您要提取的帧。 If you want to convert that to a cv::Mat you can do that by creating a mat with that IplImage: 如果要将其转换为cv :: Mat,可以通过使用该IplImage创建一个mat来实现:
Mat myImage(IplImage);
There is a nice tutorial on it here . 这里有一个不错的教程 。
However, you are doing it the old way. 但是,您使用的是旧方法。 The newest version of OpenCV has the latest camera capture abilities, and you should do something like this:
最新版本的OpenCV具有最新的相机捕获功能,您应该执行以下操作:
#include "cv.h"
#include "highgui.h"
using namespace cv;
int main()
{
VideoCapture cap(0); // open the default camera
if(!cap.isOpened()) // check if we succeeded
return -1;
namedWindow("Output",1);
while(true)
{
Mat frame;
cap >> frame; // get a new frame from camera
//Do your processing here
...
//Show the image
imshow("Output", frame);
if(waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.