【opencv七】利用opencv调用电脑摄像头

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qiu931110/article/details/85174008

利用opencv调用电脑摄像头,并实时显示。其实就是用cap.open(0)这一个语句就可以调用本机摄像头了。

#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
using namespace cv;

int main()
{
	namedWindow("Example5",WINDOW_AUTOSIZE);

	VideoCapture cap;
	cap.open(0);
    //VideoCapture cap(0);这句话可以替代上面两个语句,效果是一致的。
	if (!cap.isOpened())
	{
		std::cerr << "Couldn't open capture." << std::endl;
		return -1;
	}

	Mat frame;
	while(1)
	{ 
		cap >> frame;
		if (frame.empty()) break;
		imshow("Example5",frame);
		if (waitKey(33) >= 0) break;
	}

	getchar();
	return 0;

}

如下图所示,,摄像头画质差,,人还。。嚇嚇,仅仅为了展示调用成功。

猜你喜欢

转载自blog.csdn.net/qiu931110/article/details/85174008