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;
opencv 从摄像头中读取视频并保存(c++版)的更多相关文章
- ios从相册:摄像头中获取视频
ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...
- 基于opencv在摄像头ubuntu根据视频获取
基于opencv在摄像头ubuntu根据视频获取 1 工具 原料 平台 :UBUNTU12.04 安装库 Opencv-2.3 2 安装编译执行步骤 安装编译opencv-2.3 參考h ...
- 也谈matlab中读取视频的一个重要函数mmreader
也谈matlab中读取视频的一个重要函数mmreader 在matlab中输入help mmreader来查阅一下该函数,有如下信息: MMREADER Create a multimedia rea ...
- opencv3读取视频并保存为图片
#include <iostream> #include <vector> #include <opencv2/opencv.hpp> using namespac ...
- Opencv从文件中播放视频
1.VideoCapture()括号中写视频文件的名字,在播放每一帧的时候,使用cv2.waitKey()设置适当的持续时间,太低会播放的很快,太高会很慢,通常情况下25毫秒就行了. 2.获取相机/视 ...
- How to read video frames in hadoop?如何在Hadoop中读取视频帧?
To process specialized file formats (such as video) in Hadoop, you'd have to write a custom InputFor ...
- Linux下安装opencv with-ffmpeg解决无法读取视频的问题
1. 编译安装ffmpeg 下载源码,执行 ./configure --disable-yasm --enbale-shared --prefix=/usr/local/ffmpeg 即可. 2. 下 ...
- OpenCV读写摄像头并写入视频
#include <opencv2/opencv.hpp>using namespace cv;#include <iostream>using namespace std; ...
- opencv学习之路(2)、读取视频,读取摄像头
一.介绍 视频读取本质上就是读取图像,因为视频是由一帧一帧图像组成的.1秒24帧基本就能流畅的读取视频了. ①读取视频有两种方法: A. VideoCapture cap; cap.open(“1.a ...
随机推荐
- 【杂记】linux下各种软件安装方法(持续记录)
1.安装jdk: 网上一堆说先从windows下压缩包,然后通过共享文件夹copy到linux系统里,然后解压安装,emmmmm 首先进入usr文件夹,新建java文件夹: mkdir java 直接 ...
- Flutter Navigator operation requested with a context that does not include a Navigat
如下直接在 MaterialApp 中使用 Navigator 是会报 Navigator operation requested with a context that does not inclu ...
- awk练习
首先,了解awk的运行格式 awk '条件类型1{动作1} 条件类型2{动作2} ...' filename 1. [root@server3 mnt]# cat passwd root x 0 0 ...
- thymeleaf常用语法
常用标签语法:①th:text<span th:text="${name}">1</span>注释:如果${name}有值则将替换掉1的值,若无则为1 ②t ...
- ViewData与ViewBag的区别
本文导读:在asp.net mvc程序设计中,传递数据常常会用到viewdata.viewbag.ViewData是一个字典集合,通过key值读取对应的value:ViewBag是动态类型,作用和Vi ...
- db2 tsm backup fails with rc–50(1)
2015-01-05-19.21.54.477532+000 E8484227A347 LEVEL: Error PID : 10027058 TID : ...
- 微信公众号中的支付宝支付与微信支付 && 支付宝支付问题(微信bug)
一般,在微信公众号中的商城都是需要支持微信支付和支付宝支付的,当然,较大的公司对于鹅厂和阿里的站队就不说了,所以这里简单记录一下支付宝支付和微信支付的主要流程.说是简单介绍,这是因为确实不难,因为前端 ...
- how to be an efficient man
"This Monday I was invited to do a presentation on this Friday, and today is Friday. I am going ...
- PHP如何判断对象为空的方法分享
1.网上很多方法分享说用empty()方法判断对象是否为空.empty()的方法介绍:格式:bool empty ( mixed var )功能:检查一个变量是否为空返回值:若变量不存在则返回 TRU ...
- 【Css】Layout布局(一)
看下图: css框模型(Box Model),也有叫做盒模型的.规定了元素框处理元素内容.内边距.边框 和 外边距 的方式. element元素,也是内容的主体: padding内边距,也右称为填充的 ...