关于读出图片中数字的代码,现在已有但只能读出四个数字来,无论你图片上有多少数字有没有高手愿意帮忙看看,修改一下了,愿意的留下邮箱我把程序发过去. 希望懂的大哥帮帮忙.
解决方案 »
- *****请问delphi有没有这个颜色选择控件的问题*****
- 处理粘贴事件
- 请问怎么得到指针的地址?
- 用DBGrid直接連TTable一個字段[decimal(18,4)],輸入125.2000卻變成125.1999,為什麼會這樣?
- 如何将一个project转为dll?
- 求Delphi6的升级程序SP3 下载后立刻结贴!!还有斑竹我的专家分怎么自己减了200多分啊!
- 关于安装程序的,哪里有full版的
- delphi控制SQL Server数据恢复的问题!(三层结构〉〉客户端恢复疑问?)
- 招聘
- 当我FREE时没有调用DLL出口函数?
- 为什么在FastReport 4.7.3下页码显示错误
- 谁有DEPHI的反编译工具Revendepro!!小弟跪求呀!
怕我们偷你的技术吗?
50%的识别率
一句话:无语
[email protected]
[email protected]
发过来研究一下,[email protected]
18楼你没有留下邮箱我发不过去啊.
interface
uses windows,math,classes,controls,graphics,jpeg,sysutils,dialogs,extctrls,forms,
stdctrls,ComCtrls;
Type
pRGBTripleArray = ^TRGBTripleArray;
TRGBTripleArray = array [0 .. 65535] of TRGBTriple;
Ptemplate=^Ttemplate; //被识别的数字当用记录保存起来
Ttemplate=record
number:integer;
top:Integer;
Left:Integer;
end;
TBmp2Number=class(Tobject)
private
FSourceBitMap:Tbitmap;
FTempl_index:integer;
Ftempl_Path:String;
Fdiscern_rate:Double;
FNumber:string;
FNumberList:TList;
tmeplate:Ptemplate;
fStop:Boolean;
FShowDemo:Boolean;
protected
procedure SetTempl_index(value:Integer);
procedure SetTempl_path(Value:String);
procedure InitTemplate;
Function GetNumber:String;
public
memo1:TRichedit;
image1,image2:Timage;
pb_Count,pb_deta:TProgressbar;
constructor Create;
published
property SourceBitMap:Tbitmap read FSourceBitMap write FSourceBitmap;
property Templ_index:integer read Ftempl_index write SetTempl_index;
Property Templ_Path:String read Ftempl_Path write SetTempl_path;
property discern_rate:Double read Fdiscern_rate write Fdiscern_rate ;
property Number:String read GetNumber;
property Stop:Boolean read Fstop write FStop;
property ShowDemo:Boolean read FShowDemo write FShowDemo;
end;
//SourceBitmap:电表图片,template_index:调用的模板号 template_path;模板存放的目录
Function Pic2Bmp(PicFileName:String):TBitmap;
implementation
//将图片转换成BMP格式,以便比较,主要是因为数码相机采集的图片基本上是JPEG 格式的。
//所以在装入时需要将其转换成BMP图片,便于比较
Function Pic2Bmp(PicFileName:String):TBitmap;
var
Str:String;
Icon: TIcon;
Jpeg1:TJPEGIMAGE;
MetaFile:TMetafile;
begin
result:=TBitMap.create;
result.PixelFormat:=pf24bit;
Str := ExtractFileExt(PicFileName);
Str :=Uppercase(Copy(Str,2,3));
if (Str='BMP') then
result.LoadFromFile(PicFileName)
else //Jpeg转换成BMP
if (Str='JPG') or (Str='JPEG') then
begin
Jpeg1 := TJPEGIMAGE.Create;
Jpeg1.LoadFromFile(PicFileName);
result.Assign(Jpeg1);
Jpeg1.free;
end
else //ICO 转换成BMP
if (Str='ICO') or (Str='ico') then
begin
Icon := TIcon.Create;
Icon.LoadFromFile(PicFileName);
result := TBitmap.Create;
result.Width := Icon.Width;
result.Height := Icon.Height;
result.Canvas.Draw(0, 0, Icon);
Icon.Free;
end
else //WMF转换成BMP
if Str='WMF' then
begin
Metafile:=TMetaFile.create;
MetaFile.LoadFromFile(PicFileName);
with result do
begin
Height:=Metafile.Height;
Width:=Metafile.Width;
Canvas.Draw(0,0,MetaFile);
end;
MetaFile.Free;
end;
end;
constructor TBmp2Number.Create;
begin
inherited Create;
Ftempl_index:=1;
Ftempl_Path:='template';
Fdiscern_rate:=100;
end;
procedure TBmp2Number.SetTempl_index(value:integer);
begin
FtempL_index:=Value;
initTemplate;
end;
procedure TBmp2Number.SetTempl_path(value:String);
begin
FTempl_path:=value;
initTemplate;
end;
//初始化运行模板库
procedure TBmp2Number.InitTemplate;
begin
if tempL_Index=0 then exit;
if Not DirectoryExists(Templ_Path) then exit;
end;
//逐行扫描的方式识别图片中的数字
function TBmp2Number.GetNumber:string;
var
tmpleBmp,midbmp:TBitMap;
row,Col,mRow,mCol,numberNo:integer;
NewRow,NewCol:integer;
PSource, Ptemple: pRGBTripleArray;
mR, mG, mB, tR, tG, tB: Integer;
mP, tP: pRGBTripleArray;
succ:Boolean;//对比是否成功
begin
//数据的初步检查
if sourcebitmap=nil then
begin
showmessage('请装入目标图片!');
exit;
end;
FNumberList:=Tlist.Create;
try
if assigned(pb_Count) then
pb_Count.Max:= SourceBitMap.width;
if assigned(pb_deta) then
pb_deta.Max:= SourceBitMap.Height;
for Col:=0 to SourceBitMap.width-1 do
begin
if stop then exit;
if ShowDemo then
memo1.Lines.Add('本列是:'+inttostr(col));
if assigned(pb_Count) then
begin
pb_Count.Position:=col;
Application.ProcessMessages;
end;
for Row:=0 to SourceBitMap.Height-1 do
begin
if assigned(pb_deta) then
begin
pb_deta.Max:= SourceBitMap.Height;
pb_deta.Position:=Row;
Application.ProcessMessages;
end;
if stop then exit;
for numberNo:=0 to 9 do //0至9的数字分别装入模板
begin
if not fileexists(Templ_Path+inttostr(numberNo)+'_'+inttostr(Templ_index)+'.bmp') then continue;
if stop then exit;
tmpleBmp:=TBitMap.create;
tmpleBmp:=Pic2Bmp(Templ_Path+inttostr(numberNo)+'_'+inttostr(Templ_index)+'.bmp');
// tmpleBmp.LoadFromFile(Templ_Path+inttostr(numberNo)+'_'+inttostr(Templ_index)+'.bmp');
if ShowDemo then
image1.Picture.bitmap:=tmplebmp;
//从原图像中驳离出来与模板文件同样大小的文件来
midbmp:=Tbitmap.Create;
midbmp.PixelFormat:= tmpleBmp.PixelFormat;
midbmp.Width:=tmplebmp.Width;
midbmp.height:=tmplebmp.Height;
application.ProcessMessages;
//
midbmp.Canvas.CopyRect(Rect(0,0,midbmp.width,midbmp.height),
sourcebitmap.canvas,
Rect(Col,row,Col+tmpleBmp.width,row+tmpleBmp.height));
if ShowDemo then
image2.picture.bitmap:=midbmp;
Assert(midbmp.PixelFormat = tmpleBmp.PixelFormat);
//然后逐行取值比较
for mRow:=0 to MidBmp.Height-1 do
begin
mp:= midBmp.ScanLine[mRow];
tp:= tmplebmp.ScanLine[mRow];
if stop then exit;
for mcol:=0 to MidBmp.Width -1 do
begin
if stop then exit;
mR := mp[mcol].rgbtRed;
mG := mP[mcol].rgbtGreen;
mB := mP[mcol].rgbtBlue;
tR := tP[mcol].rgbtRed;
tG:= tP[mcol].rgbtGreen;
tB:=tP[mcol].rgbtBlue;
if ShowDemo then
memo1.Lines.Add('Mrow:'+Inttostr(mrow)+'MCol:'+inttostr(Mcol)+'mr:'
+inttostr(mr)+'mg:'+inttostr(mg)+'mb:'+
inttostr(mb)+'tr:'+inttostr(tr)+'tg:'+inttostr(tg)+'tb:'+
inttostr(tb));
if (mR <> tR) or (mG <> tG) or (mB <> tB) then//如果像素不等
begin
succ:=false;
break;
end
else
succ:=true;
end; // end mcol:=0 to midbmp.width -1 do
end; //end mrow:=0 to midbmp.height-1 do
freeandnil(midbmp);
if succ then
begin//对比成功
new(tmeplate);
tmeplate.number:= numberNo;
tmePlate.top := Row;
tmePlate.left:=col;
FNumberList.Add(tmeplate);
end ;
// else
// break;
freeandnil(tmpleBmp);
end; //end for number
end; //end for row
end; // end for col
except
showmessage('对比失败!');
end;
for row:=0 to FNumberList.Count -1 do
Result:=result+inttostr(Ptemplate(FNumberlist.Items[row]).number);
for row:=FNumberList.count-1 downto 0 do
begin
Dispose(Ptemplate(FNumberList[Row]));
FNumberlist.Delete(row);
end;
FNumberlist.free;
end;
end.
这个大家帮忙看看能不能让其读出八位的数字.
function TBmp2Number.GetNumber:string;
var
tmpleBmp,midbmp:TBitMap;
row,Col,mRow,mCol,numberNo:integer;
NewRow,NewCol:integer;
PSource, Ptemple: pRGBTripleArray;
mR, mG, mB, tR, tG, tB: Integer;
mP, tP: pRGBTripleArray;
succ:Boolean;//对比是否成功
begin
//数据的初步检查
if sourcebitmap=nil then
begin
showmessage('请装入目标图片!');
exit;
end;
FNumberList:=Tlist.Create;
try
if assigned(pb_Count) then
pb_Count.Max:= SourceBitMap.width;
if assigned(pb_deta) then
pb_deta.Max:= SourceBitMap.Height;
for Col:=0 to SourceBitMap.width-1 do
begin
if stop then exit;
if ShowDemo then
memo1.Lines.Add('本列是:'+inttostr(col));
if assigned(pb_Count) then
begin
pb_Count.Position:=col;
Application.ProcessMessages;
end;
for Row:=0 to SourceBitMap.Height-1 do
begin
if assigned(pb_deta) then
begin
pb_deta.Max:= SourceBitMap.Height;
pb_deta.Position:=Row;
Application.ProcessMessages;
end;
if stop then exit;
for numberNo:=0 to 9 do //0至9的数字分别装入模板
begin
if not fileexists(Templ_Path+inttostr(numberNo)+'_'+inttostr(Templ_index)+'.bmp') then continue;
if stop then exit;
tmpleBmp:=TBitMap.create;
tmpleBmp:=Pic2Bmp(Templ_Path+inttostr(numberNo)+'_'+inttostr(Templ_index)+'.bmp');
// tmpleBmp.LoadFromFile(Templ_Path+inttostr(numberNo)+'_'+inttostr(Templ_index)+'.bmp');
if ShowDemo then
image1.Picture.bitmap:=tmplebmp;
//从原图像中驳离出来与模板文件同样大小的文件来
midbmp:=Tbitmap.Create;
midbmp.PixelFormat:= tmpleBmp.PixelFormat;
midbmp.Width:=tmplebmp.Width;
midbmp.height:=tmplebmp.Height;
application.ProcessMessages;
//
midbmp.Canvas.CopyRect(Rect(0,0,midbmp.width,midbmp.height),
sourcebitmap.canvas,
Rect(Col,row,Col+tmpleBmp.width,row+tmpleBmp.height));
if ShowDemo then
image2.picture.bitmap:=midbmp;
Assert(midbmp.PixelFormat = tmpleBmp.PixelFormat);
//然后逐行取值比较
for mRow:=0 to MidBmp.Height-1 do
begin
mp:= midBmp.ScanLine[mRow];
tp:= tmplebmp.ScanLine[mRow];
if stop then exit;
for mcol:=0 to MidBmp.Width -1 do
begin
if stop then exit;
mR := mp[mcol].rgbtRed;
mG := mP[mcol].rgbtGreen;
mB := mP[mcol].rgbtBlue;
tR := tP[mcol].rgbtRed;
tG:= tP[mcol].rgbtGreen;
tB:=tP[mcol].rgbtBlue;
if ShowDemo then
memo1.Lines.Add('Mrow:'+Inttostr(mrow)+'MCol:'+inttostr(Mcol)+'mr:'
+inttostr(mr)+'mg:'+inttostr(mg)+'mb:'+
inttostr(mb)+'tr:'+inttostr(tr)+'tg:'+inttostr(tg)+'tb:'+
inttostr(tb));
if (mR <> tR) or (mG <> tG) or (mB <> tB) then//如果像素不等
begin
succ:=false;
break;
end
else
succ:=true;
end; // end mcol:=0 to midbmp.width -1 do
end; //end mrow:=0 to midbmp.height-1 do
freeandnil(midbmp);
if succ then
begin//对比成功
new(tmeplate);
tmeplate.number:= numberNo;
tmePlate.top := Row;
tmePlate.left:=col;
FNumberList.Add(tmeplate);
end ;
// else
// break;
freeandnil(tmpleBmp);
end; //end for number
end; //end for row
end; // end for col
except
showmessage('对比失败!');
end;
for row:=0 to FNumberList.Count -1 do
Result:=result+inttostr(Ptemplate(FNumberlist.Items[row]).number);
for row:=FNumberList.count-1 downto 0 do
begin
Dispose(Ptemplate(FNumberList[Row]));
FNumberlist.Delete(row);
end;
FNumberlist.free;
end;
end.
有人指点一下这个吗?
[email protected]
改起来应该不复杂,[email protected]
看看也学习下。
了解下
[email protected]