2013-01-18 220 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