#include "opnecv2/opencv.hpp"
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
int c=0;
VideoCapture cap(c);//调用摄像头,如果有多个摄像头,可以调整c(0,1,2,...)来选择到你想要的摄像头,
if (!cap.isOpened())
{
return -1;
}
bool stop = false;
int a = 0;
//设置视频编写器
VideoWriter write;
string outVideo = "Show_Example.avi";
int fps = 30;//帧率double fps=cap.get(CV_CAP_PROP_FPS);但是我调用该函数返回的是0
int height = static_cast<int>(cap.get(CV_CAP_PROP_FRAME_HEIGHT));//读取视频的高度
int width = static_cast<int>(cap.get(CV_CAP_PROP_FRAME_WIDTH));//读取视频的宽度
//目前opencv对保存视频的支持格式不是很多,我尝试了很多种,后面有格式和编码方式的补充。我这里使用的是.avi格式,编码方式选择XVID
write.open(outVideo, CV_FOURCC('X','V','I','D'), fps, Size(width, height), true);
while (!stop)
{
Mat frame;
cap >> frame;
blur(frame,frame,Size(3,3),Point(-1,-1));
imshow("当前视频", frame);
write.write(frame);
if (waitKey(30) >= 0)
stop = true;
}
return 1;
}