C++OpenCV读取视频数据和摄像头数据

废话不多说直接上代码了,因为比较简单:

1.读取视频数据

#include<iostream>
#include<opencv2/highgui.hpp>
#include<opencv2/imgcodecs.hpp>
#include<opencv2/opencv.hpp>

using namespace cv;
using namespace std;

/*
	读取视频数据
*/
void main()
{
	string path = "F:/testImage/Megamind.avi";
	VideoCapture cap(path);
	Mat img;
	while (true)
	{
		cap.read(img);
		imshow("Image", img);
		waitKey(20);  
	}
}

其中waikey()中设置的越小刷新的就越快相当于加速播放;越大越慢

2.读取摄像头数据

#include<iostream>
#include<opencv2/highgui.hpp>
#include<opencv2/imgcodecs.hpp>
#include<opencv2/opencv.hpp>

using namespace cv;
using namespace std;


/*
	读取摄像头数据
*/
void main()
{
	VideoCapture cap(0);
	Mat img;
	while (true)
	{
		cap.read(img);
		imshow("Image", img);
		waitKey(1);
	}
}

猜你喜欢

转载自blog.csdn.net/bigData1994pb/article/details/124415040