Adding Data To Every Frame of an Image Acquisition

3 views (last 30 days)
I'm using Image Acquisition Toolbox to acquire data from a GigE camera. Ideally, I would like to accomplish 3 tasks while acquiring images:
  1. Acquire frames as fast as possible (goal is around 90fps)
  2. Monitor a data stream input to the computer while acquiring images (using the Data Acquisition Toolkit). When the datastream provides a nonzero input, I'd like to be able to make a note of that and determine which frame in the acquisition aligns in time with the input.
  3. Preview the acquisition live while it is occuring.
I've found a number of ways to achieve each of these goals individually, but cannot find a solution for doing all three at once. See the three code examples below. Each accomplishes some of what I would like but not everything.
Here is what I have tried:
%% BASICS: SET UP THE CAMERA
vidObj = videoinput('gige')
triggerconfig(vidObj, 'manual') %enable manual trigger
logfile = VideoWriter('myVid.avi') %open videowriter to save to disk
vidObj.DiskLogger = logfile
%% ATTEMPT 1: acquire single images in a loop with preview. Achieves goals 2 and 3 but not 1
open(logfile)
frameTimeStamps = zeros(1, 100) %will hold time stamps for each frame in order to calculate frame rate
start(vidObj)
preview(vidObj)
tic
for i = 1:100
sn = getsnapshot(vidObj)
frameTimeStamps(i) = toc;
tic
logfile.writeVideo(sn)
if condition == true
%place holder, would make a note that the data stream showed a
%nonzero input here
end
end
toc;
stoppreview(vidObj)
stop(vidObj)
FramesPerSecond = 1/mean(frameTimeStamps) %%RESULTS IN ABOUT 30FPS, WAY TOO SLOW
%I have also tried implementing vidObj = imaq.VideoDevice in conjuction with
%the step(vidObj) function using this same framework, but it results in a roughly equal frame rate.
%% ATTEMPT# 2: acquire data in a loop without showing preview. Achieves goals 1 and 2 but not 3
open(logfile)
frameTimeStamps = zeros(1, 100)
start(vidObj)
tic
for i = 1:100
sn = getsnapshot(vidObj)
frameTimeStamps(i) = toc;
tic
logfile.writeVideo(sn)
if condition == true
%place holder, would make a note that the data stream showed a
%nonzero input here
end
end
toc;
stop(vidObj)
FramesPerSecond = 1/mean(frameTimeStamps) %%RESULTS IN ABOUT 90FPS, GOOD!
%% ATTEMPT 3: Acquire multiple frames at once outside of a loop. Achieves goals 1 and 3, but not 2 because I'm not imaging in a loop
vidObj.FramesPerTrigger = 100;
start(vidObj)
preview(vidObj)
tic
trigger(vidObj)
wait(vidObj) %for some reason I get an error here: "WAIT reached its timeout before OBJ stopped running"... not sure why
totalTime = toc;
stop(vidObj)
FPS = vidObj.FramesPerTrigger/totalTime %Can't actually run this version because of the above error using wait(), but signs indicate FPS should be around 90
Am I doing something wrong? Is there a way to achieve fast acquisition, preview the live image while logging, and check a condition on each frame?
Thanks
p.s. if anyone knows why I get the error when calling wait() in attempt 3 I would also appreciate help on that.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!