Opencv 简单视频播放器
2024-09-05 07:53:48
- // C++ header and namespace
- #include <iostream>
- #include <string>
- #include <cstdlib>
- using namespace std;
- // Opencv header and namespace
- #include <opencv2/core/core.hpp>
- #include <opencv2/highgui/highgui.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include <opencv2/video/video.hpp>
- using namespace cv;
- bool JumpToFrame(false);
- int main(int argc, char* argv[])
- {
- //!< Check out Input video
- if (argc != 2)
- {
- cerr << "Usage: VideoPlayer.exe VideoFilename." << endl;
- exit(1);
- }
- //!< Check out Open Video
- VideoCapture capture(argv[1]);
- if (!capture.isOpened())
- {
- return 1;
- }
- #pragma region InfoOfVideo
- long NumberOfFrame = static_cast<long>(capture.get(CV_CAP_PROP_FRAME_COUNT));
- double HeightOfFrame = capture.get(CV_CAP_PROP_FRAME_HEIGHT);
- double WidthOfFrame = capture.get(CV_CAP_PROP_FRAME_WIDTH);
- double FpsOfVideo = capture.get(CV_CAP_PROP_FPS);
- cout << "The name of the input video is " << argv[1] << "." << endl;
- cout << "NumberOfFrame : " << NumberOfFrame << endl;
- cout << "HeightOfFrame : " << HeightOfFrame << endl;
- cout << "WidthOfFrame : " << WidthOfFrame << endl;
- cout << "FpsOfVieo : " << FpsOfVideo << endl;
- #pragma endregion
- // !< JumpToFrame function
- while (JumpToFrame)
- {
- double Position = 0.0;
- cout << "Please input the number of frame which you want jump to!" << endl;
- cin >> Position;
- capture.set(CV_CAP_PROP_POS_FRAMES, Position);
- }
- // !< Delay between each frame in ms corresponds to video frame rate(fps)
- Mat frame;
- bool stop(false);
- int delay = 1000 / FpsOfVideo;
- namedWindow("Extracted Frame");
- while (!stop)
- {
- //read next frame if any
- if (!capture.read(frame))
- {
- break;
- }
- imshow("Extracted Frame", frame);
- //introduce a delay or press key to stop
- if (waitKey(delay) >= 0)
- {
- stop = true;
- }
- }
- // !< Close the video file.
- // Not required since called by destructor
- capture.release();
- return 0;
- }
最新文章
- 新知识:Java 利用itext填写pdf模板并导出(昨天奋战到深夜四点,知道今天两点终于弄懂)
- winform打开唯一窗体、构造函数传值
- Android 监听键盘的弹起与收缩
- Wind River Linux 6 Security Profile
- mongoDB7--游标cursor
- MAC的VIMRC
- java程序员--小心你代码中的内存泄漏
- BZOJ 3876: [Ahoi2014]支线剧情 [上下界费用流]
- Exception in thread ";main"; expected &#39;<;document start>;&#39;, but found BlockMappingStart in &#39;reader&#39;, line 23, column 2: nimbus.host: ";master";
- Java开发笔记(八十七)随机访问文件的读写
- Web前端 web的学习之路
- 基于 docker 的yapi(快速部署)
- python中列表中元素的增删改查
- spring框架排错
- Socket:读写处理及连接断开的检测
- [LeetCode&;Python] Problem 463. Island Perimeter
- Windows Server 2012 R2部署--安装桌面体验
- MAC之tar解压与压缩打包命令
- Python中abs()和math.fabs()区别
- URL参数获取/转码
热门文章
- Codeforces Round #456 (Div. 2) B题
- Luogu P1450 [HAOI2008]硬币购物 背包+容斥原理
- [Luogu] 旅行
- 【luoguP1196】 [NOI2002]银河英雄传说--边带权并查集 ,
- windbg双机调试配置[转]
- 阿里云Ubuntu安装LNMP环境之Mysql
- 初次接触python,怎么样系统的自学呢?
- Mybatis源码学习之parsing包(解析器)(二)
- SpringMVC 请求映射注解
- 获取当前页面的webview ID