#include<iostream>
//opencv头文件
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
VideoCapture capture(0);
while (1)
{
Mat frame;
capture >> frame;
imshow("摄像头", frame);
waitKey(30);
}
return 0;
}
opencv读取图片
#include<iostream>
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
Mat img = imread("images/test.jpg");
//k控制台窗口ID
namedWindow("test");
//显示图像
imshow("test", img);
//等待时间
waitKey(3000);
system("pause");
return 0;
}
opencv读取视频
#include <opencv2\opencv.hpp>
using namespace cv;
using namespace std;
int main()
{
//读取视频或摄像头
VideoCapture capture("images/1.avi");
while (true)
{
Mat frame;
capture >> frame;
imshow("读取视频", frame);
waitKey(30); //延时30
}
return 0;
}