How do I make the GUI executable
4 次查看(过去 30 天)
显示 更早的评论
Hi guys,
What I want to ask is the general code can’t be put into the GUI, because the above code can run without GUI code, but once the GUI is added, it will be like this.
The code is related to deep learning. I want to change the part that shows the numbers to the actions I have learned. I hope that the part of the result is the action instead of the number. But I have encountered this problem so I replaced it with a number. I am still a beginner Hope everyone can help me.


采纳的回答
Image Analyst
2020-12-5
The network called "netTransfer" needs to be in scope. It is not. You need to make sure netTransfer is in the workspace of the function or script where you're calling classify().
92 个评论
Dong Yi
2020-12-5
x is the action given by my deep learning. My goal is to add this piece of code to the GUI to become executable and take out the x worth action and display it in the GUI.
Image Analyst
2020-12-5
Put these lines before the classify() line:
whos d
whos netTransfer
What does it show in the command window?
Walter Roberson
2020-12-5
Walter Roberson
2020-12-5
Your GUI will load the network at some point during its initialization. Have your GUI store the network in the handles structure, and use guidata() to update the master copy of the handle structure.
Then inside your function that needs to use the network to classify a sound, then pull the stored network out of the handle structure.
Quoting the relevant guidance from the FAQ, from near the very top of the section pointed to:
The main techniques are:
- Using the handles structure. You can dynamically add on new members to the handles structure that contain your variables that you want to pass in. Unlike global variables, which expose the variables only where you put the global statement, attaching to the handles structure and passing handles will share all the variables you have attached to the handles structure. This could expose variables to your function that you did not need or want exposed. Since variables passed in to MATLAB functions are "pass by value" and not "pass by reference" if you change any of the variables, you are only changing the local copy. If you change any of the variables attached as members of the handle structure, and you want to retain these changed values in the calling function, you will have to return the handles structure as an output of your function, and accept it in your calling function, or else use the guidata() function. Otherwise changes you make to the handles structure variables are only local and will not survive once the function has returned.
Walter Roberson
2020-12-5
function GUI2_Openfcn(hObject, event, handles)
filestruct = load('FileWithNetwork.mat');
handles.netTransfer = filestruct.netTransfer;
guidata(hObject, handles);
end
function pushbutton1_callback(hObject, event, handles)
netTransfer = handles.netTransfer;
now do your stuff
end
Dong Yi
2020-12-5
Thank you, it can be executed. I want to make sure that this kind of real-time code can be recognized immediately and sent the result immediately?
Dong Yi
2020-12-5


The first picture is the result of normal running out without adding the GUI.
The second one is the result of adding the GUI.
Walter Roberson
2020-12-5
I suggest changing
cc = imread(pic);
to
if ~exist(pic, 'file'); continue; end %skip unavailable files
As for the problem with axes:
When you use imshow() and the current axes occupies the entire default axes area for the figure, then imshow() deletes the axes and recreates it, unless "hold" is on for the axes.
I recommend against using imshow() inside a GUI; I recommend that you only use imshow() for quick exploration of images when you do not care about making a GUI.
Dong Yi
2020-12-5
Or I can set another button to execute the mat file. If it can, I want to know why there is no x, y value.

