procedure TMainForm.FPCapture2Complete(ASender: TObject;
const ReaderSerNum: WideString; const pSample: IDispatch);
var
l_interface : IDispatch;
tptStream : TMemoryStream;
p : Pointer;
begin
l_interface := FPGetImage.ConvertToPicture(pSample);
SetOlePicture(pbPrint2.Picture,IPictureDisp(l_interface)); //display print
//Search FP in db
With DM.VerifyQry do
begin
Close;
SQL.Clear;
SQL.Add('SELECT MemberName, MemberFP FROM MemberTbl');
// Open;
Active := True;
First;
while (NOT DM.VerifyQry.Eof) do
begin
try
// DM.VerifyQry.Locate('MemberID',FieldByName('MemberID').AsInteger,[]);
tptStream := TMemoryStream.Create();
// (DM.VerifyQry.FieldByName('MemberFP') AS TBlobField).SaveToStream(tptStream);
TBlobField(DM.VerifyQry.FieldByName('MemberFP')).SaveToStream(tptStream);
vrnt2 := VarArrayCreate([0, tptStream.Size], VarByte);
tptStream.Position := 0;
p := VarArrayLock(vrnt2);
tptStream.Read(p^, tptStream.Size);
VarArrayUnlock(vrnt2);
tptStream.Free;
except
tptStream.Free;
vrnt2:=null;
end;
Next;
end;
end;
FPTemplateFromDB2.Deserialize(vrnt2);
try
FPExtraction.CreateFeatureSet(pSample,DataPurposeVerification);
except
on E: exception do begin
showmessage('Exception occurred in CreateFeatureSet:' + e.Message);
exit;
end;
end;
if FPExtraction.FeatureSet=nil then begin
showmessage('Failed to extract verification features');
exit;
end;
try
FPVerifyRslt:= FPVerify.Verify(FPExtraction.FeatureSet,FPTemplateFromDB) as DPFPEngXLib_TLB.DPFPVerificationResult;
except
on E: Exception do begin
showmessage('Verify method failed');
showmessage(e.Message);
exit;
end;
end;
if fpverifyrslt.Verified=true then begin
ShowMessage('Matched');
end else begin
ShowMessage('Not Verified');
end;
end;
procedure TMainForm.FPCaptureComplete(ASender: TObject;
const ReaderSerNum: WideString; const pSample: IDispatch);
begin
l_interface := FPGetImage.ConvertToPicture(pSample);
lblInfo.Caption:='Sample Captured';
SetOlePicture(pbPrint.Picture,IPictureDisp(l_interface)); //display print
if breginprogress=true then begin
if index > 4 then index:=1; //reset index if beyond 4 presses
if index=1 then
begin
FPImage1.Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'\images\greenfp.bmp');
lbl1.Font.Color:=clGreen;
lbl2.Font.Color:=clYellow;
end;
if index=2 then
begin
FPImage2.Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'\images\greenfp.bmp');
lbl2.Font.Color:=clGreen;
lbl3.Font.Color:=clYellow;
end;
if index=3 then
begin
FPImage3.Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'\images\greenfp.bmp');
lbl3.Font.Color:=clGreen;
lbl4.Font.Color:=clYellow;
end;
if index=4 then lbl4.Font.Color:=clGreen;
index := index + 1;
//Create registration\enrollment featureset from sample captured
try
FPExtraction.CreateFeatureSet(pSample,DataPurposeEnrollment);
except
on E: Exception do begin
showmessage('Exception inside CreateFeatureSet');
showmessage(E.Message);
FPregister.Clear;
ResetLabels;
index:=1;
exit;
end;
end;
if FPExtraction.FeatureSet <> nil then
//Add features to registration object
FPRegister.AddFeatures(FPExtraction.FeatureSet)
else begin
Showmessage('Could not create featureset, poor press');
FPRegister.Clear;
ResetLabels;
index:=1;
exit; //return
end;
//If 4 successful features added, status should be 'Ready'
if FPRegister.TemplateStatus=TemplateStatusTemplateReady then begin
FPImage4.Picture.LoadFromFile(ExtractFilePath(Application.ExeName)+'\images\greenfp.bmp');
lblResult.Caption:='User Enrolled - Press Finger for Verification';
lbl1.Visible:=false; lbl2.Visible:=false; lbl3.Visible:=false; lbl4.Visible:=false;
FPTemplate:=FPRegister.Template as DPFPShrXLib_TLB.DPFPTemplate;
breginprogress:=false; //stop registration process, enable verification
//Before saving data to database you will need to get the raw data (variant)
try
vrnt:=FPTemplate.Serialize; //raw data is now stored in this variant
//Now that you have the variant, try to get raw byte array
//We are assuming here that you cannot save a variant directly to database field
//That you need a byte array before saving the data to the database.
aryLow:=VarArrayLowBound(vrnt,1);
aryHigh:=varArrayHighBound(vrnt,1);
aryHigh:=aryHigh-aryLow;
vtByteBuf:=VarArrayLock(vrnt); //lock down the array
for loopIndex := 0 to aryHigh - 1 do
fpData[loopIndex]:=vtByteBuf[loopIndex];
VarArrayUnlock(vrnt);
With DM.MemberTbl do
begin
Insert;
DM.MemberTbl.FieldByName('MemberName').AsString := tmpMemberName;
DM.MemberTbl.FieldByName('MemberFP').AsVariant := vrnt;
Post;
end;
except
on E: Exception do showmessage('Trouble saving data');
end;
//This section would be in a different form or part of your application.
//So just pretend that the user is at a login screen
//Before verification or user login you will need to read the user's fingerprint template from database
{Database logic not included}
//Once you get the raw data (here we are just reusing the fpData as opposed
//To actually loading it from a database) you will need to create a variant array.
rawDataSize:=High(fpData) - Low(fpData); //Obviously this would be set to actual data length of the field
try
vrnt := VarArrayCreate([0,rawDataSize],varByte); //Allocate the array required to store the fpdata in your variant
vtByteBuf:=VarArrayLock(vrnt);
for loopIndex := 0 to rawDataSize - 1 do
vtByteBuf[loopIndex]:=fpData[loopIndex];
VarArrayUnlock(vrnt);
except
on E: Exception do begin
showmessage('Ole exception');
showmessage(e.Message);
FPregister.Clear; //Reset registration rather than just exit program
ResetLabels;
index:=1;
exit;
end;
end;
//Then recreate a DPFPTemplate object by just calling Deserialize(yourvariant)
FPTemplateFromDB.Deserialize(vrnt);
//Now the template (FPTemplate2) is ready to be matched against.
end
else if FPRegister.TemplateStatus=TemplateStatusCreationFailed then
begin
showmessage('Registration failed');
FPRegister.Clear; //Reset registration operation
ResetLabels();
index:=1;
exit;
end;
end
else begin //Code for verification
//Create verification featureset
try
FPExtraction.CreateFeatureSet(pSample,DataPurposeVerification);
except
on E: exception do begin
showmessage('Exception occurred in CreateFeatureSet:' + e.Message);
//saveSample('pSample' + IntToStr(fileIndex),DPFPShrXLib_TLB.DPFPSample(pSample));
fileIndex:= fileIndex+1;
exit;
end;
end;
if FPExtraction.FeatureSet=nil then
begin
showmessage('Failed to extract verification features');
exit;
end;
//Perform verification\matching
try
FPVerifyRslt:= FPVerify.Verify(FPExtraction.FeatureSet,FPTemplateFromDB) as DPFPEngXLib_TLB.DPFPVerificationResult;
except
on E: Exception do begin
showmessage('Verify method failed');
showmessage(e.Message);
exit;
end;
end;
lblResult.Font.Size:=24;
if fpverifyrslt.Verified=true then
begin
lblResult.Font.Color:=clgreen;
lblResult.Caption:='Matched!';
end
else begin
lblResult.Font.Color:=clRed;
lblResult.Caption:='Not matched!';
end;
end;
end;
ASKER
ASKER
ASKER
Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.
TRUSTED BY
The problem is that I don't see the structure, where it may fail.