GUI Matrix dimensions must agree.
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
tsai kai shung
am 31 Okt. 2017
Kommentiert: Walter Roberson
am 31 Okt. 2017
function numberdetect_Callback(hObject, eventdata, handles)
global t
global t1
t=timer('TimerFcn',{@timerCallback3,handles},'ExecutionMode', 'fixedDelay','Period', 0.1);
guidata(hObject,handles);
stop(t1);
start(t);
function timerCallback3(hObject, eventdata, handles)
global vid
global t
global frame
global c
if (vid==-1)
msgbox('請首先進行預覽!');
stop(t);
return;
end
frame=getsnapshot(vid);
imagen = rgb2gray(frame);
threshold = graythresh(imagen);
i_bw = ~im2bw(imagen,threshold);
i_bw2 = bwareaopen(i_bw,30);
i_bw3 = imclearborder(i_bw2);
re=i_bw3;
load templates
[fl re]=lines(re);
imgn=fl;
[L Ne] = bwlabel(imgn);
word = [];
for n=1:Ne
[r,d] = find(L==n);
n1=imgn(min(r):max(r),min(d):max(d));
img_r=imresize(n1,[42 24]);
comp=[];
for n=1: 24 : 240
sem=Corr2(templates(1:42,n:n+23),img_r);
comp=[comp sem];
end
vd=find(comp==max(comp));
%*-*-*-*-*-*-*-*-*-*-*-*-*-
if vd==1
letter='1';
elseif vd==2
letter='2';
elseif vd==3
letter='3';
elseif vd==4
letter='4';
elseif vd==5
letter='5';
elseif vd==6
letter='6';
elseif vd==7
letter='7';
elseif vd==8
letter='8';
elseif vd==9
letter='9';
else
letter='0';
end
word = [word letter];
end
if word == '40'
set(handles.text2,'string','40');
else
set(handles.text2,'string','no');
end
axes(handles.axesshow);
imshow(imagen);
end
function r = Corr2(A,B)
A = A - mean2(A);
B = B - mean2(B);
r = sum(sum(A.*B))/sqrt(sum(sum(A.*A))*sum(sum(B.*B)));
function [fl re]=lines(im_texto)
im_texto=clip(im_texto);
fl=im_texto;%Only one line.
re=[ ];
function img_out=clip(img_in)
[f c]=find(img_in);
img_out=img_in(min(f):max(f),min(c):max(c));%Crops image
I am use this function on guide but show the error: Matrix dimensions must agree.
0 Kommentare
Akzeptierte Antwort
Walter Roberson
am 31 Okt. 2017
You have
if word == '40'
Do not use "==" to compare character vectors. == does element-by-element comparison, word(1) compared to the first character of '40', word(2) compared to the second character of '40', word(3) compared to ... error, there is no third character of '40' .
You should use strcmp() to compare anything that is not known for certain to be a single character.
6 Kommentare
Walter Roberson
am 31 Okt. 2017
if strcmp(word, '40')
set(handles.text2,'string','40')
else
set(handles.text2,'string','error');
end
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu 迁移使用 GUIDE 创建的 App finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!