Image Analyst
2020-12-5
编辑:Image Analyst
2020-12-5
When you say "there is no x, y value", are you saying that after the loop, x and y are still empty? If so you need to follow normal, typical debugging steps, like setting a breakpoint on the classify() line and see if scores returns anything or if it is also null. If x and y are null, and either scores is null or you did not execute the call to classify, then they'll be null after the loop also.
And the for loop you should have this:
for k = 1 : zz
baseFileName = sprintf('%012d_rendered.png', k);
fullFileName = fullfile(pwd, baseFileName);
if ~isfile(fullFileName)
continue; % No such file exists by this name.
end
rgbImage = imread(fullFileName);
% Needs to be color for AlexNet.
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels == 1
% It's gray scale but needs to be color for AlexNet
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
end
% Needs to be 227x227 for AlexNet, so resize it.
resizedImage = imresize(rgbImage, [227, 227]);
[YPred, scores] = classify(handles.netTransfer, resizedImage);
x = [x; scores(:)];
y = [y; scored(:)]; % Why are x and y the same??????
end
Dong Yi
2020-12-5
sorry x is YPred.
But I have typed in the last line
set(handles.text2,'String','ok');
The result also shows OK. Doesn’t it mean that the entire code has been run?
Sorry that my English is not very good, I am also a beginner to MATLAB, please forgive me.
Dong Yi
2020-12-6
It can be executed but there is still no x value in the workspace.
My ideal gui is to run through all the pictures in the folder and display the recognition results, just like the principle of turning a book.
Walter Roberson
2020-12-6
Please post code instead of images of code. I am not going to type in all of your code by hand just to show you a change.
Dong Yi
2020-12-6
编辑:Dong Yi
2020-12-6
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)
netTransfer = handles.netTransfer;
zz=659;
x=[];
y=[];
for k = 1 : zz
baseFileName = sprintf('%012d_rendered.png', k);
fullFileName = fullfile(pwd,baseFileName);
if ~isfile(fullFileName)
continue; % No such file exists by this name.
end
rgbImage = imread(fullFileName);
% Needs to be color for AlexNet.
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels == 1
% It's gray scale but needs to be color for AlexNet
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
end
% Needs to be 227x227 for AlexNet, so resize it.
resizedImage = imresize(rgbImage, [227, 227]);
[YPred, scores] = classify(handles.netTransfer, resizedImage);
x = [x; YPred(:)];
y = [y; scores(:)];
end
Dong Yi
2020-12-6
function varargout = GUI2(varargin)
% GUI2 MATLAB code for GUI2.fig
% GUI2, by itself, creates a new GUI2 or raises the existing
% singleton*.
%
% H = GUI2 returns the handle to a new GUI2 or the handle to
% the existing singleton*.
%
% GUI2('CALLBACK',hObject,eventData,handles,...) calls the local
% function named CALLBACK in GUI2.M with the given input arguments.
%
% GUI2('Property','Value',...) creates a new GUI2 or raises the
% existing singleton*. Starting from the left, property value pairs are
% applied to the GUI before GUI2_OpeningFcn gets called. An
% unrecognized property name or invalid value makes property application
% stop. All inputs are passed to GUI2_OpeningFcn via varargin.
%
% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one
% instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES
% Edit the above text to modify the response to help GUI2
% Last Modified by GUIDE v2.5 05-Dec-2020 17:13:11
% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name', mfilename, ...
'gui_Singleton', gui_Singleton, ...
'gui_OpeningFcn', @GUI2_OpeningFcn, ...
'gui_OutputFcn', @GUI2_OutputFcn, ...
'gui_LayoutFcn', [] , ...
'gui_Callback', []);
if nargin && ischar(varargin{1})
gui_State.gui_Callback = str2func(varargin{1});
end
if nargout
[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT
% --- Executes just before GUI2 is made visible.
function GUI2_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% varargin command line arguments to GUI2 (see VARARGIN)
% Choose default command line output for GUI2
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
% UIWAIT makes GUI2 wait for user response (see UIRESUME)
% uiwait(handles.figure1);
% --- Outputs from this function are returned to the command line.
filestruct = load('matlab.mat');
handles.netTransfer = filestruct.netTransfer;
guidata(hObject, handles);
function varargout = GUI2_OutputFcn(hObject, eventdata, handles)
% varargout cell array for returning output args (see VARARGOUT);
% hObject handle to figure
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Get default command line output from handles structure
varargout{1} = handles.output;
% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
netTransfer = handles.netTransfer;
xx=1000;
x=[];
y=[];
for ii=1:659
pic=sprintf('%012d_rendered.png',ii)
cc = imread(pic);
d = imresize(cc,[227, 227]);
[YPred,scores] = classify(netTransfer,d);
x=[x;YPred];
axes(handles.axes1);
imshow(cc);
set(handles.text2,'String',ii);
pause(0.087);
end
% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% --- Executes on button press in pushbutton3.
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)
netTransfer = handles.netTransfer;
zz=659;
x=[];
y=[];
for k = 1 : zz
baseFileName = sprintf('%012d_rendered.png', k);
fullFileName = fullfile(pwd,baseFileName);
if ~isfile(fullFileName)
continue; % No such file exists by this name.
end
rgbImage = imread(fullFileName);
% Needs to be color for AlexNet.
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels == 1
% It's gray scale but needs to be color for AlexNet
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
end
% Needs to be 227x227 for AlexNet, so resize it.
resizedImage = imresize(rgbImage, [227, 227]);
[YPred, scores] = classify(handles.netTransfer, resizedImage);
x = [x; YPred];
y = [y; scores(:)];
end
set(handles.text2,'String','LOAD');
Walter Roberson
2020-12-6
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)
netTransfer = handles.netTransfer;
zz=659;
x=[];
y=[];
number_loaded = 0;
filenames_used = {};
for k = 1 : zz
baseFileName = sprintf('%012d_rendered.png', k);
fullFileName = fullfile(pwd,baseFileName);
if ~isfile(fullFileName)
continue; % No such file exists by this name.
end
rgbImage = imread(fullFileName);
number_loaded = number_loaded + 1;
% Needs to be color for AlexNet.
[rows, columns, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels == 1
% It's gray scale but needs to be color for AlexNet
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
end
% Needs to be 227x227 for AlexNet, so resize it.
resizedImage = imresize(rgbImage, [227, 227]);
[YPred, scores] = classify(handles.netTransfer, resizedImage);
x = [x; YPred(:)];
y = [y; scores(:)];
filenames_used{number_loaded} = baseFileName;
end
handles.x = x;
handles.y = y;
handles.filenames_used = filenames_used;
guidata(handles);
if number_loaded == 0
fprintf('No appropriate files found in current directory\n');
else
fprintf('%d files found in current directory\n', number_loaded)
end
Image Analyst
2020-12-6
Somehow "handles" got blown away before you clicked pushbutton3. Can you search your code and see if there is a "clear" or "clearvars" anywhere in your code? Otherwise, attach your latest m-file and fig file and a few PNG files and any mat file that is needed and I'll try to run it.
Dong Yi
2020-12-6
- GUI2.fig
- GUI2.m
- 000000000000_rendered.png
- 000000000001_rendered.png
- 000000000002_rendered.png
- 000000000003_rendered.png
- 000000000004_rendered.png
- 000000000005_rendered.png
- 000000000006_rendered.png
- 000000000007_rendered.png
- 000000000008_rendered.png
- 000000000009_rendered.png
- 000000000010_rendered.png
- 000000000011_rendered.png
- 000000000012_rendered.png
- 000000000013_rendered.png
- 000000000014_rendered.png
- 000000000015_rendered.png
- 000000000016_rendered.png
- 000000000017_rendered.png
- 000000000018_rendered.png
- 000000000019_rendered.png
- 000000000020_rendered.png
- 000000000021_rendered.png
- 000000000022_rendered.png
- 000000000023_rendered.png
- 000000000024_rendered.png
- 000000000025_rendered.png
- 000000000026_rendered.png
- 000000000027_rendered.png
- 000000000028_rendered.png
- 000000000029_rendered.png
- 000000000030_rendered.png
- 000000000031_rendered.png
- 000000000032_rendered.png
- 000000000033_rendered.png
- 000000000034_rendered.png
- 000000000035_rendered.png
- 000000000036_rendered.png
- 000000000037_rendered.png
- 000000000038_rendered.png
- 000000000039_rendered.png
- 000000000040_rendered.png
- 000000000041_rendered.png
- 000000000042_rendered.png
- 000000000043_rendered.png
- 000000000044_rendered.png
- 000000000045_rendered.png
- 000000000046_rendered.png
- 000000000047_rendered.png
- 000000000048_rendered.png
- 000000000049_rendered.png
- 000000000050_rendered.png
- 000000000051_rendered.png
- 000000000052_rendered.png
- 000000000053_rendered.png
- 000000000054_rendered.png
- 000000000055_rendered.png
- 000000000056_rendered.png
- 000000000057_rendered.png
- 000000000058_rendered.png
- 000000000059_rendered.png
- 000000000060_rendered.png
- 000000000061_rendered.png
- 000000000062_rendered.png
- 000000000063_rendered.png
- 000000000064_rendered.png
- 000000000065_rendered.png
- 000000000066_rendered.png
- 000000000067_rendered.png
- 000000000068_rendered.png
- 000000000069_rendered.png
- 000000000070_rendered.png
- 000000000071_rendered.png
- 000000000072_rendered.png
- 000000000073_rendered.png
- 000000000074_rendered.png
- 000000000075_rendered.png
- 000000000076_rendered.png
- 000000000077_rendered.png
- 000000000078_rendered.png
- 000000000079_rendered.png
- 000000000080_rendered.png
- 000000000081_rendered.png
- 000000000082_rendered.png
- 000000000083_rendered.png
- 000000000084_rendered.png
- 000000000085_rendered.png
- 000000000086_rendered.png
- 000000000087_rendered.png
- 000000000088_rendered.png
- 000000000089_rendered.png
- 000000000090_rendered.png
- 000000000091_rendered.png
- 000000000092_rendered.png
- 000000000093_rendered.png
- 000000000094_rendered.png
- 000000000095_rendered.png
- 000000000096_rendered.png
- 000000000097_rendered.png
- 000000000098_rendered.png
Not pass too much at once
Walter Roberson
2020-12-8
I know there are some file distribution sites he cannot access for work security reasons, but I do not know which they are. He suggested OneDrive or GoogleDrive, so we can be sure you can access those.
Walter Roberson
2020-12-9
Unfortunately, we cannot load that .mat file without the 14000 png files in C:\Users\User\Desktop\test\handdown\ (and we have to place them in that exact directory.) However, I suspect we do not need that part of the .mat file so we can possibly ignore that.
Walter Roberson
2020-12-9
Okay, so what problem are we trying to solve now, after the fix I posted above
guidata(hObject, handles);
?
I ran the code and I do not see any obvious problems.
I do recommend that you save only the netTransfer in the .mat file you load, or else that you change the load() to only load the netTransfer variable out of the file. But that is an efficiency matter, not a fundamental problem.
I also recommend that you put a semi-colon on the end of the assignment to 'pic' in pushbutton1_Callback and that you add
if ~exist(pic, 'file'); continue; end;
right after the assignment to pic.
Dong Yi
2020-12-9
I need the x value in the workspace. My GUI result is that when I open openpose, I let the photos in the storage folder show up and perform deep learning, so that the x value can run out of the text.
Walter Roberson
2020-12-9
Which workspace do you need the x value to end up in, and which action needs to trigger it being put there?
You are already saving the x data by using
handles.x = x;
so it is already available for you to work with -- such as if you added another push button to retrieve handles.x and do something with it.
Image Analyst
2020-12-9
Like he suggested simply save the netTransfer in a mat file
save('netTransfer.mat', 'netTransfer');
after you create it, and recall it when you are in the function that needs it
s = load('netTransfer.mat');
netTransfer = s.netTransfer;
Image Analyst
2020-12-9
No of course not. You get Ypred as an output of classify(). And to call classify() you need netTransfer, which is what you get (after you created it and wrote it out to disk) when you call load() to read it in back from disk. Then you're building up x from appending Ypred (at least that's what the code you showed does).
Walter Roberson
2020-12-9
Here is cleaned up code.
It writes the x and y data into the base workspace. For emphasis, it also writes all_YPred into the base workspace -- which is just a copy of x. Just to emphasize that x and the accumulated YPred are the same.
It also writes filenames_used to the base workspace -- because it is meaningless to look at the YPred values without knowing which files they came from.
Walter Roberson
2020-12-9
You need a static text that contains the 264 words that are similar to 'handdown' and 'playphone' ?
Do you have a quite wide display, or should we be programming in a quite small font?
264 words of 9 or 10 characters each (including space between them) is about 2508 letters on average. If you used font size 6 (small but readable with effort) then that would be over 15000 pixels. It is unlikely that your monitor has a display resolution of 15000 pixels wide.
Dong Yi
2020-12-9
When GUI axes show the first picture, my text shows the results of deep learning, similar to the principle of turning books.
Dong Yi
2020-12-9
Thank you. The classify button has achieved my goal. However, the play button will still run out of ERROR.

