在Delphi中进行指纹仪的二次开发(2)
2008-04-09 04:31:55来源:互联网 阅读 ()
procedure uru_AllocFeature; external DLLNAME;
procedure uru_FreeFeature; external DLLNAME;
function uru_GetImageWidth; external DLLNAME;
function uru_GetImageHeight; external DLLNAME;
function uru_Register; external DLLNAME;
function uru_AcquireFeatures; external DLLNAME;
function uru_verifyFeatures; external DLLNAME;
procedure uru_DllRegister; external DLLNAME;
Procedure uru_StopGetImage;external DLLNAME;
end.
完成以上工作以后,则可以在主工程文件中引用Shelluru.pas文件,然后就可以调用Shelluru.pas文件中定义的函数了。
2.把验证后的指纹数据保存在文件中或数据库中
通过调用以上定义的函数,我们可以实现一个指纹的注册,验证,指纹数据保存,指纹再验证(识别)的指纹识别系统。下面重点介绍一下指纹的注册和验证识别过程的编程实现:
procedure TForm1.BtnRegisterClick(Sender: TObject); file://注册指纹
var
i:integer;
begin
if UserList.Selected = nil then
begin
MessageBox(Application.Handle, ''''请先选择用户!'''', nil, MB_OK);
Exit;
end;
if UserList.Selected.Data <> nil then
Feature := UserList.Selected.Data file://此时Feature为空
else
uru_AllocFeature(Feature);
if Feature = nil then file://假如指纹特征为空
begin
Status.SimpleText := ''''不能分配Feature内存'''';
Exit;
end;
for i := 1 to 4 do
begin
FillChar(Pixels[i]^, uru_GetImageWidth * uru_GetImageHeight, $FF);
Images[i].Refresh;
end;
Status.SimpleText := ''''开始注册 '''' UserList.Selected.Caption '''' 的指纹...'''';
if uru_Register(Handle, DeviceNo, 4, @Pixels, Feature) = FT_OK then
begin
Status.SimpleText := UserList.Selected.Caption '''': 注册成功!'''';
if UserList.Selected.Data = nil then
UserList.Selected.Data := Feature;
end
else
begin
if UserList.Selected.Data = nil then uru_FreeFeature(Feature);
Status.SimpleText := UserList.Selected.Caption '''': 注册失败!'''';
end;
end;
此函数主要调用了DLL中的uru_Register函数,用来为用户注册指纹,注册指纹是为了提取指纹的特征值,为特征值分配一端内存,用来存储指纹特征值数据,并用一个指针指向这段内存,以便将来可以找回来。注册完成后要立即进行一次验证,确保数据无误,验证过程如下:
procedure TForm1.BtnVerifyClick(Sender: TObject); file://验证指纹
var
aFeature: pointer;
i: integer;
fingerpath: string ;
begin
fingerpath:=''''C:\finger'''' Edit9.Text Edit10.Text;//指纹数据存储路径
if UserList.Selected = nil then
begin
MessageBox(Application.Handle, ''''请先选择用户!'''', nil, MB_OK);
Exit;
end;
if UserList.Selected.Data = nil then
begin
MessageBox(Application.Handle, PChar(Format(''''用户 %s 还没有注册指纹,请先注册!'''', [UserList.Selected.Caption])), nil, MB_OK);
Exit;
end;
FillChar(Pixels[5]^, uru_GetImageWidth * uru_GetImageHeight, $FF);
Images[5].Refresh;
Status.SimpleText := ''''开始验证 '''' UserList.Selected.Caption '''' 的指纹...'''';
Feature := UserList.Selected.Data; file://需要对比指纹数据
move(Feature^,byt,len); file://把内存中的一段长为len,从Feature开始的数据移到byte数组中
uru_AllocFeature(aFeature);//分配指纹数据地址
if (uru_AcquireFeatures(handle, DeviceNo, Pixels[5], aFeature) = FT_OK) and uru_verifyFeatures(@byt, aFeature) then
file://uru_AcquireFeatures指纹验证
file://uru_verifyFeatures指纹对比
begin
Status.SimpleText := UserList.Selected.Caption '''': 验证成功!'''';
AssignFile(F,fingerpath);//分配文件
ReWrite(F);//重写文件
for i:=0 to len do
Write(F,byt[i]);//把指纹仪数据写入文件
CloseFile(F);//关闭文件
end
else
Status.SimpleText := UserList.Selected.Caption '''': 验证失败!'''';
uru_FreeFeature(aFeature); file://释放内存
end;
以上过程关键在于指纹验证成功后,及时把内存中的指纹数据存到数据文件中,数据文件名最好是用户名加上编号,以便以后验证时方便找到对应的用户指纹数据。最后还要记得把临时分配的内存释放掉。把指纹数据存储到文件,以后就可以通过打开文件的方式,把数据文件调出来,与当前用户进行一个匹配的过程,以便验证用户的正确身份,具体过程如下:
procedure TForm1.BitBtn2Click(Sender: TObject); file://验证旧用户指纹
var
aFeature1: pointer;
i: integer;
begin
if OpenDialog1.Execute then
begin
AssignFile(G,OpenDialog1.FileName);//指定文件
Reset(G);//重置文件
for i:=0 to len do
Read(G,byt2[i]);//把文件中的指纹仪数据移到byte2数组中
CloseFile(G);//关闭文件
end;
FillChar(Pixels[5]^, uru_GetImageWidth * uru_GetImageHeight, $FF);
Images[5].Refresh;
Status.SimpleText := ''''开始验证 '''' UserList.Selected.Caption '''' 的指纹...'''';
uru_AllocFeature(aFeature1);//分配指纹数据地址
if (uru_AcquireFeatures(handle, DeviceNo, Pixels[5], aFeature1) = FT_OK) and uru_verifyFeatures(@byt2, aFeature1) then
Status.SimpleText := UserList.Selected.Caption '''': 验证成功!''''
else
Status.SimpleText := UserList.Selected.Caption '''': 验证失败!'''';
标签:
版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有
IDC资讯: 主机资讯 注册资讯 托管资讯 vps资讯 网站建设
网站运营: 建站经验 策划盈利 搜索优化 网站推广 免费资源
网络编程: Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 其它
服务器技术: Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护
软件技巧: 其它软件 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷
网页制作: FrontPages Dreamweaver Javascript css photoshop fireworks Flash
