Reading video sequences
In order to process a video sequence, we need to be able to read each of its frames. OpenCV has put in place an easy-to-use framework that can help us perform frame extraction from video files or even from USB or IP cameras. This recipe shows you how to use it.
How to do it...
Basically, all you need to do in order to read the frames of a video sequence is create an instance of the cv::VideoCapture
class. You then create a loop that will extract and read each video frame. Here is a basic main function that displays the frames of a video sequence:
int main() { // Open the video file cv::VideoCapture capture("bike.avi"); // check if video successfully opened if (!capture.isOpened()) return 1; // Get the frame rate double rate= capture.get(CV_CAP_PROP_FPS); bool stop(false); cv::Mat frame; // current video frame cv::namedWindow("Extracted Frame"); // Delay...