Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

gui timer error problem

2 Ansichten (letzte 30 Tage)
tsai kai shung
tsai kai shung am 31 Okt. 2017
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
if true
 function frameshow_Callback(hObject, eventdata, handles)
global t  %%%%顏色辨識timer
global t1
t1=timer('TimerFcn',{@timerCallback1,handles},'ExecutionMode', 'fixedDelay','Period', 0.1);
guidata(hObject,handles);
stop(t);
start(t1);
function timerCallback1(hObject, eventdata, handles)
global vid
global t1
global frame
 if (vid==-1)
    msgbox('請首先進行預覽!');
    stop(t1);
    return;
end
axes(handles.axesshow);
frame=getsnapshot(vid);
imshow(frame);
  end
if true
  % function shapedetect_Callback(hObject, eventdata, handles)
global t
global t1
t=timer('TimerFcn',{@timerCallback2,handles},'ExecutionMode', 'fixedDelay','Period', 0.1);
guidata(hObject,handles);
stop(t1);
start(t);
function timerCallback2(hObject, eventdata, handles)
global vid
global t
global frame
global c
if (vid==-1)
  msgbox('請首先進行預覽!');
  stop(t);
  return;
end
frame=getsnapshot(vid);
i_gray = rgb2gray(frame);
level = graythresh(i_gray);
i_bw = im2bw(i_gray,level);
bw_edge = edge(i_bw,'canny');
boundary=bwboundaries(bw_edge,'noholes');
boundary = boundary{1};%取陣列裡的值
boundaryx=boundary(:,2);
boundaryy=boundary(:,1);
centroid=[(max(boundaryx)+min(boundaryx))/2 (max(boundaryy)+min(boundaryy))/2];
boundaryx=boundaryx-centroid(1);
boundaryy=boundaryy-centroid(2);
% ==================x - y => theta - rho極座標轉換=========================
[theta,rho]=cart2pol(boundaryx,boundaryy);
B =[theta*180/pi rho];
r=sortrows([theta*180/pi rho]);
[~,idx]=min(r(:,2));
if idx>1
  r=[r(idx:end,:);r(1:idx-1,1)+360 r(1:idx-1,2)];
end
theta=B(:,1);
rho=r(:,2)/max(rho);
 %======================================判斷形狀=================================================
 if min(rho)>.7
    set(handles.text2,'string','circle');  
else
    % find peak numbers
    peak_num=length(findpeaks(r(round(linspace(1,length(theta),min([length(theta) 32]))),2)));
    switch peak_num
        case 3
            set(handles.text2,'string','triangle');
        case 4
            set(handles.text2,'string','rectangle');
        otherwise
            set(handles.text2,'string','unkonwshape');
    end
end
axes(handles.axesshow);
imshow(bw_edge);
  end
why i can run on the guide In operation show Error while evaluating TimerFcn for timer timer-160 

Antworten (0)

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!