The example we saw previously is a very simple one. The background is still, there is no particular fluctuation of the brightness on the scene, and the moving object has a very distinctive color. Let's now see what happens when we have a more complex scene to handle. We will work with the driving video, presented in the previous chapter, which represents one of the most challenging scenarios; a moving camera, with a scene with moving background, and several moving objects. Let's start:
Our first step is, as always, to load the video we will process:
>> obj = VideoReader('inter.avi'); % Read video file >> vid = read(obj); % Load all frames
The montage of our frames looks like this:
>> montage(vid,'Size',[4 7]) % Using a 4x7 grid for our 28 frames
Now, we will subtract each frame from the next one, excluding the first. The result will be stored in a predefined matrix:
>> subtracted = zeros(size(vid)); % Preallocate space...