【计算机视觉】【车辆识别】--Matlab实现

希望利用计算机自动计算出停车场车辆数目:

这里由于没有参考背景图,只有这一张,所以我采用的是对图像二值化,腐蚀膨胀,并且对白车、棕车、黑车各有一个阈值,之后计算图像域数量,则分别可以得到白车、黑车、棕车的数量,加在一起则是总数量,这里得到的结果是11.5辆。

clc;
clear all
I=imread('D:/作业1.png');
G=rgb2gray(I);
%  G=histeq(G);
H=imhist(G);
%  bar(H);
[a,b]=size(G);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取白车
G=G-100;
for i=1:1:a
   
    for j=1:1:b
        
       if G(i,j)>=25
           
           G2(i,j)=1;
           
       else
           
              G2(i,j)=0;
             
       end   
    end
end
se1=strel('square',10);
G4=imdilate(G2,se1);
se1=strel('square',15);
G4=imerode(G4,se1);
XX=bwlabel(G4,8);
white=max(max(XX))/2%%%%%%%%%%%%%两个点为1个白车
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取黑车
G=rgb2gray(I);
G=G+100;
[a,b]=size(G);
for i=1:1:a
   
    for j=1:1:b
        
       if G(i,j)<=150
           
           G1(i,j)=1;
           
       else
           
              G1(i,j)=0;
             
       end   
    end
end
se1=strel('square',20);%20  
G4=imerode(G1,se1); 
se1=strel('square',35); %35
G5=imdilate(G4,se1);
XX1=bwlabel(G5,8);
black=max(max(XX1))-2%%%%%%%%%%%%%%减去两个背景
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%提取棕车
G=rgb2gray(I);
[a,b]=size(G);
for i=1:1:a
   
    for j=1:1:b
        
       if G(i,j)<=100&&G(i,j)>=70
           
           G1(i,j)=1;
           
       else
           
              G1(i,j)=0;
             
       end   
    end
end
se1=strel('square',30);
G4=imerode(G1,se1);
se1=strel('square',30); 
G5=imdilate(G4,se1);
XX2=bwlabel(G5,8);
brown=max(max(XX2))-1%%%%%%%%%%%%减去中间背景点
XX3=XX1+XX2+XX;
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%出图
subplot 221
imshow(I)
subplot 222
% X1=double(G)-XX*255;
% imshow(X1/255)
 imshow(XX)
subplot 223
imshow(XX1)
% X2=double(G)-XX1*255;
% imshow(X2/255)
% imshow(XX1)
subplot 224
% X3=double(G)-XX2*255;
% imshow(X3/255)
 imshow(XX2)
sum=white+black+brown
 

11.5

发布了142 篇原创文章 · 获赞 358 · 访问量 65万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 技术黑板 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览