how can we detect vehicles using matlab
1 view (last 30 days)
Show older comments
respected sir/mam
i am unable to detect exact number of vehicles in the presence of day light and during the nights.here is my code with which i am working with to tackle this problem.can you please guide me to solve this problem.
clc;
close all;
clear all;
f=imread('C:\Users\Pratyusha\Desktop\project pics\morning 1030\2.jpg');
f=imresize(f,[800 NaN]);
figure (1)
imshow(f)
g=rgb2gray(f);
g=im2bw(g);
g=medfilt2(g,[5 5]);
figure (2)
imshow (g)
conc=strel('disk',5);
gi=imdilate(g,conc);
figure(3);
imshow(gi);
conc1=strel('disk',5);
ge=imerode(gi,conc1);
figure(4);
imshow(ge);
gdiff=imsubtract(gi,ge);
figure(5);
imshow(gdiff);
gdiff1=mat2gray(gdiff);
figure (6)
imshow (gdiff1)
gdiff2=conv2(gdiff1,[1 1;1 1]);
figure (7)
imshow (gdiff2)
gdiff3=imadjust(gdiff2,[0.5 0.7],[0 1],0.1);
figure (8)
imshow (gdiff3)
B=logical(gdiff3);
[a1 b1]=size(B);
figure(9)
imshow(B)
er=imerode(B,strel('line',60,8));
figure(10)
imshow(er)
out1=imsubtract(B,er);
F=imfill(out1,'holes');
H=bwmorph(F,'thin',1);
H=imerode(H,strel('line',8,55));
figure(11)
imshow(H)
I=bwareaopen(H,floor((a1/18)*(b1/18)));
I(1:floor(.9*a1),1:2)=1;
I(a1:-1:(a1-20),b1:1:(b1-2))=1;
figure(12)
imshow(I)
figure (13)
imshowpair (f,I)
Iprops=regionprops(I,'BoundingBox','Image');
hold on
text(8,785,strcat('\color{green}Cars Detected:',num2str(length(Iprops))))
hold on
for n=2:size(Iprops,1)
rectangle('Position',Iprops(n).BoundingBox,'EdgeColor','g','LineWidth',2);
end
hold off
0 Comments
Answers (0)
See Also
Categories
Find more on Image Processing Toolbox in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!