Skip to Main Content Skip to Search
Home |   Select Country  Choose Country  |  Contact Us  |  Cart Store 
Create Account | Log In
Products & Services Solutions Academia Support User Community Company
spacer spacer spacer spacer spacer spacer

 

Image Acquisition Toolbox 3.4

Creating Time-Lapse Video Using Postprocessed Data

The Image Acquisition Toolbox™ makes it easy to produce time-lapse photography. In this demo, we will use postprocessing to delete frames from an acquired sequence of images. This is ideal for situations where you are not sure which frames are relevant during capture, or where your processing would take too long to occur during the acquisition. A possible application would be to delete frames that have no motion relative to the previous frame. The primary disadvantage of this method of time decimation is that it requires large amounts of memory to store all the frames. This demo acquires to memory, but you would likely acquire to an AVI file, and then use the mmreader command to postprocess the frames.

Watch a day long time-lapse sequence. (21 seconds)

Contents

Create a Video Input Object

Before acquiring images using the Image Acquisition Toolbox, create a video input object.

% When executing the following code, you may need to
% modify it to match your acquisition hardware.
vid = videoinput('winvideo',1,'RGB24_400x300');

Configure the Video Input Object

The configuration we will use is

  • Acquire 100 frames
set(vid,'FramesPerTrigger',100);
vid
Summary of Video Input Object Using 'Creative WebCam (WDM)'.

   Acquisition Source(s):  input1 is available.

  Acquisition Parameters:  'input1' is the current selected source.
                           100 frames per trigger using the selected source.
                           'RGB24_400x300' video data to be logged upon STAR
T.
                           Grabbing first of every 1 frame(s).
                           Log data to 'memory' on trigger.

      Trigger Parameters:  1 'immediate' trigger(s) on START.

                  Status:  Waiting for START.
                           0 frames acquired since starting.
                           0 frames available for GETDATA.

Acquire and Retrieve the Frames

start(vid);
wait(vid);
framesavailable = get(vid,'FramesAvailable')
framesavailable =

   100

frames = getdata(vid,framesavailable);

Postprocess the Acquired Frames

Here, simply remove every other frame. However, you could do processing that is much more complex.

toberemoved_index = [2:2:framesavailable];
frames(:,:,:,toberemoved_index) = [];
numframes = size(frames,4)
numframes =

    50

Render the Frames to an AVI File

Render the frames to an AVI file. To do this, create the AVI file, call the addframe function to add each frame to the AVI file, and then use the close function to release the resources associated with the AVI file.

avi = avifile('timelapsevideo');
for frame_index=1:numframes
    avi = addframe(avi,frames(:,:,:,frame_index));
end
avi = close(avi);

Play Back the Time-Lapse AVI Sequence

To play back the time-lapse AVI sequence, right-click on the filename in the MATLAB® Current Directory browser, and choose Open Outside MATLAB from the context menu.

Clean Up

When you are done with the video input object, you should use the delete function to free the hardware resources associated with it, and remove it from the workspace using the clear function.

delete(vid);
clear vid;
Contact sales
Free technical kit
Trial software
E-mail this page

Get Pricing and
Licensing Options