歡迎來到Linux教程網
Linux教程網
Linux教程網
Linux教程網
Linux教程網 >> Linux編程 >> Linux編程 >> 用OpenCV讀取視頻的簡單例子

用OpenCV讀取視頻的簡單例子

日期:2017/3/1 10:12:51   编辑:Linux編程

用OpenCV讀取視頻的簡單例子:

  1. #include "stdafx.h"
  2. #include "cv.h"
  3. #include <cxcore.h>
  4. #include <highgui.h>
  5. int main(int argc,char** argv)
  6. {
  7. CvCapture* g_capture = cvCreateFileCapture("D:\\test2.avi"); // 視頻地址
  8. IplImage* frame;
  9. string originVideoWinName = "Video_Origin";
  10. cvNamedWindow(originVideoWinName.c_str(),CV_WINDOW_AUTOSIZE);
  11. while (1)
  12. {
  13. frame = cvQueryFrame(g_capture); // 捕獲每幀
  14. if (!frame)
  15. {
  16. break;
  17. }
  18. cvShowImage(originVideoWinName.c_str(),frame);
  19. char c = cvWaitKey(33);
  20. if (c==27)
  21. {
  22. break;
  23. }
  24. }
  25. cvReleaseCapture(&g_capture);
  26. cvDestroyWindow(originVideoWinName.c_str());
  27. }
Copyright © Linux教程網 All Rights Reserved