Now that you are acquainted with the processes of importing videos in MATLAB and creating new ones from still images, it is time we explore another aspect of MATLAB video processing, which is video acquisition. In this chapter, we will learn how you can use MATLAB to acquire videos, or sequences of images, which are saved on your computer rather than the storage of the camera. Furthermore, we will learn about the storage space problems faced everyday by video processing professionals and discuss compression issues and tricks, so that we mitigate this problem. Finally, some difficulties of real-time video processing in MATLAB will be presented and explained. Various tips on speeding up such processes will also be given. While learning all these, we will investigate hands-on examples that will help you comprehend various implementation techniques.
In this chapter, we will cover:
So, let's start!
Till now we have used MATLAB as a powerful and versatile image processing tool. In the previous chapter, we also started exploring its video reading and writing capabilities. You may be surprised to find out that MATLAB has another useful functionality. It can be used to capture and record images and videos shot either by external cameras connected to a PC, or by internal cameras embedded in laptops. The tool that supports these capabilities is included in the Image Acquisition Toolbox and it is called Image Acquisition Tool.
The Image Acquisition Tool is a simple, yet effective, Graphical User Interface (GUI) that enables MATLAB to turn your PC to a Digital Video Recorder (DVR). It is invoked by simply typing its function name in the command line as follows:
>> imaqtool
Once it is called, the window that appears looks like the following screenshot:
In the Image Acquisition Tool window, there are several subwindows that are used for acquisition purposes. We will briefly learn their properties here, so that you know your way around when we start using this tool.
The Hardware Browser window contains the list of acquisition devices that can be used by the Image Acquisition Tool. If your computer does not have a camera connected to it, or an embedded camera, this list will be empty. When a camera is detected by the Hardware Browser window, then its name, followed by its supported video formats are listed in the window. In our case, just one video camera with two supported formats was connected to the PC, so expanding its list of supported formats looked like the following screenshot:
The default video format was highlighted and written in bold, so that we know that it is preselected for us. Of course, we can choose the alternative format just by clicking on it.
The Information window is used to provide additional information about whichever part of the list in the Hardware Browser window you have clicked on. In our case, clicking sequentially on the first three items of the list, leads to the following results:
The Desktop Help window contains helpful information about all the other windows in the GUI. It will change its contents depending on the window you have chosen to click on.
The Preview window is the part of the tool that provides a visual guide for you on what the camera is capturing. You can start or stop previewing what your camera sees, by clicking on the Start Preview or Stop Preview button respectively. From here, you can also start or stop the acquisition process, by clicking on the Start Acquisition or Stop Acquisition button respectively. There is also a Trigger button that may be used when you have set the acquisition trigger to be manual (through the Acquisition Parameters window) and finally there is an Export Data... button to save the acquired video, or sequence of images. This option allows you to export the video to a MAT-file, to the MATLAB Workspace, to the Movie Player, or to a video file using VideoWriter. All previews are displayed in a figure embedded in the Preview window, the size of which changes dynamically when you change the size of the window.
The Acquisition Parameters window is the panel in which all the settings for the acquisition process are defined. It contains five different tabs, named General, Device Properties, Logging, Triggering, and Region of Interest. Let's see what their settings are.
The Device Properties tab will be useful only in cases where your acquisition device allows it. In our examples it won't be the case, since our camera did not support its properties to be set. Other cameras may give you the choice of setting properties such as its exposure, or frame rate.
The Logging tab allows you to define where the acquired frames will be saved, under which filename, how high your allowed memory limit will be set, and finally the output file format you want to use. More specifically:
VideoWriter
function, in the path and under the filename that you choose in the Disk Logging (VideoWriter) setting.The Triggering tab allows you to change the following settings:
The Region of Interest tab allows you to define a region of the frame that you want to be acquired. By default, the entire frame will be saved, but you can limit the area either by clicking on the Select or Edit button and then defining a rectangular area of the frame shown in the Preview window (you must have clicked on Start Preview first), or by setting the X-offset and the Y-offset as shown in the following screenshot:
The Session Log window is similar to the Command History window of the MATLAB environment, which was presented in the first chapter. It is a very useful part of the Image Acquisition Tool, since it dynamically presents the equivalent command line actions for every choice you make in the GUI. It can be used to teach you some of the core functions used for image acquisition, so that later on you can use them in your own MATLAB code.