视频流读写的实现类:VideoCapture
1、read
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture; //创建对象
capture.open("demo.mp4"); //打开文件
if (!capture.isOpened()) //如果文件不存在则返回 -1
{
printf("cloud not load video data \n");
return -1;
}
Mat frame;
namedWindow("video",WINDOW_AUTOSIZE);
while (capture.read(frame)) //将视频读入对象读到的图片传入图片对象中
{
imshow("video",frame); //然后每张图片经过XX毫秒,播放出来
char c = waitKey(50);
if (c == 27) //Esc值为27 以便暂停
{
break;
}
}
waitKey(0);
return 0;
}
2、write
#include<opencv2/opencv.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main(int argc, char**argv)
{
VideoCapture capture(0);
if (!capture.isOpened()) //如果文件不存在则返