2013-01-18 128 views
1

到目前为止,嘿嘿,我管理OpenCV播放video.avi,但我现在应该做什么来提取帧...?如何从AVI视频中提取帧

下面

是代码我至今写了有我的视频播放:

#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"); 
} 
+0

确定什么,我目前正在努力做的,就是播放视频提取帧和用于处理即模糊这些捕获的帧,门槛。本质上我想绘制包围盒,同时播放视频 – Tomazi

回答

0

frame要解压缩的帧。如果你想将其转换成一个CV ::太,你可以通过与IplImage结构创造一个垫子做到这一点:

Mat myImage(IplImage); 

There is a nice tutorial on it here

但是,你正在以旧的方式去做。 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; 
} 
+0

许多thx ....但我怎么说,捕获每个第5帧,并显示或保存...? – Tomazi

+0

只需使用imwrite:http://opencv.willowgarage.com/documentation/cpp/reading_and_writing_images_and_video.html#cv-imwrite。 imwrite(myImage,“filename.png”); – Jason

+0

因此,我可以在该框架上做一些处理,即模糊,然后阈值.... – Tomazi