Main Content

Logging Image Data to Disk

Formats for Logging Data to Disk

While a video input object is running, you can log image data being acquired to a disk file. Logging image data to disk provides a record of your data.

For the best performance, logging to disk requires a MATLAB® VideoWriter object, created by a MATLAB function, not an Image Acquisition Toolbox™ function. After you create and configure a VideoWriter object, provide it to the videoinput object DiskLogger property.

VideoWriter provides a number of different profiles that log the data in different formats. The following example uses the Motion JPEG 2000 profile, which can log single-banded (grayscale) data as well as multi-byte data. Supported profiles are:

  • 'Motion JPEG 2000' — Compressed Motion JPEG 2000 file.

  • 'Archival' — Motion JPEG 2000 file with lossless compression.

  • 'Motion JPEG AVI' — Compressed AVI file using Motion JPEG codec.

  • 'Uncompressed AVI' — Uncompressed AVI file with RGB24 video.

  • 'MPEG-4' — Compressed MPEG-4 file with H.264 encoding (systems with Windows 7 or macOS 10.7 and later).

  • 'Grayscale AVI' — Uncompressed AVI file with grayscale video. Only used for monochrome devices.

  • 'Indexed AVI' — Uncompressed AVI file with indexed video. Only used for monochrome devices.

Logging Data to Disk Using VideoWriter

This example uses a GigE Vision® device in a grayscale format (Mono10).

  1. Create a video input object that accesses a GigE Vision image acquisition device and uses grayscale format at 10 bits per pixel.

    vidobj = videoinput('gige',1,'Mono10');
  2. You can log acquired data to memory, to disk, or both. By default, data is logged to memory. To change the logging mode to disk, configure the video input object LoggingMode property.

    vidobj.LoggingMode = 'disk'
  3. Create a VideoWriter object with the profile set to Motion JPEG 2000.

    logfile = VideoWriter('logfile.mj2','Motion JPEG 2000')
  4. Configure the video input object to use the VideoWriter object.

    vidobj.DiskLogger = logfile;
  5. Now that the video input object is configured for logging data to a Motion JPEG 2000 file, initiate the acquisition.

    start(vidobj)
  6. Wait for the acquisition to finish.

    wait(vidobj,5)
  7. When logging large amounts of data to disk, disk writing occasionally lags behind the acquisition. To determine whether all frames are written to disk, you can use the DiskLoggerFrameCount property.

    while (vidobj.FramesAcquired ~= vidobj.DiskLoggerFrameCount) 
        pause(.1)
    end
  8. You can verify that the FramesAcquired and DiskLoggerFrameCount properties have identical values by using these commands and comparing the output.

    vidobj.FramesAcquired
    vidobj.DiskLoggerFrameCount
  9. When the video input object is no longer needed, delete it and clear it from the workspace.

    delete(vidobj)
    clear vidobj

Guidelines for Using a VideoWriter Object to Log Image Data

Note the following when using VideoWriter.

  • You should not delete the video input object until logging has been completed as indicated by the DiskLoggerFrameCount property equaling the FramesAcquired property. Doing so causes disk logging to stop without all of the data being logged.

  • If start is called multiple times without supplying a new VideoWriter object, the contents of the previous file are erased when start is called.

  • After the VideoWriter object has been passed to the DiskLogger property, you should not modify it.