How to use imaqtool functions such as "trigger" "getdata" in "spmd" "batch" structures (parallel toolbox) ?

1 view (last 30 days)
I am making a MATLAB GUI which acquires images from a camera (using imaqtool) and post-processes them.
To reduce the time taken by the acquisition and the transfer to my CPU (getdata), I would like to multithread between my postprocessing and the acquisition, hence removing the delay trigger->acquisition->getdata and creating a (circular) buffer with the images ready for the postprocessing. The idea is to postprocess whilst the images are made available to my CPU.
However, it doesn't work.
delete(gcp('nocreate'))
parpool(2)
vid = videoinput('gentl', 1, 'Mono8');
src = getselectedsource(vid);
triggerconfig(vid, 'manual');
vid.TriggerRepeat=Inf;
start(vid)
trigger(vid)
Image=mean((getdata(vid)),4,'native');
spmd
switch labindex
case 1
trigger(vid)
A=getdata(vid);
Image=mean((getdata(vid)),4,'native');
case 2
postprocessing
end
end
here is the error message I get:
Warning: An error occurred when running a class's loadobj method. The object that was loaded from the MAT-file was a copy of the object before the loadobj method was run. The rest of the variables were also loaded from the MAT-file.
The encountered error was:
Undefined function or variable 'out'.
> In parallel.internal.pool.deserialize (line 33)
In parallel.internal.pool.deserializeFunction (line 17)
In spmdlang.remoteBlockExecution>iDeserializeInputs (line 176)
In spmdlang.remoteBlockExecution>iPrelude (line 119)
In spmdlang.remoteBlockExecution (line 36)
Lab 2:
Warning: An error occurred when running a class's loadobj method. The object that was loaded from the MAT-file was a copy of the object before the loadobj method was run. The rest of the variables were also loaded from the MAT-file.
The encountered error was:
Undefined function or variable 'out'.
> In parallel.internal.pool.deserialize (line 33)
In parallel.internal.pool.deserializeFunction (line 17)
In spmdlang.remoteBlockExecution>iDeserializeInputs (line 176)
In spmdlang.remoteBlockExecution>iPrelude (line 119)
In spmdlang.remoteBlockExecution (line 36)
Error using Untitled2 (line 162)
Error detected on worker 1.
Caused by:
Error using Untitled2 (line 162)
An UndefinedFunction error was thrown on the workers for 'trigger'. This may be because the file containing 'trigger' is not accessible on the workers. Specify the required files for this parallel pool using the command:
addAttachedFiles(pool, ...). See the documentation for parpool for more details.
Undefined function 'trigger' for input arguments of type 'struct'.
Additionally, I tried to use the batch function in the same way but without success with something similar to:
vid = videoinput('gentl', 1, 'Mono8');
src = getselectedsource(vid);
triggerconfig(vid, 'manual');
vid.TriggerRepeat=Inf;
start(vid)
ite=0;
while condition==0
if ite==0
trigger(vid)
wait(vid,100,'logging')
Image=mean((getdata(vid)),4,'native');
ite=1;
job=batch('Batch_Camera_Acquisition');
elseif ite==1
wait(job)
load(job,'Image')
job=batch('Batch_Camera_Acquisition');
end
postprocessing
end
%%
% Batch_Camera_Acquisition.m
% trigger(vid)
% wait(vid,100,'logging')
% Image=mean((getdata(vid)),4,'native');
I have a Processor AMD Ryzen Threadripper 2950X 16-Core Processor, 3500 Mhz, 16 Core(s), 32 Logical Processor(s)
Any help would be appreciated,
Thanks

Accepted Answer

Tutu
Tutu on 25 Jul 2019
Use 'FramesAcquiredFcn' and 'parfeval'
see example here: https://uk.mathworks.com/matlabcentral/answers/350044-how-can-i-simultaneously-acquire-images-and-save-them-to-disk-as-tiff-files

More Answers (0)

Community Treasure Hunt

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

Start Hunting!