Visual Studio2019打开电脑摄像头

Visual Studio2019打开电脑摄像头

#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;
}

猜你喜欢

转载自blog.csdn.net/qq_51432166/article/details/130912380