OPENCV Self-study note 24. Raspberry Pi +opencv Read camera

Source: Internet
Author: User
Raspberry pi +opencv read camera

Call the camera on the Raspberry Pi, read each frame in the video stream, and use the canny edge detection to extract the edges in each frame, the final effect is as follows:

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 W E 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, 3);

        Imshow ("edges", edges);
        if (Waitkey () >= 0) break;
    The camera would be deinitialized automatically in Videocapture destructor
    return 0;
}

Note: code from OPENCV official website

CMakeLists.txt

Project (Readvideo)
find_package (OpenCV REQUIRED)
add_executable (readvideo readvideo)
target_link_ Libraries (Readvideo ${opencv_libs})

Compile

CMake.
Make

Run the program:./readvideo

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.