Walter Roberson
2020-12-9
I do not know what the predictions variable is. That was not a variable name that I put in.
Dong Yi
2020-12-9
I also want to know one thing
Is there a way to combine these two buttons
The result of the GUI is that I immediately took a picture, immediately recognized the action and gave the action result, which means it is instant.
Image Analyst
2020-12-9
Yes, just put all the code for that into the callback function of one button.
Image Analyst
2020-12-9
Evidently predictions(ii) is not a string or character array. What kind of variable is it?
Image Analyst
2020-12-9
It should be a string if you're going to put it into a static text label. To find out what it actually is, look at the classify() documentation or do this:
whos predictions
Walter Roberson
2020-12-9
Put breakpoints at line 154
y = vertcat(y{1:number_loaded});
and at line 97
xx = length(filenames);
When you push Classify it should stop at the first of the breakpoints. Ask it what class(x) is, and then continue running. When you push Play Results it should stop at the second of the breakpoints. Ask it what class(predictions) is and then continue running. Let us know what the results are.
Image Analyst
2020-12-9
OK, but what does it show as the data type for predictions and Ypred in the Workspace panel? Or type this in the command window
>> whos predictions
>> whos YPred
but like I said, they won't be strings or character arrays so you can't assign them to a static text label.
Dong Yi
2020-12-9
编辑:Image Analyst
2020-12-9


