linux下用opencv读取摄像头数据

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;
}

猜你喜欢

转载自blog.csdn.net/alspd_zhangpan/article/details/107483911