用c++opencv打开摄像头,并读取其画面
时间: 2023-05-29 13:01:33 浏览: 517
打开摄像头-C++_C++_调用摄像头_
5星 · 资源好评率100%
#include <opencv2/opencv.hpp>
int main()
{
cv::VideoCapture cap(0);
if(!cap.isOpened()) // check if we succeeded
return -1;
cv::namedWindow("My Camera Feed", cv::WINDOW_NORMAL);
while(true)
{
cv::Mat frame;
cap >> frame; // get a new frame from camera
cv::imshow("My Camera Feed", frame);
if(cv::waitKey(30) >= 0) break;
}
// the camera will be deinitialized automatically in VideoCapture destructor
return 0;
}
阅读全文