But isn't it only static text that can display my results?
Image Analyst
2020-12-9
Correct, unless you just want to see what you have shown above. So you need to figure out how to convert categorical to character array so you can then assign it to the static text label on your GUI. I'm not sure how to do that off the top of my head.
Dong Yi
2020-12-9
Can this part work?
about ""So you need to figure out how to convert categorical to character""?
Walter Roberson
2020-12-9
Use
set(handles.text2,'String', string(predictions(ii)));
You are using R2018a it appears. The conversion to character is handled automatically by R2020b that I tested in.
Dong Yi
2020-12-9
Thank you both for learning a lot. The current problems have been solved. If there are any related questions, I will come up and ask!!!!
Dong Yi
2020-12-10
But can I trouble you?
Although the immediacy method is to synthesize a button, how should I typeset it?
Walter Roberson
2020-12-10
I do not understand the question?
If you are asking about using latex such as
then you cannot do that with a uicontrol text field for a traditional figure (such as used by GUIDE)
If you are asking about setting font size or font name, you can do that by setting the appropriate property for the uicontrol text field, such as
set(handles.text, 'FontSize', 10)
Dong Yi
2020-12-10
Because the result of my current GUI is to shoot a folder with openpose and then play.
What I want to show now is that when I open openpose, I also open my GUI. When openpoes takes a photo, my GUI will immediately read the recognition action, and immediately give the result, an instant effect.
Walter Roberson
2020-12-10
It should be obvious. The classify button reads one image at a time and classifies it and stores one result at a time. The display button reads one image at a time and displays it along with the corresponding result from predictions. It is obvious that you could have the classify button display the image just read along with the classification result for it.
Image Analyst
2020-12-10
Just to be absurdly explicit, it would be something like this:
function pushbutton1_Callback(hObject, eventData, handles)
% Code to read
imread(......)
end
function pushbutton2Callback(hObject, eventData, handles)
% Code to classify
classify(.....)
end
you would now have
function pushbuttonBoth_Callback(hObject, eventData, handles)
% Code to read
imread(......)
% Code to classify
classify(.....)
end
Image Analyst
2020-12-10
That is not a field of handles. You probably forgot to call guidata() right after you tacked on that field in the function wherever you did that.
Dong Yi
2020-12-11
filenames_used(number_loaded+1:end) = [];
x = vertcat(x{1:number_loaded});
y = vertcat(y{1:number_loaded});
handles.x = x;
handles.y = y;
handles.filenames_used = filenames_used;
guidata(hObject, handles);
assignin('base', 'x', x);
assignin('base', 'y', y);
assignin('base', 'all_YPred', x);
assignin('base', 'filenames_used', filenames_used);
if number_loaded == 0
fprintf('No appropriate files found in current directory\n');
else
fprintf('%d files found in current directory\n', number_loaded)
set(handles.pushbutton1, 'enable', 'on')
end
set(handles.text2,'String', 'Please execute');
Do I have to add this paragraph? If I only use a button.
Walter Roberson
2020-12-11
Yes, all of that code is necessary. It is present to deal with your requirement that x must end up in "the workspace". You insisted on that multiple times when we said that did not make sense to do, so you are stuck with it now.
Walter Roberson
2020-12-11
No, that section of code is strictly after the for.
The new things you need to do before the for:
- activate your axes as the place to plot to
The new things you need to do inside your for, after you have classified the current file:
- plot the current data
- set the text field to reflect string() of the result that was just predicted for this file
- pause() to give time for the plot to show up
Dong Yi
2020-12-18
When I have a large number of photos, what is the situation where it cannot be executed?
Dong Yi
2020-12-18
编辑:Dong Yi
2020-12-18
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
netTransfer = handles.netTransfer;
zz = 10000;
x = cell(zz, 1);
y = cell(zz, 1);
number_loaded = 0;
filenames_used = cell(zz,1);
for k = 1 : zz
baseFileName = sprintf('%012d_rendered.png', k);
fullFileName = fullfile(pwd,baseFileName);
if ~isfile(fullFileName)
continue; % No such file exists by this name.
end
rgbImage = imread(fullFileName);
number_loaded = number_loaded + 1;
% Needs to be color for AlexNet.
[~, ~, numberOfColorChannels] = size(rgbImage);
if numberOfColorChannels == 1
% It's gray scale but needs to be color for AlexNet
rgbImage = cat(3, rgbImage, rgbImage, rgbImage);
end
% Needs to be 227x227 for AlexNet, so resize it.
resizedImage = imresize(rgbImage, [227, 227]);
[YPred, scores] = classify(netTransfer, resizedImage);
x{k} = YPred(:);
y{k} = scores(:);
filenames_used{number_loaded} = baseFileName;
end
filenames_used(number_loaded+1:end) = [];
x = vertcat(x{1:number_loaded});
y = vertcat(y{1:number_loaded});
handles.x = x;
handles.y = y;
handles.filenames_used = filenames_used;
guidata(hObject, handles);
assignin('base', 'x', x);
assignin('base', 'y', y);
assignin('base', 'all_YPred', x);
assignin('base', 'filenames_used', filenames_used);
if number_loaded == 0
fprintf('No appropriate files found in current directory\n');
else
fprintf('%d files found in current directory\n', number_loaded)
set(handles.pushbutton1, 'enable', 'on')
end
ax = handles.axes1;
filenames = handles.filenames_used;
predictions = handles.x;
xx = length(filenames);
for ii=1:xx
pic = filenames{ii};
if ~exist(pic, 'file'); continue; end
cc = imread(pic);
imshow(cc, 'Parent', ax);
set(handles.text2,'String', string(predictions(ii)));
set(handles.text3,'String', ii);
pause(0.087);
end
I have tried a lot of sorting but the result is not real-time. If it is executed when openpose takes 100 pictures, he will only read 100 pictures, but my openpose is continuously outputting. How do I let him? Display one after reading one?
It has troubled me for a long time.
Walter Roberson
2020-12-18
When I have a large number of photos, what is the situation where it cannot be executed?
Sorry, I do not understand that question.
Dong Yi
2020-12-18
I have tried a lot of sorting but the result is not real-time. If it is executed when openpose takes 100 pictures, he will only read 100 pictures, but my openpose is continuously outputting. How do I let him? Display one after reading one?
Walter Roberson
2020-12-18
With regards to updating while pictures are being taken: you did not implement any of the logic that was suggested in my response https://www.mathworks.com/matlabcentral/answers/679288-how-do-i-make-the-gui-executable#comment_1196519
You also have not correctly merged the playing code with the prediction code. I already explained what you have to do, in https://www.mathworks.com/matlabcentral/answers/679288-how-do-i-make-the-gui-executable#comment_1200960
I am not eager to implement this all for you as you do not appear to be learning from the steps I tell you to do, and you do not appear to be learning from seeing me implement the steps that I told you to do. The point of you having been assigned this project in the first place was for you to learn how to program: the point was not for you to find someone who would do all of the code for you.
Dong Yi
2020-12-18
编辑:Walter Roberson
2020-12-19
filenames_used{number_loaded} = baseFileName;
filenames_used(k+1:end) = [];
x = vertcat(x{k});
y = vertcat(y{k});
pic=sprintf('%012d_rendered.png',k);
cc = imread(pic);
imshow(cc, 'Parent', ax);
predictions = handles.x;
set(handles.text2,'String', string(predictions(k)));
set(handles.text3,'String', k);
pause(0.087);

Is it because my X value is not read in?
Image Analyst
2020-12-18
No, we discussed this before. It's because you said predictions(k) is a categorical, and evidently a categorical can't be converted to a string. Maybe use a switch statement to check predictions(k) and assign the proper string by hard coding it in.
After 90 comments, I'm about reaching my limit. Like I said before can you call tech support? You said you could/would. Trust me, they have people there who can speak English, Chinese, Hindi, and lots of other languages, even if you call the USA office in Natick. I'm sure you'll be able to communicate with them in your native language.
Walter Roberson
2020-12-19
You have
x = vertcat(x{k});
but you
predictions = handles.x;
and you had not updated handles.x between those two. So you are not using the most recently calculated predictions; you are using whatever happened to be in handles.x .
更多回答(0 个)
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Environment and Settings 的更多信息
标签
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!发生错误
由于页面发生更改,无法完成操作。请重新加载页面以查看其更新后的状态。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom(English)
亚太
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)










