Video playback

Another important I/O task in computer vision is being able to open and process a video file. Fortunately, OpenCV can easily deal with videos through the VideoCapture class. Instead of constructing it with a device number, as was done previously, we need to create it with the file path. We can also use the empty constructor and make the open(String filename) method responsible for pointing to the file.

The videoplayback project available in the chapter's source code has the same structure as the swing-imageshow project, explained previously. It only differs when you initialize the VideoCapture instance:

VideoCapture capture = new VideoCapture("src/main/resources/videos/tree.avi");

We have also put a 50ms delay between each frame so ...

Get OpenCV 3.0 Computer Vision with Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.