Until now, we have demonstrated ways to display videos in MATLAB that are quite useful for adding processing steps in the loop, but are somewhat difficult in comparison to standard video-playing software. However, MATLAB also provides a tool aimed at those that do not want to get their hands dirty with frame-by-frame processing. Its name is implay
and it has a pretty straightforward usage. It can be used in three different ways; as a standalone GUI-based video player, as a function that plays back a given image sequence stored in a matrix and as a function that loads and plays a video given its filename. Let's see how these work.
This is the most common way to use this tool. It is invoked by typing in its name:
>> implay
This opens the following window:
This GUI gives you the following choices:
imtool
for processing (fifth icon)imtool
(seventh icon)When we load a video, a second toolbar opens up beneath the first one:
This second toolbar will probably look familiar to anyone that has used video players of any kind. Its functionalities are:
All these functionalities give the everyday users of MATLAB a handy tool to playback their videos. Let's see how they can be combined with what we have already shown.
Instead of clicking on the third icon of the GUI, we can call implay
with the filename of the video we want to play as input:
>> implay('singleball.avi'),
We can also use a different frame rate:
>> implay('singleball.avi',20);
Combining it with a function such as imread and a loop that goes through all the filenames of images in a directory, we can also playback an image sequence such as the driving scene presented in an earlier example:
>> cd ('E:Videosseq'), % Change working directory >> contents = dir('*.jpeg'), % Get names of jpeg images >> for i = 1:length(contents) % Loop through all images images(:,:,:,i) = imread(contents(i).name); % Import and save them end >> implay(images,15); % Play back the video sequence at 15 fps