Now it is time to tackle our first video acquisition assignment. We will use the most common settings to save a video in our disk, explaining every step of the process. The camera used for this example, will be a 10-year old DV camera, with a firewire (IEEE 1394) port. The connection to the PC will be via the firewire port on our motherboard. Other viable solutions can be used, for example, USB web cams, frame grabbers, and so on. A list of supported hardware per manufacturer and per operating system can be found on https://www.mathworks.com/products/imaq/supported/index.html.
Now, let's start our process:
imaqtool
. Since we are working on Windows, we can ensure that our camera is supported, using a free utility that can be downloaded from https://www.mathworks.com/products/imaq/supported/detect-devices-utility.zip. Running the 64 bit executable file detectDevices.exe
on our 64 bit system yields to the following result:>> imaqtool
The output of the previous command is as follows:
As expected, the camera was recognized and it showed up in the Hardware Browser window, under the name Microsoft DV Camera and VCR (winvideo-1).
500.0
MB (you can set it lower if you don't have enough RAM).E:VideosAcquisition
.bin.avi
). We will change this to test.avi for this example.30
. If you have followed all the actions above correctly, you should see the the following Logging tab:test.avi
video is safely stored in our disk and we also have a maximum of 500.0
MB of video stored in our RAM. In case we exceed the storage limit, we will get a warning message as follows:9
of the total 401
frames that were acquired (1 every 50). The test.avi
video is stored in the disk at this point.vid = videoinput('winvideo', 1, 'dvsd_720x576'), src = getselectedsource(vid); vid.FramesPerTrigger = 1; vid.FramesPerTrigger = Inf; vid.LoggingMode = 'disk&memory'; imaqmem(500000000); diskLogger = VideoWriter('E:VideosAcquisitionin.avi', 'Uncompressed AVI'), vid.DiskLogger = diskLogger; diskLogger = VideoWriter('E:VideosAcquisition est.avi', 'Uncompressed AVI'), vid.DiskLogger = diskLogger; preview(vid); start(vid); stoppreview(vid); test = getdata(vid);
This was a rather detailed example of a simple way to work with the Image Acquisition Tool of MATLAB. The steps described the process of setting up the tool to behave as a simple video recorder, waiting for the user's command to start and stop the acquisition process. The acquisition is performed at a constant frame rate set to 30 fps
and the video is saved both in the RAM and a predefined folder of the disk. A thing to beware of is that the RAM can keep a limited amount of data, defined by you. If the video exceeds the set limit, an error message like the one presented in step 12 pops up. However, you do not lose your work, since you can stop the recording and export the video logged to the RAM in any of the available ways you wish. After we saved the video both in an .avi
file on the disk and in the MATLAB Workspace as a four-dimensional matrix, we then proceeded to save the commands generated from our process in a MATLAB script.
Now that you have an idea of how the Image Acquisition Tool works, it is time that you take the wheel. Let's try to make a different variation of the acquisition process by adding some functionality. You should try to set up the tool, so that it gets to do 25 manually triggered acquisitions of frames. The data should be logged only to the disk, in a folder of your choice, using the filename test2.mp4
. The output file should be compressed as MPEG-4 of a quality factor of 100 and the frame rate should be 25 fps (leading to a video that is 1 second long). The choice of resolution is up to you.
If you perform the settings correctly and click on the
Start Acquisition
button, you will get a message with a counter that informs you what the number of your click on the Trigger button will be, out of a total of 25. Every time you click on the Trigger button, the counter will be increased by one, until it reaches 25, in which case the acquisition process will stop. This way you will produce a video file that is 1 second long, comprises 25 frames and looks like a time-lapse video, since you naturally did not click all the frames at a frequency of 1/25th of a second.