VideoCapture 读入视频的方法有两种:
①先实例化再初始化:
VideoCapture capture;
capture.open("C:/Users/齐明洋/Desktop/1.mp4")
②实例化的同时进行初始化
VideoCapture capture("C:/Users/齐明洋/Desktop/1.mp4");
这两种写法的区别就如定义一个 int 类型的变量一样;
“int a;a=1;”
“int a=1;”
视频读入到 VideoCapture 类对象之后,紧接着用一个循环将每一帧显示出来。
代码:
#include<opencv.hpp> using namespace cv; int main() { VideoCapture capture("C:/Users/齐明洋/Desktop/1.mp4");
while (1) { Mat frame; capture >> frame;
imshow("读取视频", frame);
waitKey(1); } }
效果: