Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
4.4k views
in Technique[技术] by (71.8m points)

matlab cvst - boundary error of image processing Index exceeds matrix dimensions. error

The name of the fruit captured by the camera. Dimensional analysis and color analysis were done. I can't get results due to error. I run a code and "Index exceeds matrix dimensions" appears as an error but I don't understand why.

Index exceeds matrix dimensions.

Error in tolgaile (line 69) text(boundary(1,2)-35,boundary(1,1)+13,metric_string,'color','y', ...

enter image description here

video=videoinput('winvideo',1);
preview(video);
yakalanangoruntu=getsnapshot(video);
image(yakalanangoruntu);
figure(1),imshow(yakalanangoruntu);
imagegray=rgb2gray(yakalanangoruntu);
figure(2), imshow(imagegray);

level=graythresh(imagegray);

bw=im2bw(imagegray,0.48);
figure(3),imshow(bw);

bw=bwareaopen(bw,30);
figure(8), imshow(bw);

se=strel('disk',10);
bw=imclose(bw,se);
figure(4),imshow(bw);

bw=imfill(bw,'holes');
figure(5), imshow(bw);

[B,L]= bwboundaries(bw,'noholes'),disp(B)
figure(6), imshow(label2rgb(L,@jet,[.5 .5 .5]))


hold on


for k=1:length(B)
boundary= B(k);
plot(boundary{1}(:,2),boundary{1}(:,1),'w','LineWidth', 2) % Orijinal gri tonlamal? goruntu uzerindeki siniri yazilan aral?klarla cizilir
end

fprintf('Nesneler i?aretlenmi?tir. Toplam Nesne Say?s?=&d
',k)
stats =regionprops(L,'Area','Centroid');

for k=1:length(B)

boundary=B(k);

delta_aq = diff('B(k)') .^2;
perimeter = sum(sqrt(sum(delta_aq,2) ) );

area = stats(k) .Area ;

metric = 4*pi*area/perimeter^2;

metric_string = sprintf ('%2.2f',metric);
centroid = stats(k) .Centroid;
'FillColor', 'Custom', ...
if metric > 0.9344
text(centroid(1),centroid(2),'?ember');

elseif (metric <= 0.6250) && (metric >= 0.6100) && 'Color', [1 0 0], ... // K?rm?z? color
 text(centroid(1), centroid(2),'Elma');
elseif (metric <= 0.6255) && (metric >= 0.6225) && 'Color', [1 0 0], ... // 
 text(centroid(1), centroid(2),'Nar');
elseif (metric <= 0.6900) && (metric >= 0.6755) && 'Color', [1 0 0], ... //
 text(centroid(1), centroid(2),'Portakal'); 
elseif (metric <= 0.6800) && (metric >= 0.6750) && 'Color', [1 0 0], ... // 
 text(centroid(1), centroid(2),'Muz'); 
elseif (metric <= 0.6915) && (metric >= 0.6890) && 'Color', [1 0 0], ... // 
 text(centroid(1), centroid(2),'Havu?'); 
elseif (metric <= 0.6955) && (metric >= 0.6920) && 'Color', [1 0 0], ... // K?rm?z? color
 text(centroid(1), centroid(2),'Mandalina'); 
end
disp(metric)
 text(boundary{1}(:,2),boundary{1}(:,1),metric_string,'color','y', .. ...
    'FontSize',14,'FontWeight','bold');
end

enter image description here

this is a carrot so must be in the following range and the printout should write carrots

text(centroid(1), centroid(2),'Havu?');



elseif (metric <= 0.6955) && (metric >= 0.6920) && 'Color', [1 0 0], ... // K?rm?z? color

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
等待大神解答

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...