ubuntu opencv c++ 读取摄像头

代码在git
main.cpp

clude <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
#include <opencv2/core/core.hpp>

using namespace cv;


int main()
{
    VideoCapture cap(0);
    if(!cap.isOpened())
    {
        return -1;
    }
    Mat frame;
    Mat edges;

    bool stop = false;
    while(!stop)
    {
        cap>>frame;
        cvtColor(frame, edges, CV_BGR2GRAY);
//        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);  
//        Canny(edges, edges, 0, 30, 3);  
        imshow("当前视频",frame);
        if(waitKey(30) >=0)
            stop = true;
    }
    return 0;
}


CMakeLists.txt

cmake_minimum_required(VERSION 2.8)
project( camer )
find_package( OpenCV REQUIRED )
include_directories( ${OpenCV_INCLUDE_DIRS} )
add_executable( camer main.cpp )
target_link_libraries( camer ${OpenCV_LIBS} )
cd build
cmake ..
make 
./camer
posted @ 2022-08-19 22:47  luoganttcc  阅读(92)  评论(0)    收藏  举报