1 简介
2 部分代码
clc;clear;close all;
img_rgb=imread('支柱杆号.png');
I=img_rgb;
%% 灰度化及二值化
I1=rgb2gray(I);
I1=im2bw(I1);
I1=ROI(I1,3,10);
I1=bwareaopen(I1,100);
%% 垂向矫正
tic
BW=edge(I1,'canny');
[H,T,R]=hough(BW);
P=houghpeaks(H,4,'threshold',ceil(0.3*max(H(:))));
lines=houghlines(BW,T,R,P,'FillGap',50,'MinLength',7);
max_len = 0;
hold on;
for k=1:length(lines)
xy=[lines(k).point1;lines(k).point2];
len=norm(lines(k).point1-lines(k).point2);
Len(k)=len;
if (len>max_len)
max_len=len;
xy_long=xy;
end
end
[~,Index1]=max(Len(:));
K1=-(lines(Index1).point1(2)-lines(Index1).point2(2))/...
(lines(Index1).point1(1)-lines(Index1).point2(1));
angle=atan(K1)*180/pi;
I1 = imrotate(I1,-angle-90,'loose');
I1=ROI(I1,5,5);
%% 几何矫正
I1=Ajust(I1);
x=Xtrait(I1);
Lx=length(x);
for i=1:Lx-1
if x(i)>=x(i+1)
break
end
end
nX1=i;
for i=1:Lx-1-nX1
if x(Lx-i)>=x(Lx-i-1)
break
end
end
nX2=Lx-i;
I1=I1(:,nX1:nX2);
%% 移除小对象
I1=~I1;
I1=bwareaopen(I1,400);
I1=~I1;
%% ROI
I1=~I1;
I1=ROI(I1,1,1);
%% 切割
y=Ytrait(I1);
Py0=1;
figure();title('分割后');
for i=1:4
while ((y(Py0)<1)&&(Py0<length(y)))
Py0=Py0+1;
end
Py1=Py0;
while (((y(Py1)>=2)&&(Py1<length(y)))||((Py1-Py0)<50))
Py1=Py1+1;
end
Z=I1(Py0:Py1,:,:);
Py0=Py1;
subplot(1,4,i),imshow(Z);
switch strcat('Z',num2str(i))
case 'Z1'
PIN1=Z;
case 'Z2'
PIN2=Z;
case 'Z3'
PIN3=Z;
otherwise
PIN4=Z;
end
end
%% 分割后预处理
PIN1=ROI(PIN1,1,1);
PIN1=imresize(PIN1,[40 20]);
PIN2=ROI(PIN2,1,1);
PIN2=imresize(PIN2,[40 20]);
PIN3=ROI(PIN3,1,1);
PIN3=imresize(PIN3,[40 20]);
PIN4=ROI(PIN4,1,1);
PIN4=imresize(PIN4,[40 20]);
%% 将分割后的后的车牌字符归一化处理
n1=CCmatching(PIN1);
n2=CCmatching(PIN2);
n3=CCmatching(PIN3);
n4=CCmatching(PIN4);
marknumber=n1*1000+n2*100+n3*10+n4;
output=num2str(marknumber);
disp(strcat('支柱杆号是:',output));
toc
3 仿真结果
4 参考文献
[1]许庶, 马志锋, 吴炜. 基于计算机视觉的集装箱号码识别系统[J]. 电视技术, 2010(5):4.
博主简介:擅长智能优化算法、神经网络预测、信号处理、元胞自动机、图像处理、路径规划、无人机等多种领域的Matlab仿真,相关matlab代码问题可私信交流。
部分理论引用网络文献,若有侵权联系博主删除。
完整代码获取关注微信公众号天天matlab