How to use a CNN - classify in a GUI file?
9 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hi all:
I have a .mat file where I call a CNN trained after that I read an image and CNN classifies the image and shows it on the screen, all that works well.
The code is the following:
load myNet.mat
[filename, filepath] = uigetfile ({'*. png'}, 'Select and image');
picture = imread (strcat (filepath, filename));
picture2 = imresize (picture, [227,227]); % Resize the picture
label = classify (myNet, picture2); % Classify the picture
image (picture2); % Show the picture
title (char (label)); % Show the label
drawnow;
clearvars picture picture2
Now I want to make a user interface (GUIDE) and put the same code in several buttons, in a button I have the call to CNN and in another the selection of the image, but where I mark error is in the line:
function pushbutton3_Callback (hObject, eventdata, handles)
% hObject handle to pushbutton3 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
myNet = handles.data;
[nama_file, nama_path] = uigetfile ({'*. png'; '. jpg'; '. tif';}, ...
'Upload image');
if ~ isequal (nama_file, 0)
handles.data1 = imread (fullfile (nama_path, nama_file));
guidata (hObject, handles);
axes (handles.axes1);
imshow (handles.data1);
title ('Test image');
handles.img = handles.data1;
picture = handles.data1;
picture2 = imresize (picture, [227,227]); % Resize the picture
label = classify (myNet, picture2); % Classify the picture
handles.text1.String = label; % Do it like this instead of using set ()
clearvars picture picture2
else
return
end
The line:
label = classify (myNet, picture2); % Classify the picture
It marks me the following errors:
* ------------------------------------------------- --------------
Error using classify (line 123)
Requires at least three arguments.
Error in apif> pushbutton3_Callback (line 152)
label = classify (myNet, picture2); % Classify the picture
Error in gui_mainfcn (line 95)
feval (varargin {:});
Error in apif (line 42)
gui_mainfcn (gui_State, varargin {:});
Error in
matlab.graphics.internal.figfile.FigFile / read> @ (hObject, eventdata) apif ('pushbutton3_Callback', hObject, eventdata, guidata (hObject))
Error while evaluating UIControl Callback.
* ------------------------------------------------- --------------
Any idea what I'm doing wrong?
Thanks for your answers and regards
attentively
Angel
Antworten (0)
Siehe auch
Kategorien
Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!