Main Content

Logging Data to Memory

This example shows how to log image data and view logged data.

Previewing Data

Before logging data, images from an image acquisition device can be previewed live using the PREVIEW function. Calling the PREVIEW function, will open a preview window. To close the preview window, use the CLOSEPREVIEW function.

%访问图像采集设备。vidobj = videoinput('winvideo', 1);
% Open the preview window.preview(vidobj)

单帧采集

To acquire a single frame, use the GETSNAPSHOT function.

snapshot = getsnapshot(vidobj);
% Display the frame in a figure window.imagesc(snapshot)

多框架获取

To specify the number of frames to log upon triggering, configure the video input object's FramesPerTrigger property.

% Configure the number of frames to log upon triggering.vidobj.FramesPerTrigger = 50;

An image acquisition object must be running before data can be logged. To initiate an acquisition, use the START function.

start(vidobj)
% Notice that the number of frames being logged to memory ...numAvail = vidobj.FramesAvailable
numAvail = 7
% ... 在增加 ...numAvail = vidobj.FramesAvailable
numAvail = 14
% ... over time.numAvail = vidobj.FramesAvailable
numAvail = 21

To retrieve logged data from memory, use the GETDATA function with the video input object and the number of frames to retrieve.

% Retrieve some of the logged frames.imageData = getdata(vidobj, 30);
%注意记忆中剩余的帧数。numAvail = vidobj.FramesAvailable
numAvail = 20
% Display the last frame extracted from memory.显示亮度图像(imageData (:,:,: 30))

% Wait for the acquisition to finish.wait(vidobj);

To acquire data continuously, configure the FramesPerTrigger property to infinity. Upon triggering, data will be logged until the video input object stops running. To stop an object from running, use the STOP function.

vidobj.FramesPerTrigger = inf;
% Initiate the acquisition.start(vidobj)% Notice the number of frames in memory.numAvail = vidobj.FramesAvailable
numAvail = 6
% Loop through till 10 frames are acquiredwhile(numAvail<=10) numAvail = vidobj.FramesAvailable;end
%停止收购。stop(vidobj)
% View the total number of frames that were logged before stopping.numAcquired = vidobj.FramesAcquired;
numAcquired = 10
% Retrieve all logged data.imageData = getdata(vidobj, numAcquired);
% Display one of the logged frames.imagesc(iMagedata(:,:,:,:,numaCquiried))))

Viewing Logged Data.

To view the most recently logged image data without extracting it from memory, use the PEEKDATA function with the video input object and the number of frames to view. Viewing logged data using PEEKDATA will not remove any logged data from memory.

% Configure the number of frames to log upon triggering.vidobj.FramesPerTrigger = 35;
% Initiate the acquisition.start(vidobj)
% Wait for the acquisition to finish.wait(vidobj, 3);
% Verify the number of frames logged to memory.numAvail = vidobj.FramesAvailable
numAvail = 35
% Access the logged data without extracting them from memory.imageData = peekdata(vidobj, numAvail);
%验证所有记录帧是否仍在内存中可用。numframeAvailable = vidobj.frameavailable
numFramesAvailable = 35

Once the video input object is no longer needed, delete and clear the associated variable.

delete(vidobj) clearvidobj