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. }

Opencv 简单视频播放器的更多相关文章

  1. 使用VideoView实现简单视频播放器

    转载请注明出处:http://blog.csdn.net/hejjunlin/article/details/39471397 VideoView内部封装好了Mediaplayer.Android框架 ...

  2. QT-简易视频播放器

    一直没找到理由去学一下QT,由于工作原因之后的工作内容会用到QT,于是这两天摸索了下:早上临时决定先做个视频播放器玩一下,于是先用qml发现不会用,无果,于是放弃了使用qml,等之后系统的看一下Jav ...

  3. 转:最简单的基于 DirectShow 的视频播放器

    50行代码实现的一个最简单的基于 DirectShow 的视频播放器 本文介绍一个最简单的基于 DirectShow 的视频播放器.该播放器对于初学者来说是十分有用的,它包含了使用 DirectSho ...

  4. 【转】100行代码实现最简单的基于FFMPEG+SDL的视频播放器

    FFMPEG工程浩大,可以参考的书籍又不是很多,因此很多刚学习FFMPEG的人常常感觉到无从下手.我刚接触FFMPEG的时候也感觉不知从何学起. 因此我把自己做项目过程中实现的一个非常简单的视频播放器 ...

  5. 最简单的基于FFMPEG+SDL的视频播放器 ver2 (採用SDL2.0)

    ===================================================== 最简单的基于FFmpeg的视频播放器系列文章列表: 100行代码实现最简单的基于FFMPEG ...

  6. 最简单的基于DirectShow的示例:视频播放器自定义版

    ===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...

  7. 最简单的基于DirectShow的示例:视频播放器图形界面版

    ===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...

  8. 最简单的基于DirectShow的示例:视频播放器

    ===================================================== 最简单的基于DirectShow的示例文章列表: 最简单的基于DirectShow的示例:视 ...

  9. 最简单的基于libVLC的例子:最简单的基于libVLC的视频播放器(图形界面版)

    ===================================================== 最简单的基于libVLC的例子文章列表: 最简单的基于libVLC的例子:最简单的基于lib ...

随机推荐

  1. [Debug] Debugger Statements

    For example you have the following code; function reverse(str) { let reversed = ""; for (l ...

  2. Finding Lane Lines on the Road

    Finding Lane Lines on the Road The goals / steps of this project are the following: Make a pipeline ...

  3. Mybatis的mapper接口在Spring中实例化过程

    在spring中使用mybatis时一般有下面的配置 <bean id="mapperScannerConfigurer" class="org.mybatis.s ...

  4. POJ2182 Lost Cows 树状数组

    题意:有编号1~n乱序排列的奶牛,给出了每一个奶牛前小于自己编号的奶牛数目 维护一个树状数组,下标是编号,值为$0/1$标识是否存在,很显然最后一个牛的编号是知道的,我们在树状数组上二分出前缀和为小于 ...

  5. conda 激活环境失败解决办法

    https://stackoverflow.com/questions/41746137/conda-environment-is-discoverable-but-not-activateable- ...

  6. Python回归分析五部曲(三)—一元非线性回归

    (一)基础铺垫 一元非线性回归分析(Univariate Nonlinear Regression) 在回归分析中,只包括一个自变量和一个因变量,且二者的关系可用一条曲线近似表示,则称为一元非线性回归 ...

  7. codeforces#1165 F2. Microtransactions (hard version) (二分+贪心)

    题目链接: https://codeforces.com/contest/1165/problem/F2 题意: 需要买$n$种物品,每种物品$k_i$个,每个物品需要两个硬币 每天获得一个硬币 有$ ...

  8. Codeforces 808 E. Selling Souvenirs(三分)

    E. Selling Souvenirs 题意: n件物品,有重量和价值,重量只有三种1,2,3.问取不超过m重量的物品的价值总和最大是多少.(n<=1e5,w<=3e5) 思路: n*w ...

  9. 在Linux下使用rm -rf /*后会怎样?

    每个工作过的码农,也许不知道分布式,也许不知道高并发,但想必都知道这句鼎鼎大名的代码.本人对此也是比较好奇的,不妨用虚拟机试试看 首先是普通角色: 普通角色把拥有权限的文件全都删掉了后,其他文件的提示 ...

  10. TensorFlow错误ValueError: No gradients provided for any variable

    使用TensorFlow训练神经网络的时候,出现以下报错信息: Traceback (most recent call last):   File "gan.py", line 1 ...