lengthy hardware triggered frame acquisitions



Hello,

Using Qimaging's software, our Rolera MGi firewire camera
achieves a little over 29 frames per second using a hardware
trigger and full resolution (512x512). These same results
can be achieved using a 'manual' trigger in Matlab. A new
frame can be acquired approximately every 34 milliseconds.
However, when triggerconfig in Matlab is set up to use a
hardware trigger the frame rate of the Rolera MGI drops to
1.25 frames per second (a new frame is acquired
approximately every 800 milliseconds).

Using a Nidaq card and the Qimaging trigger circuit the
possible hardware trigger conditions are 'fallingEdge' and
'risingEdge'. 'fallingEdge' is the same as pulse triggered
where the edge of the trigger pulse going from 5V to 0V
starts the exposure and the edge of the pulse going from 0V
to 5V stops the exposure. The 'risingEdge' condition
triggers a frame acquisition on the edge of the trigger
pulse going from 5V to 0V.

In the code below there are three analog out channels.
Channel number 2 lights a LED in front of the camera for 20
milliseconds, the same as the exposure time. Channel 1
feeds the QImaging Trigger circuit. The frame acquisition
and led are synchronized. Channel zero is a place holder
for now.

The full code below and the "while" loop at the very end
whre pretty much everything is commented out, acquire images
at 1.25 frames per second. Any ideas how to achieve 10 or
20 frames per second? Any ideas where the problem lies or
how to prove where the problem lies (daq, imaq, trigger
circuit, QImaging driver). My testing indicates the problem
lies in the imaq toolkit. Is it possible to prove this and
to prove where in the imaq toolkit the problem lies?

Matlab R2007b
daq toolbox 2.11
imaq toolbox 3.0
matlab 7.5
QImaging driver 1.90.1

Thank you,

Paul



function previewTriggered
%
% a simple function for testing image capture frame rates.

exposure = 0.020;
number_of_frames = 100;


% setup analogout
analogOut = analogoutput('nidaq', 'Dev1');
channel = addchannel(analogOut,0:2);
set(channel, 'Units', 'Volts');
set(channel, 'UnitsRange', [-10 10]);
set(analogOut, 'TriggerType', 'Immediate');
set(analogOut, 'SampleRate', 10000);
set(analogOut,'ClockSource','Internal');
set(analogOut, 'RepeatOutput', inf);

ioRepeatMatixInit = repmat([-10 5 0], 1000, 1);
ioRepeatMatrixStep1 = repmat([-10 0 2], 100, 1);
ioRepeatMatrixStep2 = repmat([-10 5 2], 100, 1);
ioRepeatMatrixStep3 = repmat([-10 5 0], 800, 1);
ioRepeatMatrix = repmat([ioRepeatMatrixStep1; ...
ioRepeatMatrixStep2; ioRepeatMatrixStep3], 1, 1);
ioRepeatMatrixFinal = repmat([-10 0 0], 1000, 1);


putdata(analogOut, ioRepeatMatixInit);
start(analogOut);



% camera specific set up
video_object = videoinput('qimaging',1,'MONO16_512x512');
triggerconfig(video_object,'hardware','risingEdge','TTL');
set(video_object, 'LoggingMode', 'memory')
set(video_object,'SelectedSourceName','input1')
set(video_object,'TriggerRepeat',number_of_frames);
set(video_object,'FramesPerTrigger',1);
set(video_object,'TriggerFrameDelay',0);
set(video_object,'ReturnedColorSpace','grayscale');
set(getselectedsource(video_object),'ClearingMode','None');
set(getselectedsource(video_object),'EMGain',0);
set(getselectedsource(video_object),'Exposure',exposure);
set(getselectedsource(video_object),'NormalizedGain','1.0');
set(getselectedsource(video_object),'Readout','10M');
set(getselectedsource(video_object),'ReadoutPort','EM');

% set ROI and start video object
set(video_object,'ROIPosition',[0, 0, 512, 512]);
start(video_object);
pause(2);

flushdata(video_object);

stop(analogOut);
putdata(analogOut, ioRepeatMatrix);
start(analogOut);


elapsedTime = 0;
frameNumber = 0;

while(frameNumber < number_of_frames);
tic;
display 'start of while loop'; toc;
get(video_object,'FramesAcquired')
toc;
while(get(video_object,'FramesAcquired') ~= ...
frameNumber);
get(video_object,'FramesAcquired');
end; toc;
frameNumber = frameNumber + 1; toc;

% wait... does not work for guaranteeing a
% frame has been acquired
%wait(video_object,120,'logging'); toc;

imageData = getdata(video_object,1,'uint16','numeric');
toc;
%imageData = peekdata(video_object,1); toc;
%imageData = getsnapshot(video_object); toc;
imshow(imageData,[300 7000]); toc;
minImageValue = min(min(imageData)); toc;
maxImageValue = max(max(imageData)); toc;
screenLine = [int2str(frameNumber), ...
', min = ' int2str(minImageValue) ...
', max = ' int2str(maxImageValue)]; toc;
display(screenLine); toc;
drawnow; toc;
elapsedTime = elapsedTime + toc;
end;

display(elapsedTime)
display(frameNumber)
timePerFrame = elapsedTime/number_of_frames
effectiveFrameRate = 1/timePerFrame

stop(analogOut);
putdata(analogOut, ioRepeatMatrixFinal);
start(analogOut);
stop(analogOut);
delete(analogOut);
clear analogOut;




Substitute the while loop above with the while loop below
and the same 1.25 frames per second frame rate is achieved.

while(frameNumber < number_of_frames);
tic;
%display 'start of while loop'; toc;
%get(video_object,'FramesAcquired')
%toc;
while(get(video_object,'FramesAcquired') ~= ...
frameNumber);
get(video_object,'FramesAcquired');
end; toc;
frameNumber = frameNumber + 1; toc;

% wait... does not work for guaranteeing a
% frame has been acquired
%wait(video_object,120,'logging'); toc;

%imageData = getdata(video_object,1,'uint16','numeric');
%toc;
%imageData = peekdata(video_object,1); toc;
%imageData = getsnapshot(video_object); toc;
%imshow(imageData,[300 7000]); toc;
%minImageValue = min(min(imageData)); toc;
%maxImageValue = max(max(imageData)); toc;
%screenLine = [int2str(frameNumber), ...
% ', min = ' int2str(minImageValue) ...
% ', max = ' int2str(maxImageValue)]; toc;
%display(screenLine); toc;
%drawnow; toc;
%elapsedTime = elapsedTime + toc;
end;

.



Relevant Pages