Image acquisition in parallel via FireWire

Hi everyone,
I am trying to capture images from two cameras via firewire with Matlab. For this I use the parallel toolbox. I have oriented myself on the following example: https://de.mathworks.com/matlabcentral/answers/388286-how-can-i-acquire-images-from-multiple-gige-cameras-using-image-acquisition-toolbox-and-parallel-com . I do not use a GigE interface, so I have adapted the code accordingly.
The code I use is the following:
delete(imaqfind);
parpool(2)
spmd(2)
delete(imaqfind);
vid=videoinput('gentl',labindex, 'Mono8')
img=getsnapshot(vid);
end
This does not work, however. Does someone know what might be the error?
Many thanks in advance

Answers (1)

Post a screenshot of what you see when you run imageAcquisitionExplorer or imaqtool
If there are two cameras you should see two cameras. If they both use the same interface, there should be a unique ID for each one.
imaqfind() is a function and you should not delete it. Maybe you meant to run imaqreset instead?
Type imaqfind into the command window (without deleting it of course) and what does it show?

5 Comments

imaqfind() as a function is not being deleted: imaqfind() is returning a value, and what is being returned is what is being deleted.
Thanks for your answers.
When I check the imaqtool, both cameras are detected:
When I run the imaqhwinfo('gentl') command, it detects both cameras:
When I run the code above, then the error message is
No device is available at the specified DEVICEID. See
IMAQHWINFO(ADAPTORNAME).
Therefore, tried something else, which suprisingly does work better then the code above but still not correctly:
if isempty(gcp('nocreate'))
parpool(2)
end
spmd(2)
if 1==labindex
vid=videoinput('gentl',1, 'Mono8')
% img=getsnapshot(vid);
elseif 2==labindex
vid=videoinput('gentl',1, 'Mono8')
img=getsnapshot(vid);
end
end
Now when I comment the first img=getsnapshot(vid), as it can be seen in the code, the second camera captures the image. When I uncomment the first img=getsnapshot(vid) and comment the second, the first camera captures the image. However, when I uncomment both, then there is the following error message:
Error detected on worker 1.
Caused by:
Error using imaqdevice/getsnapshot (line 65)
The image acquisition device failed to start acquiring images.
I also tried to changed the 1 for a 2 in ('gentl',1, 'Mono8'). If I do this within the first part of the if statement, then the following error message appears:
Error detected on worker 1.
Caused by:
Error using videoinput (line 536)
The image acquisition device did not provide any video sources. Video sources are required.
However, if I try it within the elseif part of the if statement, then the following error message appears:
Error detected on worker 2.
Caused by:
Error using videoinput (line 413)
No device is available at the specified DEVICEID. See IMAQHWINFO(ADAPTORNAME).
Somehow, the first worker does detect both cameras but the second worker does only detect one and it is not possible to access both cameras simultaneously.
Do you maybe have any suggestions?
Many thanks in advance!
I think you should not be calling videoinput every time you want to get a snapshot. You should call it once for each camera to get the object, then call getsnapshot with the object of the camera you want, so try
vid1 = videoinput('gentl', 1, 'Mono8'); % Initialize video input object for camera 1.
vid2 = videoinput('gentl', 2, 'Mono8'); % Initialize video input object for camera 2.
% Now, later, call these as many times as you want
% without having to call videoinput again.
cam1Image = getsnapshot(vid1); % Get frame from camera #1.
cam2Image = getsnapshot(vid2); % Get frame from camera #2.
If that doesn't work there are alternative ways using functions like start() and getdata().
Thanks for your answer!
I did now the following, which kind of worked but somehow the cameras only take pictures sometimes I press the Run button, do you maybe know what might be the reason for this?
The error message is
Caused by:
Error using imaqdevice/getsnapshot (line 65)
The image acquisition device failed to start acquiring images.
What I also don't understand is why I have to call the cameras in both workers with the same number, i.e. in both workers I have to use videoinput('gentl',1, 'Mono8'), if I use videoinput('gentl',2, 'Mono8') for one camera, then there appears an error message.
if isempty(gcp('nocreate'))
parpool(2)
end
spmd(2)
if labindex==1
vid1=videoinput('gentl',1, 'Mono8')
else
vid2=videoinput('gentl',1, 'Mono8')
end
end
spmd(2)
if labindex==1
img1=getsnapshot(vid1);
else
img2=getsnapshot(vid2);
end
end
Many thanks in advance
I don't know how your user interface works. You don't have to snap images from both camera at the same time. You can snap them one at a time, you just need to be sure that when you get the image from camera #1 you use vid1 and when you get the image from camera #2 you use vid2. You can do that by making them globals and call this just in your startup routine.
app.vid1 = videoinput('gentl', 1, 'Mono8'); % Initialize video input object for camera 1.
app.vid2 = videoinput('gentl', 2, 'Mono8'); % Initialize video input object for camera 2.
After that use app.vid1 and app.vid2 (the global instances of those video input objects) in your button callback functions or wherever else you want (as long as app is in scope).
Tech support told me that you only need to get the video inputs once -- you do not want to call them every time you click a button on your GUI. Use getdata or getsnapshot as many times as you want without ever getting (or overwriting) the video input objects.

Sign in to comment.

Products

Asked:

on 25 Aug 2023

Commented:

on 28 Aug 2023

Community Treasure Hunt

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

Start Hunting!