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 withRGB24
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
).
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');
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'
Create a
VideoWriter
object with the profile set to Motion JPEG 2000.logfile = VideoWriter('logfile.mj2','Motion JPEG 2000')
Configure the video input object to use the
VideoWriter
object.vidobj.DiskLogger = logfile;
Now that the video input object is configured for logging data to a Motion JPEG 2000 file, initiate the acquisition.
start(vidobj)
Wait for the acquisition to finish.
wait(vidobj,5)
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
You can verify that the
FramesAcquired
andDiskLoggerFrameCount
properties have identical values by using these commands and comparing the output.vidobj.FramesAcquired vidobj.DiskLoggerFrameCount
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 theFramesAcquired
property. Doing so causes disk logging to stop without all of the data being logged.If
start
is called multiple times without supplying a newVideoWriter
object, the contents of the previous file are erased whenstart
is called.After the
VideoWriter
object has been passed to theDiskLogger
property, you should not modify it.