Running function in parallel on App Designer
조회 수: 32 (최근 30일)
이전 댓글 표시
Hello,
I'm building an app which suppose to capture images from the camera while doing more things in parallel. I'm using 'parfeval' to run the function in the background and 'afterEach' to print it every time an image is captured.
Those are the functions:
methods (Access = private)
function getFrameFromCamera(app)
h = msgbox("Connecting to camera..", "Message");
app.Cam = gigecam(app.ip);
app.Cam.PixelFormat = 'BayerGB8';
app.Cam.Timeout = 15;
app.Cam.GevSCPSPacketSize = 1200;
app.Cam.Width = 1920;
app.Cam.Height = 1080;
app.Cam.CenterX = 'True';
app.Cam.CenterY = 'True';
delete(h);
while true
app.tmpImage = snapshot(app.Cam);
send(app.D, app);
end
end
function processDisp(app)
app.Image3.ImageSource = app.tmpImage;
end
end
The code in the button's function:
function ConnectButtonPushed(app, event)
app.ConnectedLamp.Color = 'yellow';
pause(0.05);
try
if ~isempty(app.CameraIPListBox.Value)
h = msgbox("Checking if the camera is available..", "Message");
app.ip = app.CameraIPListBox.Value;
gigecam(app.ip);
delete(h);
h = msgbox("Starting parallel pool (parpool) using the 'local' profile..", "Message");
imaqreset;
delete(gcp('nocreate'));
parpool('local', 1);
app.D = parallel.pool.DataQueue;
afterEach(app.D, @processDisp);
%app.Process = 0;
delete(h);
app.f = parfeval(@getFrameFromCamera, 0, app);
app.ConnectedLamp.Color = 'green';
end
catch
delete(h);
app.ConnectedLamp.Color = 'red';
msgbox("The camera is in use.", "Error");
end
end
For some reason, i get this warning twice and the functions don't excecute:
Warning: Unable to save App Designer app object. Save not supported for matlab.apps.AppBase objects
I tried to run in the background simple functions which only print and i still get the same results. I also tried to send every variable seperatly, and not the "app" variable - same results. Any idea how to solve this?
댓글 수: 4
Mario Malic
2021년 3월 29일
Interesting. It's great that it works! It would be great if you could share the code as an answer, as I'm also interested in this.
답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 MATLAB Support Package for IP Cameras에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!