【机器视觉学习笔记】OpenCV C++ 调用笔记本摄像头

平台:Windows 10 20H2
Visual Studio 2015
opencv_contrib-3.4.12


转自【opencv七】利用opencv调用电脑摄像头 —— yuanCruise

测试程序

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

using namespace cv;

int main()
{
    
    
	namedWindow("Example", 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("Example", frame);
		if (waitKey(33) >= 0) break;
	}

	waitKey(0);
	return 0;
}

实验现象

在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_44457994/article/details/121601338