OpenCV——视频操作基础

读入视频:

1 VideoCapture 类
2 //方法一
3 VideoCapture capture;
4 capture.open("test.avi");
5 
6 //方法二
7 VideoCapture capture("test.avi");
 1 #include <opencv2/opencv.hpp>
 2 #include <iostream>
 3 //#include <opencv2/highgui/highgui.hpp>
 4 //#include <imgproc/imgproc.hpp>
 5 using namespace cv;
 6 
 7 int main(int argc, char** argv)
 8 {
 9     //读入视频
10     VideoCapture capture1("test.mp4");
11     //读入摄像头
12     VideoCapture capture2(0);
13 
14     while (1)
15     {
16         Mat frame1, frame2;//定义一个Mat类变量,用于存储每一帧的图像
17 
18         //capture.read(frame);两种方法读取当前帧
19         capture1 >> frame1;//两种方法读取当前帧
20 
21         imshow("读取视频",frame1);
22 
23         capture2 >> frame2;
24         imshow("读取摄像头", frame2);
25         waitKey(30);//延时30ms
26     }
27     return 0;
28 }

猜你喜欢

转载自www.cnblogs.com/long5683/p/9633416.html