opencv 从摄像头中读取视频并保存(c++版)
原文:http://blog.csdn.net/zhongshijunacm/article/details/68947890
OpenCV中的视频操作函数如下表所列:
VideoCapture
VideoCapture::VideoCapture
VideoCapture::open
VideoCapture::isOpened
VideoCapture::release
VideoCapture::grab
VideoCapture::retrieve
VideoCapture::read
VideoCapture::get
VideoCapture::set
VideoWriter
VideoWriter::VideoWriter
ReleaseVideoWriter
VideoWriter::open
VideoWriter::isOpened
VideoWriter::write
感兴趣的可以自己查看官方文档。
这里主要介绍几个本文中使用到的函数。
C++: VideoWriter::VideoWriter()
C++: VideoWriter::VideoWriter(const string& filename, int fourcc, double fps, Size frameSize, bool isColor=true)Parameters:
filename – Name of the output video file.
fourcc – 4-character code of codec used to compress the frames. For example, CV_FOURCC(‘P’,’I’,’M’,’1’) is a MPEG-1 codec, CV_FOURCC(‘M’,’J’,’P’,’G’) is a motion-jpeg codec etc. List of codes can be obtained at Video Codecs by FOURCC page. (如果,这里输入-1.在windows下会弹出一个对话框让你选择视频解压格式。)
fps – Framerate of the created video stream.
frameSize – Size of the video frames.
isColor – If it is not zero, the encoder will expect and encode color frames, otherwise it will work with grayscale frames (the flag is currently supported on Windows only).
//视频保存位置
string outputVideoPath = "..\\images\\test.avi";
//打开摄像头
VideoCapture capture0(0);
VideoWriter outputVideo;
//获取当前摄像头的视频信息
cv::Size S = cv::Size((int)capture0.get(CV_CAP_PROP_FRAME_WIDTH),
(int)capture0.get(CV_CAP_PROP_FRAME_HEIGHT));
//打开视频路劲,设置基本信息 open函数中你参数跟上面给出的VideoWriter函数是一样的
outputVideo.open(outputVideoPath, -1, 30.0, S, true);
//CV_FOURCC('P','I','M','1')
if (!outputVideo.isOpened()) {
cout << "fail to open!" << endl;
return -1;
}
cv::Mat frameImage;
int count = 0;
while(true) {
//读取当前帧
capture0 >> frameImage;
if (frameImage.empty()) break;
++count;
//输出当前帧
cv::imshow("output", frameImage);
//保存当前帧
outputVideo << frameImage;
if (char(waitKey(1)) == 'q') break;
}
std::cout << "TotalFrame: " << count << std::endl;
最新文章
- APM程序分析-AC_WPNav.cpp
- ACM:Pseudoforest-并查集-最大生成树-解题报
- 联机事务处理OLTP(on-line transaction processing)和联机分析处理OLAP(On-Line Analytical Processing)
- Synergy
- Web工程与RMI工程进行联调
- 运用bat进行数据库备份
- hdu 2258 优先队列
- hdu1052(田忌赛马 贪心)
- 使用tornado的gen.coroutine进行异步编程
- jquery-2.0.3.js和jquery-2.0.3.min.js的区别
- (转载)shell中用date命令获取昨天、明天或者多天前的日期
- [转载]ecshop 实现订单导出功能 指定订单导出 EXCEL 数据文件
- ubuntu用不了root用户:~$ su - root Password: su: Authentication failure怎么办?
- hive Beeline plus HiveServer2简单使用
- 你可能不知道的5种 CSS 和 JS 的交互方式
- [第二届构建之法论坛] 预培训文档(C++版)
- iOS开发 关于启动页和停留时间的设置
- linux ab压力测试工具及ab命令详解
- CSUOJ 1979 古怪的行列式
- mysql数据库以加索引方式提高性能
热门文章
- 安装Termux的手机上运行Python
- dynamics crm 365 附件上传图片并且显示。
- odoo 的一些orm 操作
- python2.x提示这个错误:UnicodeDecodeError: &#39;ascii&#39; codec can&#39;t decode byte 0xe8 in position
- SQL chema的新增和修改
- python3.5+ asyncio await异步详解
- mysql 03
- Python中socket经ssl加密后server开多线程
- How to remove constantly launching services on Mac OS X
- Jenkins~powershell+cmd发布nuget包包