The reading of video mainly utilizes the Videocapture class in OpenCV. You can also make calls to the camera.
There are two ways to provide read-in video in the Videocapture class.
Instantiate and initialize first
VideoCapture capture;capture.open("Sugar.avi");
Initializing at the same time as instantiation
capture("Sugar.avi");
After the video is read into the Videocapture class object, it is immediately possible to display each frame with a loop.
Sugar.avi also needs to be placed in the directory as 1.jpg.
#include<opencv2/opencv.hpp>usingnamespace cv;int main(){ VideoCapture capture("Sugar.avi"); while(1) { Mat frame; capture>>frame; imshow("读取视频", frame); if(waitKey(600) break; } return0;}
The results of the operation are as follows:
Earlier in the study note 5 written about canny edge detection, in fact, in the video we can also add in. The code is as follows:
#include <opencv2/opencv.hpp>using namespaceCvintMain () {Videocapture capture ("Sugar.avi"); Mat edges; while(1) {Mat frame; capture>>frame; Cvtcolor (frame, edges, cv_bgr2gray); Blur (edges, edges, Size (7,7)); Canny (edges, edges,0, -,3); Imshow ("read Video", edges);if(Waitkey ( -) >=0) Break; }return 0;}
The results of the operation are as follows:
More learning materials about OPENCV and image processing and pattern recognition will continue to be updated, so stay tuned for this blog.
OpenCV (Study note 6)-Video reading and display