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