Acquiring frames for time-lapse videos

Now that you know how to acquire frames using the Image Acquisition Tool, and you have also understood the implications of enlarged uncompressed video sizes, it is time to revisit a technique covered in the previous chapter. More specifically, we will now discuss how the imaqtool can be used to create time-lapse videos. There are two ways we can use it:

  1. By acquiring a full video and then following the process shown in the previous chapter to extract the frames that will be used to make your time-lapse video. However, this process has the obvious flaw of requiring too much disk space in cases of videos that may last a day, or more.
  2. By manually triggering as many frames as you want (after having specified their number in Number of triggers). Of course, this way isn't ideal either, since it demands manual interaction.

This leads us to the conclusion that in order to tackle special tasks, such as time-lapse video creation, we should find alternative methods. For this reason, it is time to turn back to the powerful MATLAB command line and make use of the functions relating to image acquisition.

Detecting your acquisition hardware

The first step to acquiring videos through the command line is to detect the acquisition devices. This is a process that is performed through the use of imaqhwinfo:

>> imaqhwinfo

The output of the previous command is as follows:

ans = 
InstalledAdaptors: {'gentl'  'gige'  'matrox'  'winvideo'}
MATLABVersion: '8.0 (R2012b)'
ToolboxName: 'Image Acquisition Toolbox'
ToolboxVersion: '4.4 (R2012b)'

This result shows us the list of installed hardware adaptors. As you may see in the example describing the session log in the beginning of the chapter, imaqtool has used the winvideo adaptor to define the video input method. Hence, this is what we will also use here. Your selection may differ, according to the hardware you have installed in your computer.

Creating a video object and acquiring a frame

Now it is time to create a video object in our Workspace. This is accomplished using the function videoinput (exactly as in the code generated by imaqtool):

>> vidObj = videoinput('winvideo', 1, 'dvsd_720x576'),

The output of the previous code is as follows:

Error using videoinput (line 228)
There are no devices installed for the specified ADAPTORNAME. See IMAQHWINFO.

This doesn't look right! Something went wrong here. Despite the fact that the device is switched on and it has been recognized by imaqhwinfo, MATLAB produces an error message. Luckily, the solution is simple. We will just reset the image acquisition objects, using imaqreset, and then retry using videoinput:

>> imaqreset
>> vidObj = videoinput('winvideo', 1, 'dvsd_720x576'),

Success! This time, a video object named as vidObj has been created. It holds the information regarding the acquisition hardware we want to use and the resolution we will work in. The next step is to acquire a frame. Before we do, let's open a Preview window like the one used in imaqtool to get a glimpse of what our camera sees:

>> preview(vidObj)

The following screenshot is the output of the previous command:

Creating a video object and acquiring a frame

Now, we can grab one frame at any point in time we want and save it in matrix variable snapshot, using function getsnapshot:

>> snapshot = getsnapshot(vidObj);
>> figure,imshow(snapshot)    % Take a look at what we shot

The following screenshot is the output of the previous command:

Creating a video object and acquiring a frame

So, now that you know how you can capture a frame using the command line, the sky is the limit! The next step is to create a free-of-charge MATLAB-based intervalometer for our time-lapse videos. As already mentioned in the previous chapter, intervalometers are devices that take over the timing of frame capturing by our device. They also allow for more complicated adjustments, for example, the shutter speed, HDR multiple exposures, and so on. These functionalities can be also included in MATLAB, if the capturing device allows the software to manipulate them. However, the only thing that we will need for our simple example is a way to control the time intervals between sequential frame acquisitions.

The only extra function we will need is pause. This function pauses the execution of a program for a given number of seconds (given as input), before allowing it to continue. Let's see how this will work.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset