Time for action – capturing a video using a firewire connection

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:

  1. Our first step is to connect the camera using a firewire cable and switch it on in camera mode. Once we do it, our device should be recognizable by 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:
    Time for action – capturing a video using a firewire connection
  2. Since the camera is detected, we should be able to use it in the Image Acquisition Tool window. Let's verify it by invoking it:
    >> imaqtool

    The output of the previous command is as follows:

    Time for action – capturing a video using a firewire connection

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

  3. Now that the camera is recognized, we can start setting up the recording. First, let's change the resolution we will use, from the default 720 x 480, to the slightly larger 720 x 576 resolution. We do this by clicking on the second available item on the list of supported formats in the Hardware Browser window. Clicking on it leads to the following result in the Information window:
    Time for action – capturing a video using a firewire connection
  4. The next step is to select some of the details of the acquisition process. For this first example, we will not use the triggering process. We will just make a simple video recorder that starts and stops at our command. To achieve this, we will set the Frames per trigger option in the General tab of the Acquisition Parameters window to Infinite.
  5. In order to demonstrate the logging options, we will use both the RAM and the disk. To do it, we first go to the Acquisition Parameters window and set the Log to option of the Logging tab to Disk and Memory.
  6. Then, we define the Memory limit to be 500.0 MB (you can set it lower if you don't have enough RAM).
  7. Now, it is time to select the name and format of our output video file. We will click on the Browse... button to select the folder in which we want to store our video. The folder we will use is E:VideosAcquisition.
  8. Then, we have to define a name for the stored video in the Filename field (the default name filled in for you along with the full path is bin.avi). We will change this to test.avi for this example.
  9. Our final setting will be to set the format and frame rate of the video we will acquire. For this example, we will leave the default values that is the Profile field will be Uncompressed AVI and the Frame Rate field will be 30. If you have followed all the actions above correctly, you should see the the following Logging tab:
    Time for action – capturing a video using a firewire connection
  10. Now that we are finished with the settings, it is time for our final steps. The Preview window is where we will be working. First off, we click on the Start Preview button, to generate a small previewing screen that plays the role of the camera LCD screen, displaying what the camera sees in real time.
  11. When we are ready to record, we click on the Start Acquisition button. This will start the logging process, both in the RAM and in the disk (in the file we specified in steps 7 and 8).
  12. Finally, when we want to stop the recording, we click on the Stop Acquisition button. At this point, the 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:
    Time for action – capturing a video using a firewire connection
  13. After we click on the Stop Acquisition button, the Preview window will display a grid of frames from our recording. In our case, it shows 9 of the total 401 frames that were acquired (1 every 50). The test.avi video is stored in the disk at this point.
  14. At this point, we can click on the Export Data... button to export the video that has been logged to the RAM. Since we have already saved our data to a video file, we will choose to export it also to the MATLAB Workspace. In the textbox defining the Variable name, we will type test. This leads to our Workspace window containing a four-dimensional matrix with all the acquired frames in it:
    Time for action – capturing a video using a firewire connection
  15. An optional, but useful, step for our learning purposes is to save the session log to a file, so that we get to keep and study the commands that were used in this acquisition session. To do this, we click on the disk icon in the Session Log window and save the commands as a MATLAB script in a folder of our choice. If we performed all the steps described above correctly, our resulting script should look something like this:
    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);

What just happened?

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.

Have a go hero – adding a trigger to our recording

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.

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

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