1. // C++ header and namespace
  2. #include <iostream>
  3. #include <string>
  4. #include <cstdlib>
  5. using namespace std;
  6. // Opencv header and namespace
  7. #include <opencv2/core/core.hpp>
  8. #include <opencv2/highgui/highgui.hpp>
  9. #include <opencv2/imgproc/imgproc.hpp>
  10. #include <opencv2/video/video.hpp>
  11. using namespace cv;
  12. bool JumpToFrame(false);
  13. int main(int argc, char* argv[])
  14. {
  15. //!< Check out Input video
  16. if (argc != 2)
  17. {
  18. cerr << "Usage: VideoPlayer.exe VideoFilename." << endl;
  19. exit(1);
  20. }
  21. //!< Check out Open Video
  22. VideoCapture capture(argv[1]);
  23. if (!capture.isOpened())
  24. {
  25. return 1;
  26. }
  27. #pragma region InfoOfVideo
  28. long    NumberOfFrame = static_cast<long>(capture.get(CV_CAP_PROP_FRAME_COUNT));
  29. double  HeightOfFrame = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
  30. double  WidthOfFrame  = capture.get(CV_CAP_PROP_FRAME_WIDTH);
  31. double  FpsOfVideo    = capture.get(CV_CAP_PROP_FPS);
  32. cout << "The name of the input video is " << argv[1] << "." << endl;
  33. cout << "NumberOfFrame : " << NumberOfFrame << endl;
  34. cout << "HeightOfFrame : " << HeightOfFrame << endl;
  35. cout << "WidthOfFrame  : " << WidthOfFrame << endl;
  36. cout << "FpsOfVieo     : " << FpsOfVideo << endl;
  37. #pragma endregion
  38. // !< JumpToFrame function
  39. while (JumpToFrame)
  40. {
  41. double Position = 0.0;
  42. cout << "Please input the number of frame which you want jump to!" << endl;
  43. cin >> Position;
  44. capture.set(CV_CAP_PROP_POS_FRAMES, Position);
  45. }
  46. // !< Delay between each frame in ms corresponds to video frame rate(fps)
  47. Mat frame;
  48. bool stop(false);
  49. int delay = 1000 / FpsOfVideo;
  50. namedWindow("Extracted Frame");
  51. while (!stop)
  52. {
  53. //read next frame if any
  54. if (!capture.read(frame))
  55. {
  56. break;
  57. }
  58. imshow("Extracted Frame", frame);
  59. //introduce a delay or press key to stop
  60. if (waitKey(delay) >= 0)
  61. {
  62. stop = true;
  63. }
  64. }
  65. // !< Close the video file.
  66. // Not required since called by destructor
  67. capture.release();
  68. return 0;
  69. }

最新文章

  1. 新知识:Java 利用itext填写pdf模板并导出(昨天奋战到深夜四点,知道今天两点终于弄懂)
  2. winform打开唯一窗体、构造函数传值
  3. Android 监听键盘的弹起与收缩
  4. Wind River Linux 6 Security Profile
  5. mongoDB7--游标cursor
  6. MAC的VIMRC
  7. java程序员--小心你代码中的内存泄漏
  8. BZOJ 3876: [Ahoi2014]支线剧情 [上下界费用流]
  9. Exception in thread &quot;main&quot; expected &#39;&lt;document start&gt;&#39;, but found BlockMappingStart in &#39;reader&#39;, line 23, column 2: nimbus.host: &quot;master&quot;
  10. Java开发笔记(八十七)随机访问文件的读写
  11. Web前端 web的学习之路
  12. 基于 docker 的yapi(快速部署)
  13. python中列表中元素的增删改查
  14. spring框架排错
  15. Socket:读写处理及连接断开的检测
  16. [LeetCode&amp;Python] Problem 463. Island Perimeter
  17. Windows Server 2012 R2部署--安装桌面体验
  18. MAC之tar解压与压缩打包命令
  19. Python中abs()和math.fabs()区别
  20. URL参数获取/转码

热门文章

  1. Codeforces Round #456 (Div. 2) B题
  2. Luogu P1450 [HAOI2008]硬币购物 背包+容斥原理
  3. [Luogu] 旅行
  4. 【luoguP1196】 [NOI2002]银河英雄传说--边带权并查集 ,
  5. windbg双机调试配置[转]
  6. 阿里云Ubuntu安装LNMP环境之Mysql
  7. 初次接触python,怎么样系统的自学呢?
  8. Mybatis源码学习之parsing包(解析器)(二)
  9. SpringMVC 请求映射注解
  10. 获取当前页面的webview ID