I. Reading a video sequence
OPENCV provides an easy-to-use framework for extracting image frames from video files and USB cameras, and if you simply want to read a video, you just need to create a cv::videocapture instance and extract each frame in the loop. Here the video is taken with the camera and saved as AVI file, the code is as follows:
#include <opencv2\highgui\highgui.hpp> #include <opencv2\imgproc\imgproc.hpp> #include <opencv2\core
\core.hpp> using namespace CV;
using namespace Std;
int main () {//Open camera Videocapture captrue (0);
Video Write Object Videowriter write;
Write the video file name string Outflie = "E://fcq.avi";
Get the width of the frame int w = static_cast<int> (Captrue.get (cv_cap_prop_frame_width));
int h = static_cast<int> (Captrue.get (cv_cap_prop_frame_height));
Size S (W, h);
Get frame rate Double r = captrue.get (Cv_cap_prop_fps);
Open video file, ready to write Write.open (Outflie,-1, R, S, True);
Open Failed if (!captrue.isopened ()) {return 1;
} bool stop = FALSE;
Mat frame;
Loop while (!stop) {//Read frame if (!captrue.read (frame)) break;
Imshow ("Video", frame);
Write file Write.write (frame);
if (Waitkey () > 0) {stop = true;
}}//Release object Captrue.release (); Write.release ();
Cvdestroywindow ("Video");
return 0; }
A video file named "Fcq.avi" was created in the E-drive directory after it was run.