Я использую DigitalPersona u.are.u 4500. Я уже могу зарегистрироваться и проверить шаблоны отпечатков пальцев в своей базе данных.Но моя проблема состоит в том, что после того, как я уже проверил шаблон отпечатка пальца. Когда я хочу проверить другой шаблон отпечатка пальца из базы данных, приглашение показывает метод catch «Can't инициировать захват!»и все члены обработчика событий не отображаются.
// он входит в ловушку, когда я пытаюсь выполнить другую проверку
protected void Start()
{
if (null != Capturer)
{
try
{
Capturer.StartCapture();
SetPrompt("Using the fingerprint reader, scan your fingerprint.");
}
catch
{
SetPrompt("Can't initiate capture!");
}
}
}
// ЗДЕСЬ КОД ВЕРИФИКАЦИИ <- language:lang-cs ->
public delegate void OnTemplateEventHandler(DPFP.Template template);
public VerifyForm()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
#region Form Event Handlers:
private void VerifyForm_Load(object sender, EventArgs e)
{
this.WindowState = FormWindowState.Maximized;
label14.Text = BARCODE.SetValueForText1;
Init();
Start();
string selectQuery = "SELECT * FROM student_list WHERE student_number=" + (BARCODE.SetValueForText1);
connection.Open();
command = new MySqlCommand(selectQuery, connection);
mdr = command.ExecuteReader();
if (mdr.Read())
{
label14.Text = mdr.GetString("last_name");
}
else
{
label14.Text = "";
}
connection.Close();
}
private void VerifyForm_FormClosed(object sender, FormClosedEventArgs e)
{
Stop();
}
#endregion
public void Verify(DPFP.Template template)
{
Template = template;
ShowDialog();
}
private void Init()
{
base.Text = "Fingerprint Enrollment";
Enroller = new DPFP.Processing.Enrollment(); // Create an enrollment.
UpdateStatus();
try
{
Capturer = new DPFP.Capture.Capture(); // Create a capture operation.
if (null != Capturer)
Capturer.EventHandler = this; // Subscribe for capturing events.
else
SetPrompt("Can't initiate capture operation!");
}
catch
{
MessageBox.Show("Can't initiate capture operation!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
base.Text = "Fingerprint Verification";
Verificator = new DPFP.Verification.Verification(); // Create a fingerprint template verificator
UpdateStatus(0);
}
private void Process(DPFP.Sample Sample)
{
MySqlCommand command = new MySqlCommand("SELECT student_fingerprint FROM student_list WHERE student_number = @id", connection);
command.Parameters.Add("id", MySqlDbType.Text).Value = BARCODE.SetValueForText1;
connection.Open();
MySqlDataAdapter sd = new MySqlDataAdapter(command);
DataTable dt = new DataTable();
sd.Fill(dt);
foreach (DataRow dr in dt.Rows)
{
byte[] fingerprintData = (byte[])dr["student_fingerprint"];
MemoryStream ms = new MemoryStream(fingerprintData);
DPFP.Template Template = new DPFP.Template();
Template.DeSerialize(fingerprintData);
// DPFP.Verification.Verification Verificator = new DPFP.Verification.Verification();
Processs(Sample);
DrawPicture(ConvertSampleToBitmap(Sample));
//
// Process the sample and create a feature set for the enrollment purpose.
DPFP.FeatureSet features = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Verification);
// Check quality of the sample and start verification if it's good
// TODO: move to a separate task
if (features != null)
{
// Compare the feature set with our template
DPFP.Verification.Verification.Result result = new DPFP.Verification.Verification.Result();
Verificator.Verify(features, Template, ref result);
UpdateStatus(result.FARAchieved);
if (result.Verified)
{
MakeReport("The fingerprint was VERIFIED.");
MessageBox.Show("Fingerprint was Verified!");
SetPrompt("You can now proceed to the next page");
this.Invoke(new Function(delegate ()
{
btn_proceed.Enabled = true;
}));
}
else
{
MakeReport("The fingerprint was NOT VERIFIED.");
MessageBox.Show("Fingerprint was not Verified! Try again");
SetPrompt("Make sure that your finger is clean and positioned properly then try again.");
}
}
}
connection.Close();
}
private void Processs(DPFP.Sample Sample)
{
//remove it didnt work
DPFP.FeatureSet featuress = ExtractFeatures(Sample, DPFP.Processing.DataPurpose.Enrollment);
// Check quality of the sample and add to enroller if it's good
if (featuress != null) try
{
MakeReport("The fingerprint feature set was created.");
Enroller.AddFeatures(featuress); // Add feature set to template.
}
finally
{
UpdateStatus();
// Check if template has been created.
switch (Enroller.TemplateStatus)
{
case DPFP.Processing.Enrollment.Status.Ready: // report success and stop capturing
OnTemplate(Enroller.Template);
SetPrompt("Click Close, and then click Fingerprint Verification.");
Stop();
break;
case DPFP.Processing.Enrollment.Status.Failed: // report failure and restart capturing
Enroller.Clear();
Stop();
UpdateStatus();
OnTemplate(null);
Start();
break;
}
}
}
//////TEMPLATE
private void OnTemplate(DPFP.Template template)
{
this.Invoke(new Function(delegate ()
{
Template = template;
if (Template != null)
MessageBox.Show("The fingerprint template is ready for fingerprint verification.", "Fingerprint Enrollment");
else
MessageBox.Show("The fingerprint template is not valid. Repeat fingerprint enrollment.", "Fingerprint Enrollment");
}));
}
//remove if didnt work
private void UpdateStatus()
{
// Show number of samples needed.
SetStatus(String.Format("Fingerprint samples needed: {0}", Enroller.FeaturesNeeded));
}
///////
protected void SetStatus(string status)
{
this.Invoke(new Function(delegate () {
StatusLine.Text = status;
}));
}
protected void SetPrompt(string prompt)
{
this.Invoke(new Function(delegate () {
Prompt.Text = prompt;
}));
}
protected void MakeReport(string message)
{
this.Invoke(new Function(delegate () {
StatusText.AppendText(message + "\r\n");
}));
}
protected DPFP.FeatureSet ExtractFeatures(DPFP.Sample Sample, DPFP.Processing.DataPurpose Purpose)
{
DPFP.Processing.FeatureExtraction Extractor = new DPFP.Processing.FeatureExtraction(); // Create a feature extractor
DPFP.Capture.CaptureFeedback feedback = DPFP.Capture.CaptureFeedback.None;
DPFP.FeatureSet features = new DPFP.FeatureSet();
Extractor.CreateFeatureSet(Sample, Purpose, ref feedback, ref features); // TODO: return features as a result?
if (feedback == DPFP.Capture.CaptureFeedback.Good)
return features;
else
return null;
}
#region EventHandler Members:
public void OnComplete(object Capture, string ReaderSerialNumber, DPFP.Sample Sample)
{
MakeReport("The fingerprint sample was captured.");
SetPrompt("Scan the same fingerprint again.");
Process(Sample);
}
public void OnFingerGone(object Capture, string ReaderSerialNumber)
{
MakeReport("The finger was removed from the fingerprint reader.");
}
public void OnFingerTouch(object Capture, string ReaderSerialNumber)
{
MakeReport("The fingerprint reader was touched.");
}
public void OnReaderConnect(object Capture, string ReaderSerialNumber)
{
MakeReport("The fingerprint reader was connected.");
}
public void OnReaderDisconnect(object Capture, string ReaderSerialNumber)
{
MakeReport("The fingerprint reader was disconnected.");
}
public void OnSampleQuality(object Capture, string ReaderSerialNumber, DPFP.Capture.CaptureFeedback CaptureFeedback)
{
if (CaptureFeedback == DPFP.Capture.CaptureFeedback.Good)
MakeReport("The quality of the fingerprint sample is good.");
else
MakeReport("The quality of the fingerprint sample is poor.");
}
#endregion
private void DrawPicture(Bitmap bitmap)
{
this.Invoke(new Function(delegate () {
Picture.Image = new Bitmap(bitmap, Picture.Size); // fit the image into the picture box
}));
}
private DPFP.Processing.Enrollment Enroller;
protected Bitmap ConvertSampleToBitmap(DPFP.Sample Sample)
{
DPFP.Capture.SampleConversion Convertor = new DPFP.Capture.SampleConversion(); // Create a sample convertor.
Bitmap bitmap = null; // TODO: the size doesn't matter
Convertor.ConvertToPicture(Sample, ref bitmap); // TODO: return bitmap as a result
return bitmap;
}
private DPFP.Capture.Capture Capturer;
///////
private void UpdateStatus(int FAR)
{
// Show "False accept rate" value
SetStatus(String.Format("False Accept Rate (FAR) = {0}", FAR));
}
private DPFP.Template Template;
private DPFP.Verification.Verification Verificator;
protected void Start()
{
if (null != Capturer)
{
try
{
Capturer.StartCapture();
SetPrompt("Using the fingerprint reader, scan your fingerprint.");
}
catch
{
SetPrompt("Can't initiate capture!"); //the prompt goes here
}
}
}
protected void Stop()
{
if (null != Capturer)
{
try
{
Capturer.StopCapture();
}
catch
{
SetPrompt("Can't terminate capture!");
}
}
}
private void label14_Layout(object sender, LayoutEventArgs e)
{
}
private void btn_proceed_Click(object sender, EventArgs e)
{
PROCEED b = new PROCEED();
this.Hide();
b.Show();
}
private void CloseButton_Click(object sender, EventArgs e)
{
}
private void button1_Click(object sender, EventArgs e)
{
LOGIN na = new LOGIN();
this.Hide();
na.Show();
}
}