CMakeLists.txt:
cmake_minimum_required(VERSION 3.16)
project(opencvTest)
set(CMAKE_CXX_STANDARD 14)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(opencvTest main.cpp)
target_link_libraries(opencvTest ${OpenCV_LIBS})
main.cpp
#include <iostream>
#include <opencv2/opencv.hpp>
#include <string>
using namespace cv;
using namespace std;
int main()
{
VideoCapture capture(0);
if(capture.isOpened())
{
cout<<"capture is opened"<<endl;
}
Mat frame;
while (capture.isOpened())
{
capture >> frame;
imshow("capture", frame);
cvWaitKey(10);//控制视频流的帧率,10ms一帧
}
return 0;
}