need help in vehicle detection in images
4 visualizzazioni (ultimi 30 giorni)
Mostra commenti meno recenti
i am working with a code for vehicle detection... i get an error (
Index exceeds matrix dimensions.
Error in vehicle_detect (line 14) for i=1:85 im{i}=imread(strcat('snaps\',t2{i})) ;
)
which i am unable to resolve! can any one help? code is written below:
clc
clear all
close all
t=('snaps');
t1=struct2cell(t);
t2=t1(1,3:end);
p2 = [150,640];
p3= [150,1];
q3 = [200,640];
q2 = [200,1];
thcar=7;
%figure('name','Vehicle Image','numbertitle','off')
%%image read & rgb to gray conversion
for i=1:85 im{i}=imread(strcat('snaps\',t2{i})) ;
if size(im{i},3)>1
im{i}=rgb2gray(im{i});
end
imshow(im{i});
hold on
plot([p2(2),p3(2)],[p2(1),p3(1)],'Color','r','LineWidth',2)
plot([q2(2),q3(2)],[q2(1),q3(1)],'Color','b','LineWidth',2)
pause(0.1)
end
%%line drawing on images
%figure('name','Vehicle crop Image','numbertitle','off')
for i=1:length(im)
im1{i}=imcrop(im{i},[p3(2) p2(1) q3(2) q3(1)-p2(1)]) ;
imshow(im1{i})
%pause(0.1)
end
%%diffrentiated images
figure('name','diffretiated Image','numbertitle','off')
ZC=0;
for i=1:length(im1)-1
% d{i}=im1{i}-im1{i+1};
diff_im = imabsdiff(im1{i},im1{i+1});
temp= im2bw(diff_im,0.15);
[x,y]=find(temp);
I=zeros(size(temp));
Ix=im1{i+1};
for i=1:length(x)
I(x(i),y(i))=Ix(x(i),y(i));
end
% d{i}=I;
imshow(I)
%imtool(d{i});
% pause(0.2)
hold on
blobAnalysis = vision.BlobAnalysis('BoundingBoxOutputPort', true, ...
'AreaOutputPort', false, 'CentroidOutputPort', false, ...
'MinimumBlobArea', 500);
bbox = step(blobAnalysis, temp);
result = insertShape(Ix ,'Rectangle', bbox, 'Color', 'green');
ZC=ZC+(size(bbox,5)/thcar);
Zb=ZC;
resultt= insertText(result,[10 10],round(Zb(:)),'BoxOpacity', 1, ...
'FontSize', 15);
YO=imshow(resultt);
dd=size(resultt);
title('Detected Cars');
k=msgbox('cars');
close(k);
end
if ZC>=3.0
for i=0:length(ZC)
r=k/1200.33;
totalTRUCKS =round(r);
end
title('Detected TRUCKS');
msgbox(sprintf('totalTRUCKS = %2.3g\n',totalTRUCKS));
end
for i=0:length(Zb)
r=k/k*ZC-totalTRUCKS;
totalCARS =round(r);
end
msgbox(sprintf('totalCARS = %2.3g\n',totalCARS));
0 Commenti
Risposte (1)
Image Analyst
il 30 Lug 2017
What is "i"? Evidently t2 does not have that many elements. Why do you think it should?
0 Commenti
Vedere anche
Prodotti
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!