How can I connect my self written code with an the Matlab App Designer?

2 views (last 30 days)
Hello,
I am trying to create a platform where the user can click on the button and after doing so the program (my self written code) will run.
Right now it opens the camera but as it doesn't analyze anything I assume there is no connection between the code and the button.
How can I establish the connection between them?
In %Button pushed function: Button, I tried to implement my code for hand detection with my network, but nothing is working.
Thanks for any help.
% Callbacks that handle component events
methods (Access = private)
% Button pushed function: StartButton
function StartButtonPushed(app, event)
c = webcam("Webcam(X1-HTL)");
frame = snapshot(c);
im = image(app.UIAxes,zeros(size(frame),'uint8'));
axis(app.UIAxes,'image');
preview(c,im);
pause;
end
% Button pushed function: StopButton
function StopButtonPushed(app, event)
d= webcam("Webcam(X1-HTL)");
frame = snapshot(d);
im = image(app.UIAxes,zeros(size(frame),'uint8'));
axis(app.UIAxes,'image');
closepreview;
pause;
end
% Button pushed function: Button
function ButtonPushed(app, event)
a = webcam('Webcam(X1-HTL)');
frame = snapshot(a);
Handbox=[0 0 400 400];
while true
video = a.snapshot;
load Netzwerk.mat;
%Video RGB to gray
video_grey = rgb2gray(video);
videoAdj = imadjust(video_grey);
%Video RGB to BW
BW = imbinarize(videoAdj);
%Fill holes
BW_IH = imfill(BW, 'holes');
%change format [x x 1] --> [x x 3] and uint8
BW_3D = cat(3,BW_IH,BW_IH,BW_IH);
format = im2uint8(BW_3D);
%Create Handbox
Handbox_new = insertObjectAnnotation(video,'rectangle',Handbox,'Handgeste');
Handbox_crop = imcrop(format,Handbox);
video_new = imresize(Handbox_crop, [227 227]);
%classify
label=classify(Netzwerk,video_new);
im = image(app.UIAxes,zeros(size(frame),'uint8'));
axis(app.UIAxes,'image');
preview(a,im)
% title(char(label));
drawnow;
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!