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 a Noncontiguous Acquisition

The Image Acquisition Toolbox™ makes it easy to produce time-lapse video. The most efficient way to do time-lapse acquisition is to use the Image Acquisition Toolbox's built-in ability to log frames directly to an AVI file, and its ability to perform time decimation by retaining only a fraction of all the frames acquired by the camera.

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');

Determine the Frame Rate

Most devices do not allow you to control their frame rate. It is best to determine the frame rate experimentally by acquiring frames and analyzing the time stamps of the frames.

set(vid,'FramesPerTrigger',100);
start(vid);
wait(vid,Inf);

% Retrieve the frames and timestamps for each frame.
numframes = get(vid,'FramesAvailable');
[frames,time] = getdata(vid,numframes);

% Calculate the frame rate by taking the average difference
% between the timestamps for each frame.
framerate = mean(1./diff(time))
framerate =

   17.5296

Specify the Noncontiguous Acquisition

The FrameGrabInterval property specifies how often frames are stored from the video stream. For instance, if we set it to 5, then only 1 in 5 frames is kept -- the other 4 frames will be discarded.

% We want to compress 30 seconds into 3 seconds, so
% only acquire every tenth frame.
set(vid,'FrameGrabInterval',10);

Determine the Number of Frames to Acquire

To determine how many frames to acquire in total, calculate the total number of frames that would be acquired at the device's frame rate, and then divide by the FrameGrabInterval.

capturetime = 30;
interval = get(vid,'FrameGrabInterval');
numframes = floor(capturetime * framerate / interval)
numframes =

    52

set(vid,'FramesPerTrigger', numframes);

Configure AVI Disk Logging

Due to the large number of frames that will be acquired, it is more practical to log the images to disk rather than to memory. Using the Image Acquisition Toolbox, you can log images directly to an AVI file. We configure this using the LoggingMode property.

set(vid,'LoggingMode','disk');

Create an AVI file object to log to, using the avifile command. We must specify the filename to use, and the frame rate that the AVI file should be played back at. Then, set the DiskLogger property of the video input object to the AVI file.

avi = avifile('timelapsevideo','fps',framerate);
set(vid,'DiskLogger',avi);
vid
Summary of Video Input Object Using 'Creative WebCam (WDM)'.

   Acquisition Source(s):  input1 is available.

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

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

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

Perform the Time-Lapse Acquisition

Start the time-lapse acquisition, and wait for the acquisition to complete. Note that the Image Acquisition Toolbox does not tie up MATLAB® while it is acquiring. You can start the acquisition and keep working in MATLAB.

start(vid);

% Wait for the capture to complete before continuing.
wait(vid,Inf);

Close the AVI File

Once the capture is completed, retrieve the AVI file object, and use the close function to release the resources associated with it.

avi = get(vid,'DiskLogger');
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