一、读取摄像头
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
//读取视频或摄像头
VideoCapture capture(0);
while (true)
{
Mat frame;
capture >> frame;
imshow("读取视频", frame);
waitKey(30); //延时30
}
return 0;
}
二、摄像头的读取与保存
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img;
VideoCapture video(0);
if (!video.isOpened()) //判断是否调用成功
{
cout << "打开摄像头失败,请确认摄像头是否安装成功";
return -1;
}
video >> img;//获取图像
if (img.empty()) //判断读取图像是否成功
{
cout << "没有获取到图像" << endl;
return -1;
}
bool isColor = (img.type() == CV_8UC3);
VideoWriter writer;
int codec = VideoWriter::fourcc('M&#