why i can't show image in axes in serial callback

1 view (last 30 days)
i need your help! i'm a newbie
i can't show image in axes by: axes(handles.axes1); imshow('image.jpg');
my Guide have 2 axes and 2 pushbutton.
my code:
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)
global s
s = serial('COM1','Baudrate',9600,'DataBits',8,'Parity','none','StopBits',1);
s.BytesAvailableFcnCount = 1;
s.Timeout = 1;
s.BytesAvailableFcnMode = 'byte';
s.BytesAvailableFcn = @Serial_Callback;
try
fopen(s);
catch err;
if (strcmp(err.identifier,'MATLAB:serial:fopen:opfailed'))
msgbox('Open COMport fail!!! Please try again!','Error','error');
end
end
% --- Executes on button press in pushbutton2.
function Serial_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)
global video hinh s I J K a S P;
video = videoinput('winvideo',2);
hinh = getsnapshot(video);
imwrite(hinh,'anh.jpg');
a = imread('anh.jpg');
axes(handles.axes1);
imshow(a);
J = rgb2gray(a);
J = imadjust(J);
K = im2bw(J,0.7);
K = imfill(K,'hole');
K = bwareaopen(K,2500);
axes(handles.axes2);
imshow(K);
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)
global s;
fclose(s);
close;
Error: Error using feval Undefined function 'figure1_CreateFcn' for input arguments of type 'double'.
Error in gui_mainfcn (line 96) feval(varargin{:});
Error in doan (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)doan('figure1_CreateFcn',hObject,eventdata,guidata(hObject))
Error using struct2handle Error while evaluating figure CreateFcn
Error using doan>pushbutton2_Callback (line 107) Not enough input arguments.
Error in instrcb (line 36) feval(val{1}, obj, eventStruct, val{2:end});
Warning: The BytesAvailableFcn is being disabled. To enable the callback property either connect to the hardware with FOPEN or set the BytesAvailableFcn property.
Error using edit (line 66) Undefined function or variable 'hObject'.
Error in helpUtils.errorDocCallback (line 23) if ~edit(editTopic)

Answers (1)

Jan
Jan on 26 Mar 2017
"Undefined function 'figure1_CreateFcn'" sounds like you have renamed the GUI after the creation.
"pushbutton2_Callback (line 107) Not enough input arguments." is a serious problem, but without seeing the code it is not possible to give an advice.
Error using edit (line 66) Undefined function or variable 'hObject'.
Error in helpUtils.errorDocCallback (line 23) if ~edit(editTopic)
Are you sure that you want to open this is Matlab's editor?
Warning: The BytesAvailableFcn is being disabled.
There is a severe problem with the serial object, when the BytesAvailableFcn does not work. Note that the callback of the seriabl object gets this object as first input. Using a callback of the GUI is not useful and the 3rd input "handles" was not defined.
Summary: This shown and not shown parts of the code contain many problems. Start with focussing one problem after the other.
  2 Comments
amh limh
amh limh on 26 Mar 2017
Line 107: axes(handles.axes1)
How to define handles in serial callback. Help me plz
Walter Roberson
Walter Roberson on 26 Mar 2017
You have to pass the handles object yourself. Safer would be to pass the figure handle and use guidata to grab the current handle structure.

Sign in to comment.

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!