Using getsnapshot in parfor function

1 visualizzazione (ultimi 30 giorni)
sle
sle il 3 Dic 2015
Hello all,
I am trying to run this following code in parallel but got this error:
Error using realTime_pointGrey>(parfor body) (line 52)
An UndefinedFunction error was thrown on the workers for 'getsnapshot'. This might be because the file containing 'getsnapshot' is not accessible on the workers. Use
addAttachedFiles(pool, files) to specify the required files to be attached. See the documentation for 'parallel.Pool/addAttachedFiles' for more details.
Error in realTime_pointGrey (line 50)
parfor id = 1:4
Caused by:
Undefined function 'getsnapshot' for input arguments of type 'struct'.
I am not very familiar with using addAttachedFiles, could you please help me?
The code I am working on:
parfor id = 1:4
% Get the snapshot of the current frame
data(:,id) = reshape(double(rgb2gray(getsnapshot(vid))),size(data0,1)*size(data0,2),1);
end
data_mean = mean(data,2);

Risposta accettata

Edric Ellis
Edric Ellis il 3 Dic 2015
This error appears to be misleading - I think the problem is that the object vid is not being transferred to the workers correctly. You could confirm this like so
class(vid) % class on the client
spmd
class(vid) % class on the workers
end
If that isn't the same thing (and I strongly suspect it isn't), then what you need to do is create vid on the workers. In other words, I would first try
spmd
vid = <create 'vid'>;
getsnapshot(vid);
end
If that works, then one approach you might take to working with vid is to use parallel.pool.Constant as described here. (Or Worker Object Wrapper for older MATLAB releases).
  1 Commento
Walter Roberson
Walter Roberson il 3 Dic 2015
Though again, if you do manage to transfer the same vid into all workers, the order the different workers take the snapshot is not predetermined.

Accedi per commentare.

Più risposte (1)

Walter Roberson
Walter Roberson il 3 Dic 2015
If I understand correctly, the parallel workers do not have access to the image hardware devices.
With the code you posted, imagine that the workers did have access to the image hardware devices. You ask to getsnapshot() of the same video device in each of the workers. The result would, at best, depend upon the order the workers happened to execute in. What were you hoping to be able to do? Are you hoping to import images from several different devices?

Categorie

Scopri di più su Parallel for-Loops (parfor) in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by