对视频的操作主要用的是VideoCapture类。
读入视频的方法一般有两种:
1.VideoCapture capture;
capture.open("1.avi");
2.VideoCapture capture ("1.avi");
这两种写法类似于int a;a=1;和int a=1;
视频读入到VideoCapture类对象以后,再用一个循环把每一帧显示出来:
while(1)
{
Mat frame;//定义一个Mat变量,用于存储每一帧图像
capture>>frame;//读取当前帧
imshow("读取视频",frame);//显示当前帧
waitKey(30);//延时30ms
}
一般会在imshow前面加一段:
while(1)
{
Mat frame;//定义一个Mat变量,用于存储每一帧图像
capture>>frame;//读取当前帧
if(frame.empty())
{
break;//这一段表示如果视频播放完成,退出循环
}
imshow("读取视频",frame);//显示当前帧
waitKey(30);//延时30ms
}