断裂字符的合并-弧特征

前言

车号识别项目中,车号字符含有较多粘连和断裂,针对断裂字符,改进了一篇论文中的弧特征方法,效果还可以。

算法matlab代码如下:

% /************************************************************************
% * Copyright(c) 2017  ZRJ
% * All rights reserved.
% *
% * File:	arc_feature.m
% * Brief: 基于弧特征进行断裂字符区域合并算法
% * Version: 1.0
% * Author: ZRJ
% * Email: happyamyhope@163.com
% * Date:	2017/02/28
% * Reference:对粘连和缺损数字串分割的研究;
% * History:
% * 20170307:基于弧特征进行断裂字符区域合并算法;
% * 20170313:论文中对弧特征的判定有误, 进行了勘误和改进;
%
% ************************************************************************/
function [up, down] = arc_feature( BW )
%程序功能:计算区域块弧特征
%输入input:
%      BW  --  断裂字符区域块;
%输出output:
%      up  --  字符区域上半部弧特征;
%      down  --  字符区域下半部弧特征;

BW=blackqiege(BW);
BW=whiteqiege(BW); 
[m, n] = size(BW);
%
ud = zeros(1, n);
for j = 1 : 1 : n
    for i = 1 : 1 : m/2
        if(BW(i, j) == 1)
            ud(1, j) = i;%自数字上边界开始向下探到数字区域的深度;
            break;
        end
    end
end

dd = zeros(1, n);
for j = 1 : 1 : n
    for i = m : -1 : m/2
        if(BW(i, j) == 1)
            dd(1, j) = m-i+1;%自数字下边界开始向上探到数字区域的深度;
            break;
        end
    end
end
clear i j


fu_increase = 0;
fu_decrease = 0;
fd_increase = 0;
fd_decrease = 0;
for i = 1 : 1 : n-1
%改进:增多或减少趋势次数多的作为判断依据;decrease;increase
if (ud(1, i)- ud(1, i+1) > 0)%左弧
    fu_increase = fu_increase + 1;
elseif (ud(1, i)- ud(1, i+1) < 0)%右弧
    fu_decrease = fu_decrease + 1;
end

if(dd(1, i)- dd(1, i+1) > 0)%左弧
    fd_increase = fd_increase + 1;
elseif(dd(1, i)- dd(1, i+1) < 0)%右弧
    fd_decrease = fd_decrease + 1;
end
    

end
clear i 
%LU上部弧特征
if( fu_increase > fu_decrease && fu_increase >= 0.3*size(BW,2) )
    up = -1;%左弧特征
elseif( fu_increase < fu_decrease && fu_decrease >= 0.3*size(BW,2) )
    up = 1;%右弧特征
else
    up = 0;%不具有左、右弧特征
end

%LD下部弧特征
if( fd_increase > fd_decrease && fd_increase >= 0.3*size(BW,2) )
    down = -1;%左弧特征
elseif( fd_increase < fd_decrease && fd_decrease >= 0.3*size(BW,2)  )
    down = 1;%右弧特征
else
    down = 0;%不具有左、右弧特征
end


end%end function arc_feature 

blackqiege函数:去除边缘无用背景区域;

function e=blackqiege(d) 
%程序功能:实现列车车号定位文本的无关边界切割

%输入:d——去除小区域后的文本区域的二值化图像;
%输出:e——实现列车车号定位文本的无关黑色边界切割

[m,n]=size(d);

top=1;bottom=m;left=1;right=n;   % init 
    while sum(d(top,:))==0 && top<m             
        top=top+1; 
    end
    while sum(d(bottom,:))==0 && bottom>1           
        bottom=bottom-1; 
    end
    while sum(d(:,left))==0 && left<n           
        left=left+1; 
    end
    while sum(d(:,right))==0 && right>1 
        right=right-1; 
    end
dd=right-left; 
hh=bottom-top; 
if(dd < 1 && hh <1)
    e = 0;
else
    e=imcrop(d,[left top dd hh]);  %返回图像的一个裁剪区域
end


end

writeqiege函数:去除边缘无用前景区域干扰;

function e=whiteqiege(d) 
%程序功能:实现列车车号定位文本的无关边界切割

%输入:d——去除小区域后的文本区域的二值化图像;
%输出:e——实现列车车号定位文本的无关白色边界切割

[m,n]=size(d);

top=1;bottom=m;left=1;right=n;   % init 

    while sum(d(top,:))==n && top<m             
        top=top+1; 
    end
    while sum(d(bottom,:))==n && bottom>1           
        bottom=bottom-1; 
    end
    while sum(d(:,left))==m && left<n           
        left=left+1; 
    end
    while sum(d(:,right))==m && right>1 
        right=right-1; 
    end

dd=right-left; 
hh=bottom-top;  
if(dd < 1 && hh <1)
    e = 0;
else
    e=imcrop(d,[left top dd hh]);  %返回图像的一个裁剪区域
end

end

问题及改进:

1.原论文中对弧特征的定义有异议,可自行查看;

2.深入分析弧特征,改进了弧特征的定义;

3.根据项目中字符特点,对弧特征的判决条件进行了改进;

思考:

出版的论文也不一定是完善的,只是提供了一种可能的想法和思路,需要根据实际项目需求进行验证和改进!!!

原文地址:https://www.cnblogs.com/happyamyhope/p/6593347.html