这种应当不难吧,类似于验证码的识别,这种图片里面的数字大小固定,也不存在噪点和噪线的问题;
你网上搜索下验证码的识别,了解下方法,我简要说下思路:
1.图像二值化;//可百度搜索delphi图像二值化,下同
2.图像分割;
3.找数字规律特征,也是最麻烦的一步!
4.识别;
识别的原理:
采用画线分割法,看画线经过点的个数,比如在图像分割后,在1/3处画一条横线,则经过一个点的数字有:
123567,经过两个点的有:0489;同理可以在2/3再画线经过一个点的有123579。。。
//二值化代码
function TForm1.Binaryzation(img:TBitmap): TBitmap;
var
m255 : Integer;
i,j,c,t : Integer;
r,g,b : Extended;
n,k : Integer;
begin
m255 := 255;
for i := 0 to img.Width-1 do
begin
for j := 0 to img.Height-1 do
begin
if (i=0) or (i=img.Width-1) then
begin
img.Canvas.Pixels[i,j] := clBlack;
Continue;
end;
if (j=0) or (j=img.Height-1) then
begin
img.Canvas.Pixels[i,j] := clBlack;
Continue;
end;
c := img.Canvas.Pixels[i,j];
r := GetRValue(c) * 0.333;
g := GetGValue(c) * 0.333;
b := GetBValue(c) * 0.333;
t := Round((r+g+b)/m255); //0.5 U:white ,0.5 O:black
if t=0 then
img.Canvas.Pixels[i,j] := clWhite
else
img.Canvas.Pixels[i,j] := clBlack;
end;
end;
Result := img;
end;
//识别关键代码 计算画线交点个数
for i:=0 to img.Width-1 do
begin
for j:=0 to img.height-1 do
begin
if imgAfterCut.Canvas.Pixels[i,j]=clwhite then //画线与数字的交点
begin
if (i=Round(1*(img.height-1)/3)) then // 1/3处点的个数
begin
a_31 := a_31+1; //a_31定义为integer;
end;
if (i=Round(2*(img.height-1)/3)) then // 2/3处点的个数
begin
a_32 := a_32+1;
end;
//.........统计1/2 竖向1/3 2/3 1/2等.............
end;
end;
end;
if a_31= 1 then
showmessage('123..')
else
if a_31= 2 then
begin
showmessage('0489');
// 其他逻辑判断
end;