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:
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.
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.
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:
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:
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.