用OpenCV读取视频的简单例子


用OpenCV读取视频的简单例子:

  1. #include "stdafx.h"   
  2. #include "cv.h"   
  3. #include <cxcore.h>   
  4. #include <highgui.h>   
  5.   
  6.   
  7. int main(int argc,char** argv)  
  8. {  
  9.     CvCapture* g_capture = cvCreateFileCapture("D:\\test2.avi");    // 视频地址   
  10.   
  11.   
  12.     IplImage* frame;  
  13.     string originVideoWinName = "Video_Origin";  
  14.   
  15.   
  16.     cvNamedWindow(originVideoWinName.c_str(),CV_WINDOW_AUTOSIZE);  
  17.     while (1)  
  18.     {  
  19.         frame = cvQueryFrame(g_capture);                                      // 捕获每帧   
  20.         if (!frame)  
  21.         {  
  22.             break;  
  23.         }  
  24.         cvShowImage(originVideoWinName.c_str(),frame);  
  25.         char c = cvWaitKey(33);  
  26.         if (c==27)  
  27.         {  
  28.             break;  
  29.         }  
  30.     }  
  31.     cvReleaseCapture(&g_capture);  
  32.     cvDestroyWindow(originVideoWinName.c_str());  
  33. }  

相关内容