program using getsnapshot works some days, not the next

2 次查看(过去 30 天)
I have a program that takes camera images and it runs fine for days then stops (timeout from getsnapshot). This is also true of the image acquisition app. The camera viewer from the vendor (Allied Vision) works all the time.
Here is a test program
imaqreset;
vidObj = videoinput('gentl', 1, 'Mono8');
% Configure the object for manual trigger mode.
vidObj.FramesPerTrigger = 1;
vidObj.TriggerRepeat = 0;
triggerconfig(vidObj, 'manual');
vidSrc = getselectedsource(vidObj);
vidSrc.TriggerMode = 'Off';
vidSrc.TriggerSelector = 'FrameStart';
vidSrc.TriggerSource = 'FixedRate';
exp = 2000;
vidSrc.ExposureTimeAbs = exp;
maxFrameRate = vidSrc.AcquisitionFrameRateLimit;
frameRate = min(maxFrameRate, 10);
vidSrc.AcquisitionFrameRateAbs = frameRate;
% Now that the device is configured for manual triggering, call START.
% This will cause the device to send data back to MATLAB, but will not log
% frames to memory at this point.
start(vidObj)
% Measure the time to acquire n frames.
n = 10;
tic
time = zeros(n,1);
for i = 1:n
[snapshot, mdata] = getsnapshot(vidObj);
time(i) = mdata;
end
% pause off
elapsedTime = toc
% Compute the time per frame and effective frame rate.i 0
timePerFrame = elapsedTime/n
effectiveFrameRate = 1/timePerFrame
% Call the STOP function to stop the device.
stop(vidObj)
delete(vidObj);
clear vidSrc;
clear vidObj
imaqreset % to release camera

回答(1 个)

Sachin Lodhi
Sachin Lodhi 2024-2-16
编辑:Sachin Lodhi 2024-3-6
Hello Kurt,
It seems you're encountering a timeout issue when using the ‘getsnapshot’ method. Before trying a workaround, please proceed with the following steps to diagnose the issue:
  1. Confirm that the appropriate device drivers for your camera are properly installed on your computer.
  2. To ensure that your camera is being detected and associated with the correct ‘DeviceID’, execute the following command in MATLAB: imaqhwinfo('winvideo')
  3. Look for any errors by checking ‘imaqsupport’. For additional details regarding ‘imaqsupport’, you can visit the following link: https://www.mathworks.com/help/imaq/contacting-mathworks-and-using-the-imaqsupport-function.html
If you continue to face the timeout error, a potential solution is to configure your camera to use triggers. This method allows you to capture frames whenever the camera is triggered, which can help prevent timeout errors that may occur due to the frequent starting and stopping of the camera in a loop with ‘getsnapshot’. Here is a pseudo-code of how to set this up:
vid.TriggerRepeat = inf;
vid.FramesPerTrigger = 1;
triggerconfig(vid, 'manual');
start(vid);
% Loop to continuously trigger and acquire data
while true
trigger(vid); % Manually trigger the camera
frame = getdata(vid); % Retrieve the captured frame
% Process the frame as needed
end
Note that this is a pseudo-code example, and you'll need to adapt it to fit your specific application, including adding any necessary exit conditions for the loop.

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by