- Setting a larger Timeout value for the object
Image Acquisition Error: "GETDATA timed out before FRAMES were available. Error using imaqdevice/getdata. GETDATA timed out before FRAMES were available."
23 次查看(过去 30 天)
显示 更早的评论
Hi, hope y'all are doing well. Currently, I am acquiring images on two cameras that are triggered near simultaneously using an Arduino. I have a MatLab function that uses "fprintf(ardunio_var, #)" to trigger the Arduino to capture images. Then it uses "getdata(cam1, 1)" to get the data, and then write it. However, I am getting a timeout error almost 90% of the time. Every once in a while, I will stop the cam, then start it and it will work and acquire the image with no issues. I was wondering what might be the issue. I have alread looked at previous solutions, using a conditional loop to determine when frames are available, longer pause time, etc. But I am having no luck. Any help would be appreciated. Thanks!
The error is:
Error event occurred at 15:05:26 for video input object: F7_RGB_2048x2048_Mode0-pointgrey-2.
GETDATA timed out before FRAMES were available.
Error using imaqdevice/getdata (line 154)
GETDATA timed out before FRAMES were available.
Error in (line 102)
img2 = getdata(cam2, 1);
Below is the MatLab Code, and I can also include the Arduino code if necessary.
%% connect camera
if exist('cam2', 'var')
stop(cam1);
stop(cam2);
end
cam1 = videoinput('pointgrey', 1, 'F7_RGB_2048x2048_Mode0');
cam2 = videoinput('pointgrey', 2, 'F7_RGB_2048x2048_Mode0');
exposure = 100; % ms
roi = [560 848 960 784];
triggerconfig(cam1, 'hardware', 'risingEdge', 'externalTriggerMode0-Source3');
triggerconfig(cam2, 'hardware', 'risingEdge', 'externalTriggerMode0-Source3');
% triggerconfig(cam1, 'manual'); % for software trigger only
% triggerconfig(cam2, 'manual');
cam1.TriggerRepeat = Inf;
cam2.TriggerRepeat = Inf;
cam1.FramesPerTrigger = 1;
cam2.FramesPerTrigger = 1;
cam1.ROIPosition = roi;
cam2.ROIPosition = roi;
src1 = cam1.source;
src2 = cam2.source;
src1.ExposureMode = 'Manual';
src1.Exposure = 1;
src1.FrameRateMode = 'Off';
% src1.FrameRate = framerate;
src1.Shutter = exposure; % exposure time in ms
src1.GainMode = 'Manual';
src1.Gain = 3;
src1.Gamma = 1;
src1.Saturation = 100;
src1.Sharpness = 0;
src1.WhiteBalanceRBMode = 'Manual';
src1.WhiteBalanceRB = [510 660];
src1.Brightness = 0;
src2.ExposureMode = 'Manual';
src2.Exposure = 1;
src2.FrameRateMode = 'Off';
% src2.FrameRate = framerate;
src2.Shutter = exposure * 1.3; % exposure time in ms; *1.3 to match intensity of cam1
src2.GainMode = 'Manual';
src2.Gain = 3;
src2.Gamma = 1;
src2.Saturation = 100;
src2.Sharpness = 0;
src2.WhiteBalanceRBMode = 'Manual';
src2.WhiteBalanceRB = [525 667];
src2.Brightness = 0;
start(cam1);
start(cam2);
img1 = getdata(cam1, cam1.FramesAvailable); % read first dummy frame
img2 = getdata(cam2, cam1.FramesAvailable);
stop(cam1);
stop(cam2);
%% Connect arduino
x=serial('COM7','BAUD', 9600);
fopen(x);
%% Preview
stop(cam1);
stop(cam2);
preview([cam1, cam2]);
%% Stop Cams
stop(cam1);
stop(cam2);
%% capture stereo images
sample ='paper_LED_5cm_WD'; % prefix of image name
%Object Path
path_sample = 'C:\Users\...\path';
start(cam1);
start(cam2);
temp = getdata(cam1, cam1.FramesAvailable);
temp = getdata(cam2, cam2.FramesAvailable);
src1.Shutter = 100;
src2.Shutter = 100;
fprintf(x, 4); % hardware trigger both cams
% %Pause 4 seconds so TIMEOUT ERROR doesnt occur?? doesnt work, have tried longer time as well.
pause(10);
% Wait until the frames are available. Doesnt work, just hangs most of the
% time, or repeats timeout error.
% n = 1;
% while cam1.framesAvailable==0 && cam2.framesAvailable==0
% pause(1);
% display(n);
% n = n+1;
% end
img1 = getdata(cam1, 1);
img2 = getdata(cam2, 1);
imwrite(img1, [path_sample, sample, '_cam1.png']);
imwrite(img2, [path_sample, sample, '_cam2.png']);
% imwrite(img1, [path_left,'1_', num2str(n), '.png']);
% imwrite(img2, [path_right,'2_', num2str(n), '.png']);
% n = n + 1;
stop(cam1);
stop(cam2);
0 个评论
回答(1 个)
Abhijeet
2023-9-5
Hi,
I understand you are getting error while using the ‘getdata’ function for processing image from Arduino. This error is caused by caused by the delay between the device and MATLAB, which is not a constant value and this is related to the system and device driver. Due to the delay, there are no available frames when the time exceeds the Timeout value. To ensure that you are getting data from the camera, you can follow either of the two options:
%set the Timeout property of VIDEOINPUT object 'vid' to 50 seconds
set(vid,'Timeout',50)
2. Before GETDATA, wait until there's an available frame
%Wait until at least 1 frame is available
while get(vid,'FramesAvailable')<1
unavailable=1;
end
I hope this helps you.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Image Acquisition Support Packages for Hardware Adaptors (Generic Video Interface) 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!