Incrementing value in GUI with push button does not work
古いコメントを表示
I am designing a live calibration application. I have a callback in which a live preview of the webcam is presented and a callback of a pushbutton of which I want to track the amount of times the button was pressed (n). This pushbutton is only accessible if the correct information was obtained of the frame of the image.
My n is defined in the opening function as follows:
% --- Executes just before GUI_stage_3 is made visible.
function GUI_stage_3_OpeningFcn(hObject, eventdata, handles, varargin)
handles.output = hObject;
handles.n=0;
disp("start");
handles.camera=webcam(1);
handles.minArea =2; handles.maxArea = 14000;
handles.calib=[];
handles.output = hObject;
% Update handles structure
guidata(hObject, handles);
My live camera function is:
% --- Executes on button press in start_calib.
function im=start_calib_Callback(hObject1, eventdata, handles)
while true
im=handles.camera.snapshot;
im=rgb2gray(im);
im=im(1:2:end,1:2:end);
image(im);
[success, stats, cnt, id0, id1, searchPoints] = gridextractor(im, 1, handles.minArea, handles.maxArea);
drawnow;
if success==1
disp('succes')
%varargout{1}=success;
set(handles.take_calib_im,'visible','on')
else
set(handles.take_calib_im,'visible','off')
end
handles.im=im;
guidata(hObject, handles);
end
And my pushbutton function is:
% --- Executes on button press in take_calib_im.
function take_calib_im_Callback(hObject, eventdata, handles)
handles.n=handles.n+1;
disp(handles.n)
guidata(hObject, handles);
The problem is that the value of n seems to reset randomly. For example, my workspace displays '1 2 3 1 1 1 2'.
I just can't figure out why this random resetting of my n value is happening. When I try to build an example with only a pushbutton it just works fine.
採用された回答
その他の回答 (0 件)
カテゴリ
ヘルプ センター および File Exchange で Desktop についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!