Error while evaluating TimerFcn for timer 'timer'
10 ビュー (過去 30 日間)
古いコメントを表示
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);
endif 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','圓形');
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','三角形');
case 4
set(handles.text2,'string','矩形');
otherwise
set(handles.text2,'string','unkonwshape');
end
end
axes(handles.axesshow);
imshow(bw_edge);
end
1 件のコメント
Steven Lord
2017 年 10 月 31 日
What is the full text of the error message (everything displayed in red)?
回答 (0 件)
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!