【opencv2】对视频的操作

对于VideoCapture,其有如下几个操作函数:

open(conststring&filename)//打开视频文件

release()//关闭视频文件或者摄像头

get(intpropId)//返回视频的属性

CV_CAP_PROP_POS_MSEC以毫秒或者时间戳的形式当前视频文件的位置

CV_CAP_PROP_FRAME_WIDTH视频帧图片的宽度

CV_CAP_PROP_FRAME_HEIGHT视频帧图片的高度

CV_CAP_PROP_FPS帧率

CV_CAP_PROP_FOURCC视频的四字符代码

CV_CAP_PROP_FRAME_COUNT视频的总帧数

CV_CAP_PROP_FORMAT视频的图片格式

CV_CAP_PROP_MODE后端特定值指示当前捕获模式

下面几个属性只在摄像模式下有效:

CV_CAP_PROP_BRIGHTNESS图像的亮度

CV_CAP_PROP_CONTRAST图像对比度

CV_CAP_PROP_SATURATION图像的饱和度

CV_CAP_PROP_HUE图像的色度

CV_CAP_PROP_EXPOSURE图像的曝光

对于VideoWriter,,其有如下几个操作函数:

open(conststring&filename,intfourcc,doublefps,SizeframeSize,color=true)

以上几个参数在上文中均已经介绍过了。

isOpened()//与前面的是一个意思

write(constMat&image)//opencv中也同样重载了这个函数,即用操作符<<

#include "opencv2/objdetect/objdetect.hpp"#include "opencv2/highgui/highgui.hpp"#include "opencv2/imgproc/imgproc.hpp"#include <opencv2/opencv.hpp>#include <iostream>#include <stdio.h>using namespace std;using namespace cv;int main(int argc, const char** argv){Mat frame;VideoCapture video;VideoWriter newVideo;double fourcc, fps, width, height;video.open("25.avi"); //打开视频fourcc = video.get(CV_CAP_PROP_FOURCC); fps = video.get(CV_CAP_PROP_FPS);width = video.get(CV_CAP_PROP_FRAME_WIDTH);height = video.get(CV_CAP_PROP_FRAME_HEIGHT); //得到视频的一些参数//新建一个新的视频markVideo.open("markVideo10.avi", fourcc, fps);if (video.isOpened() && markVideo.isOpened() ){while(true){video >> frame; //读取视频的每一个帧resize(frame, frame, Size(320, 280)); //将视频的每一帧都缩小if (!frame.empty()){markVideo << frame;//将缩小后的每一个帧都写进新的视频}else{printf(" –(!) No captured frame — Break!"); break;}if ((char)waitKey(1) == 'c') {video.release(); markVideo.release();break;}}}return 0;}

轻轻的风,吹开你紧锁的眉头,

【opencv2】对视频的操作

相关文章:

你感兴趣的文章:

标签云: