原文: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++版)的更多相关文章

  1. ios从相册:摄像头中获取视频

    ios从相册/摄像头中获取视频 如何从相册中获取视频 使用的是一个和获取照片相同的类UIImagePickerController //相册中获取视频 - (IBAction)clickViedoOF ...

  2. 基于opencv在摄像头ubuntu根据视频获取

     基于opencv在摄像头ubuntu根据视频获取 1  工具 原料 平台 :UBUNTU12.04 安装库  Opencv-2.3 2  安装编译执行步骤 安装编译opencv-2.3  參考h ...

  3. 也谈matlab中读取视频的一个重要函数mmreader

    也谈matlab中读取视频的一个重要函数mmreader 在matlab中输入help mmreader来查阅一下该函数,有如下信息: MMREADER Create a multimedia rea ...

  4. opencv3读取视频并保存为图片

    #include <iostream> #include <vector> #include <opencv2/opencv.hpp> using namespac ...

  5. Opencv从文件中播放视频

    1.VideoCapture()括号中写视频文件的名字,在播放每一帧的时候,使用cv2.waitKey()设置适当的持续时间,太低会播放的很快,太高会很慢,通常情况下25毫秒就行了. 2.获取相机/视 ...

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

  7. Linux下安装opencv with-ffmpeg解决无法读取视频的问题

    1. 编译安装ffmpeg 下载源码,执行 ./configure --disable-yasm --enbale-shared --prefix=/usr/local/ffmpeg 即可. 2. 下 ...

  8. OpenCV读写摄像头并写入视频

    #include <opencv2/opencv.hpp>using namespace cv;#include <iostream>using namespace std; ...

  9. opencv学习之路(2)、读取视频,读取摄像头

    一.介绍 视频读取本质上就是读取图像,因为视频是由一帧一帧图像组成的.1秒24帧基本就能流畅的读取视频了. ①读取视频有两种方法: A. VideoCapture cap; cap.open(“1.a ...

随机推荐

  1. 针对ACM输出格式的一个小技巧(对格式错误说不!)

    printf("%d%c",bmax," \n"[i==n]); 上文中bmax为题目中需要输出的整形变量,可以脑补很多ans,max之类的,重点在于%c和后面 ...

  2. 简易APB4 slave实践

    一个简易的(不完整的)APB4 slave的可以没有PREADY和PSLVERR,这两个信号都被赋予常数,以及没有PPROT. 两种不同类型的寄存器: 图: 普通寄存器电路图 图: 带读写控制寄存器电 ...

  3. 4.nginx高可用

    1.大体结构 一.使用场景介绍: nginx做负载均衡,来达到分发请求的目的,但是不能很好的避免单点故障,假如nginx服务器挂点了,那么所有的服务也会跟着瘫痪 .keepalived+nginx,就 ...

  4. LeetCode 100.相同的树(C++)

    给定两个二叉树,编写一个函数来检验它们是否相同. 如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的. 示例 1: 输入: 1 1 / \ / \ 2 3 2 3 [1,2,3], [1 ...

  5. Http请求响应模型

    主要用到以下四个部分: Client   API   DB   API 场景:登录 1.Client发起请求到API接口层 1.1用户在客户端输入登录信息,点击登录,发送请求 2.API接受用户发起的 ...

  6. 转 Hibernate中cascade和inverse的作用

    Inverse和cascade是Hibernate映射中最难掌握的两个属性.两者都在对象的关联操作中发挥作用.1.明确inverse和cascade的作用inverse 决定是否把对对象中集合的改动反 ...

  7. github 相关操作知识

    新设备上使用github 1.要在本地创建一个ssh key ssh-keygen -t rsa -C "email address" 2.界面提示进入.ssh文件夹下,找到id_ ...

  8. win10中xshell的ssh链接virtualBox中的centos7

    win10下virtualbox中centos7.3与主机通过xshell的ssh建立连接的方法 2017-02-19 01:29  版权声明:本文为博主原创文章,未经博主允许不得转载.     最近 ...

  9. Delphi下OpenGL2d绘图(02)-画点

    一.前言 图形的绘制可以使用glBegin().glEnd()之间完成,绘制的框架代码可以使用 Delphi下OpenGL2d绘图(01)-初始化 中的代码.修改的部份为 Draw 函数的内容. 二. ...

  10. ASP.NET 页生命周期概述1

    ASP.NET 页运行时,此页将经历一个生命周期,在生命周期中将执行一系列处理步骤.这些步骤包括初始化.实例化控件.还原和维护状态.运行事件处理程序代码以及进行 呈现.了解页生命周期非常重要,因为这样 ...