OpenCV自学笔记24. Raspberry pi +OpenCV 读取摄像头

Raspberry pi +OpenCV 读取摄像头

在Raspberry pi上调用摄像头,读取视频流中的每一帧,并利用Canny边缘检测,提取每一帧中的边缘,最终效果如下:

OpenCV自学笔记24. Raspberry pi +OpenCV 读取摄像头_第1张图片

ReadVideo.cpp

#include "opencv2/opencv.hpp"

using namespace cv;

int main(int, char**)
{
    VideoCapture cap(0); // open the default camera
    if(!cap.isOpened())  // check if we succeeded
        return -1;

    Mat edges;
    namedWindow("edges",1);
    for(;;)
    {
        Mat frame;
        cap >> frame; // get a new frame from camera

        cvtColor(frame, edges, CV_BGR2GRAY);
        GaussianBlur(edges, edges, Size(7,7), 1.5, 1.5);
        Canny(edges, edges, 0, 30, 3);

        imshow("edges", edges);
        if(waitKey(30) >= 0) break;
    }
    // the camera will be deinitialized automatically in VideoCapture destructor
    return 0;
}

注:代码来自OpenCV官网

CMakeLists.txt

project( ReadVideo )
find_package( OpenCV REQUIRED )
add_executable( ReadVideo ReadVideo )
target_link_libraries( ReadVideo ${OpenCV_LIBS} )

编译

cmake .
make

运行程序 : ./ReadVideo

OpenCV自学笔记24. Raspberry pi +OpenCV 读取摄像头_第2张图片

OpenCV自学笔记24. Raspberry pi +OpenCV 读取摄像头_第3张图片

你可能感兴趣的:(OpenCV,Respberry,OpenCV学习笔记)