main content

logging data to memory -凯发k8网页登录

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.

% access an image acquisition device.
vidobj = videoinput('winvideo', 1);
% open the preview window.
preview(vidobj)

single frame acquisition

to acquire a single frame, use the getsnapshot function.

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

multi-frame acquisition

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
% ... is increasing ...
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);
% notice the number of frames remaining in memory.
numavail = vidobj.framesavailable
numavail =
     20
% display the last frame extracted from memory.
imagesc(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 acquired
while(numavail<=10)
    numavail = vidobj.framesavailable;
end
% stop the acquisition.
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(:,:,:,numacquired))

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);
% verify that all logged frames are still available in memory.
numframesavailable = vidobj.framesavailable
numframesavailable =
    35

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

delete(vidobj)
clear vidobj
网站地图