O'Reilly logo

OpenCV 2 Computer Vision Application Programming Cookbook by Robert Laganière

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading video sequences

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 to perform frame extraction from video files, or even from a USB camera. 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 to 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 simply 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); ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required