#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main() {
VideoCapture cap(0);
if (!cap.isOpened()) {
cout << "无法打开摄像头" << endl;
return -1;
}
namedWindow("Camera", WINDOW_NORMAL);
while (true) {
Mat frame;
cap.read(frame);
if (frame.empty()) {
cout << "无法从摄像头中获取图像" << endl;
break;
}
imshow("Camera", frame);
if (waitKey(1) == 27)
{
break;
}
}
cap.release();
destroyWindow("Camera");
return 0;
}
cmake_minimum_required(VERSION 3.16)
project(untitled)
set(CMAKE_CXX_STANDARD 14)
add_executable(untitled main.cpp)
find_package(OpenCV REQUIRED)
target_link_libraries(untitled ${OpenCV_LIBS})