-
-
Save manniru/85688df542fea80e107b to your computer and use it in GitHub Desktop.
package com.mma.fingerprint; | |
import java.sql.Connection; | |
import java.sql.DriverManager; | |
import java.sql.PreparedStatement; | |
import java.sql.ResultSet; | |
import java.sql.SQLException; | |
import java.util.EnumMap; | |
import java.util.concurrent.LinkedBlockingQueue; | |
import com.digitalpersona.onetouch.*; | |
import com.digitalpersona.onetouch.capture.DPFPCapture; | |
import com.digitalpersona.onetouch.capture.DPFPCapturePriority; | |
import com.digitalpersona.onetouch.capture.event.DPFPDataEvent; | |
import com.digitalpersona.onetouch.capture.event.DPFPDataListener; | |
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusAdapter; | |
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent; | |
import com.digitalpersona.onetouch.processing.DPFPEnrollment; | |
import com.digitalpersona.onetouch.processing.DPFPFeatureExtraction; | |
import com.digitalpersona.onetouch.processing.DPFPImageQualityException; | |
import com.digitalpersona.onetouch.readers.DPFPReaderDescription; | |
import com.digitalpersona.onetouch.readers.DPFPReadersCollection; | |
import com.digitalpersona.onetouch.ui.swing.*; | |
import com.digitalpersona.onetouch.verification.DPFPVerification; | |
import com.digitalpersona.onetouch.verification.DPFPVerificationResult; | |
public class DigitalPersona { | |
//static EnumMap<DPFPFingerIndex, DPFPTemplate> templates; | |
static EnumMap<DPFPFingerIndex, DPFPTemplate> templates = new EnumMap<DPFPFingerIndex, DPFPTemplate>(DPFPFingerIndex.class); | |
public static void main(String[] args) { | |
listReaders(); | |
DigitalPersona dp = new DigitalPersona(); | |
DPFPTemplate temp = dp.getTemplate(null, 1); | |
byte[] b = temp.serialize(); | |
dp.insert(1, b); | |
b = dp.get(); | |
DPFPTemplate temp2 = DPFPGlobal.getTemplateFactory().createTemplate(); | |
temp2.deserialize(b); | |
if (dp.verify(null, temp)) | |
System.out.println("Finger Verified!"); | |
else | |
System.out.println("Finger not verify!"); | |
//boolean verify = dp.verify(null, template); | |
//System.out.println(verify); | |
//DPFPEnrollmentEvent e = null; | |
//templates.put(e.getFingerIndex(), e.getTemplate()); | |
} | |
public Connection cn() { | |
Connection conn = null; | |
try { Class.forName("com.mysql.jdbc.Driver"); | |
conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/fingerprint", "root", ""); | |
} catch(Exception e) { System.out.println(e); } | |
return conn; | |
} | |
public void insert(int id, byte[] digital){ | |
PreparedStatement st; | |
try { | |
st = cn().prepareStatement("INSERT INTO users(username, f1) VALUES(?, ?)"); | |
st.setInt(1, id); | |
st.setBytes(2, digital); | |
st.executeUpdate(); | |
} catch (SQLException e) { System.out.println(e.getMessage()); } | |
} | |
public byte[] get(){ | |
ResultSet rs; | |
PreparedStatement st; | |
byte[] digital = null; | |
try { | |
st = cn().prepareStatement("SELECT * FROM users"); | |
rs = st.executeQuery(); | |
if(rs.next()) | |
digital = rs.getBytes("f1"); | |
else | |
System.out.println("Record not available"); | |
} catch (Exception e) { | |
System.out.println(e.getMessage()); | |
} | |
return digital; | |
} | |
public static void listReaders() { | |
DPFPReadersCollection readers = DPFPGlobal.getReadersFactory().getReaders(); | |
if (readers == null || readers.size() == 0) { | |
System.out.printf("There are no readers available.\n"); | |
return; | |
} | |
System.out.printf("Available readers:\n"); | |
for (DPFPReaderDescription readerDescription : readers) | |
System.out.println(readerDescription.getSerialNumber()); | |
} | |
public static final EnumMap<DPFPFingerIndex, String> fingerNames; | |
static { | |
fingerNames = new EnumMap<DPFPFingerIndex, String>(DPFPFingerIndex.class); | |
fingerNames.put(DPFPFingerIndex.LEFT_PINKY, "left pinky"); | |
fingerNames.put(DPFPFingerIndex.LEFT_RING, "left ring"); | |
fingerNames.put(DPFPFingerIndex.LEFT_MIDDLE, "left middle"); | |
fingerNames.put(DPFPFingerIndex.LEFT_INDEX, "left index"); | |
fingerNames.put(DPFPFingerIndex.LEFT_THUMB, "left thumb"); | |
fingerNames.put(DPFPFingerIndex.RIGHT_PINKY, "right pinky"); | |
fingerNames.put(DPFPFingerIndex.RIGHT_RING, "right ring"); | |
fingerNames.put(DPFPFingerIndex.RIGHT_MIDDLE, "right middle"); | |
fingerNames.put(DPFPFingerIndex.RIGHT_INDEX, "right index"); | |
fingerNames.put(DPFPFingerIndex.RIGHT_THUMB, "right thumb"); | |
} | |
public DPFPTemplate getTemplate(String activeReader, int nFinger) { | |
System.out.printf("Performing fingerprint enrollment...\n"); | |
DPFPTemplate template = null; | |
try { | |
DPFPFingerIndex finger = DPFPFingerIndex.values()[nFinger]; | |
DPFPFeatureExtraction featureExtractor = DPFPGlobal.getFeatureExtractionFactory().createFeatureExtraction(); | |
DPFPEnrollment enrollment = DPFPGlobal.getEnrollmentFactory().createEnrollment(); | |
while (enrollment.getFeaturesNeeded() > 0) | |
{ | |
DPFPSample sample = getSample(activeReader, | |
String.format("Scan your %s finger (%d remaining)\n", fingerName(finger), enrollment.getFeaturesNeeded())); | |
if (sample == null) | |
continue; | |
DPFPFeatureSet featureSet; | |
try { | |
featureSet = featureExtractor.createFeatureSet(sample, DPFPDataPurpose.DATA_PURPOSE_ENROLLMENT); | |
} catch (DPFPImageQualityException e) { | |
System.out.printf("Bad image quality: \"%s\". Try again. \n", e.getCaptureFeedback().toString()); | |
continue; | |
} | |
enrollment.addFeatures(featureSet); | |
} | |
template = enrollment.getTemplate(); | |
System.out.printf("The %s was enrolled.\n", fingerprintName(finger)); | |
} catch (DPFPImageQualityException e) { | |
System.out.printf("Failed to enroll the finger.\n"); | |
} catch (InterruptedException e) { | |
throw new RuntimeException(e); | |
} | |
return template; | |
} | |
public boolean verify(String activeReader, DPFPTemplate template) { | |
try { | |
DPFPSample sample = getSample(activeReader, "Scan your finger\n"); | |
if (sample == null) | |
throw new Exception(); | |
DPFPFeatureExtraction featureExtractor = DPFPGlobal.getFeatureExtractionFactory().createFeatureExtraction(); | |
DPFPFeatureSet featureSet = featureExtractor.createFeatureSet(sample, DPFPDataPurpose.DATA_PURPOSE_VERIFICATION); | |
DPFPVerification matcher = DPFPGlobal.getVerificationFactory().createVerification(); | |
matcher.setFARRequested(DPFPVerification.MEDIUM_SECURITY_FAR); | |
for (DPFPFingerIndex finger : DPFPFingerIndex.values()) { | |
//DPFPTemplate template = user.getTemplate(finger); | |
if (template != null) { | |
DPFPVerificationResult result = matcher.verify(featureSet, template); | |
if (result.isVerified()) { | |
System.out.printf("Matching finger: %s, FAR achieved: %g.\n", | |
fingerName(finger), (double)result.getFalseAcceptRate()/DPFPVerification.PROBABILITY_ONE); | |
return result.isVerified(); | |
} | |
} | |
} | |
} catch (Exception e) { | |
System.out.printf("Failed to perform verification."); | |
} | |
return false; | |
} | |
public DPFPSample getSample(String activeReader, String prompt) | |
throws InterruptedException | |
{ | |
final LinkedBlockingQueue<DPFPSample> samples = new LinkedBlockingQueue<DPFPSample>(); | |
DPFPCapture capture = DPFPGlobal.getCaptureFactory().createCapture(); | |
capture.setReaderSerialNumber(activeReader); | |
capture.setPriority(DPFPCapturePriority.CAPTURE_PRIORITY_LOW); | |
capture.addDataListener(new DPFPDataListener() | |
{ | |
public void dataAcquired(DPFPDataEvent e) { | |
if (e != null && e.getSample() != null) { | |
try { | |
samples.put(e.getSample()); | |
} catch (InterruptedException e1) { | |
e1.printStackTrace(); | |
} | |
} | |
} | |
}); | |
capture.addReaderStatusListener(new DPFPReaderStatusAdapter() | |
{ | |
int lastStatus = DPFPReaderStatusEvent.READER_CONNECTED; | |
public void readerConnected(DPFPReaderStatusEvent e) { | |
if (lastStatus != e.getReaderStatus()) | |
System.out.println("Reader is connected"); | |
lastStatus = e.getReaderStatus(); | |
} | |
public void readerDisconnected(DPFPReaderStatusEvent e) { | |
if (lastStatus != e.getReaderStatus()) | |
System.out.println("Reader is disconnected"); | |
lastStatus = e.getReaderStatus(); | |
} | |
}); | |
try { | |
capture.startCapture(); | |
System.out.print(prompt); | |
return samples.take(); | |
} catch (RuntimeException e) { | |
System.out.printf("Failed to start capture. Check that reader is not used by another application.\n"); | |
throw e; | |
} finally { | |
capture.stopCapture(); | |
} | |
} | |
public String fingerName(DPFPFingerIndex finger) { | |
return fingerNames.get(finger); | |
} | |
public String fingerprintName(DPFPFingerIndex finger) { | |
return fingerNames.get(finger) + " fingerprint"; | |
} | |
} |
Good day I have tried implementing your solution in a sample test with my sample code below, but I still get the error below, Please what Might I be doing wrongly?
`
package application3;
import com.digitalpersona.onetouch.DPFPDataPurpose;
import com.digitalpersona.onetouch.DPFPFeatureSet;
import com.digitalpersona.onetouch.DPFPFingerIndex;
import com.digitalpersona.onetouch.DPFPGlobal;
import com.digitalpersona.onetouch.DPFPSample;
import com.digitalpersona.onetouch.DPFPTemplate;
import com.digitalpersona.onetouch.capture.DPFPCapture;
import com.digitalpersona.onetouch.capture.DPFPCapturePriority;
import com.digitalpersona.onetouch.capture.event.DPFPDataEvent;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusEvent;
import com.digitalpersona.onetouch.capture.event.DPFPReaderStatusListener;
import com.digitalpersona.onetouch.processing.DPFPEnrollment;
import com.digitalpersona.onetouch.processing.DPFPFeatureExtraction;
import com.digitalpersona.onetouch.processing.DPFPImageQualityException;
import com.digitalpersona.onetouch.readers.DPFPReadersCollection;
import java.awt.event.ActionEvent;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JButton;
/**
*
-
@author uncle-samba
*/
public class FrameDis extends javax.swing.JFrame {DPFPTemplate template;
DPFPFingerIndex fingerIndex;
String report = "";/**
-
@param args the command line arguments
/
public static void main(String[] args) {
/ Set the Nimbus look and feel /
//
/ If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.- For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
*/
try {
for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
if ("Nimbus".equals(info.getName())) {
javax.swing.UIManager.setLookAndFeel(info.getClassName());
break;
}
}
} catch (ClassNotFoundException ex) {
java.util.logging.Logger.getLogger(FrameDis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (InstantiationException ex) {
java.util.logging.Logger.getLogger(FrameDis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (IllegalAccessException ex) {
java.util.logging.Logger.getLogger(FrameDis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
} catch (javax.swing.UnsupportedLookAndFeelException ex) {
java.util.logging.Logger.getLogger(FrameDis.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
}
//
/* Create and display the form */
java.awt.EventQueue.invokeLater(() -> {
FrameDis f = new FrameDis();
//byte[] b = template1.serialize();
f.setVisible(true);
});
}
public DPFPTemplate getTemplate(String reader, int nFinger) {
StringBuilder sb = new StringBuilder();
DPFPTemplate temp = null;
DPFPFeatureExtraction extraction;
DPFPEnrollment enrollment;
DPFPFingerIndex finger;
try {
finger = DPFPFingerIndex.LEFT_THUMB;
extraction = DPFPGlobal.getFeatureExtractionFactory().createFeatureExtraction();
enrollment = DPFPGlobal.getEnrollmentFactory().createEnrollment();while (enrollment.getFeaturesNeeded() > 0) { DPFPSample sample = getSample(reader, String.format("Scan your %s finger (%d remaining)\n", "left pinky", enrollment.getFeaturesNeeded())); if (sample == null) continue; DPFPFeatureSet featureSet; try { featureSet = extraction.createFeatureSet(sample, DPFPDataPurpose.DATA_PURPOSE_ENROLLMENT); enrollment.addFeatures(featureSet); } catch (DPFPImageQualityException e) { setText("Featureset Error [getTemplate]:", String.format("Bad image quality: \"%s\". Try again. \n", e.getCaptureFeedback().toString())); } } temp = enrollment.getTemplate(); setText("message [getTemplate]", "Finger enrolled!");
} catch (UnsatisfiedLinkError err) {
setText("UnsatisfiedLinkError [getTemplate]:", err.getLocalizedMessage());
} catch (InterruptedException ex) {
setText("InterruptedException [getTemplate]:", ex.getLocalizedMessage());
Logger.getLogger(FrameDis.class.getName()).log(Level.SEVERE, null, ex);
}
return temp;
} - For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
public DPFPSample getSample (String reader, String prompt) throws InterruptedException {
final LinkedBlockingQueue samples = new LinkedBlockingQueue<>();
DPFPCapture capture = DPFPGlobal.getCaptureFactory().createCapture();
capture.setReaderSerialNumber(reader);
capture.setPriority(DPFPCapturePriority.CAPTURE_PRIORITY_LOW);
capture.addDataListener((DPFPDataEvent dpfpde) -> {
if (dpfpde != null && dpfpde.getSample() != null) {
try {
samples.put(dpfpde.getSample());
} catch (Exception e) {}
}
});capture.addReaderStatusListener(new DPFPReaderStatusListener() { int lastStatus = DPFPReaderStatusEvent.READER_CONNECTED; @Override public void readerConnected(DPFPReaderStatusEvent dpfprs) { if (lastStatus != dpfprs.getReaderStatus()) setText("Reader Status", "Reader Connected!"); lastStatus = dpfprs.getReaderStatus(); } @Override public void readerDisconnected(DPFPReaderStatusEvent dpfprs) { if (lastStatus != dpfprs.getReaderStatus()) setText("Reader Status", "Reader Disconnected"); lastStatus = dpfprs.getReaderStatus(); } }); try { capture.startCapture(); return samples.take(); } catch (Exception e) { setText("Error Capture Starting!:", e.getLocalizedMessage()+"\n"); throw e; } finally { setText("Capture Stopping:", prompt); capture.stopCapture(); }
}
public void listReaders () {
DPFPReadersCollection readers;
try {
readers = DPFPGlobal.getReadersFactory().getReaders();
if (readers == null || readers.isEmpty()) {
setText("Error", "No readers Found!");
return;
}
StringBuilder sb = new StringBuilder();
readers.stream().forEach((d) -> {
sb.append("reader: ")
.append(d.getSerialNumber());
});
setText("readers", sb.toString());
} catch (Exception exception ) {
setText("Error", exception.getLocalizedMessage());
}
}
/**- Creates new form FrameDis
*/
public FrameDis() {
initComponents();
}
/**
-
This method is called from within the constructor to initialize the form.
-
WARNING: Do NOT modify this code. The content of this method is always
-
regenerated by the Form Editor.
*/
@SuppressWarnings("unchecked")
//
private void initComponents() {jButton1 = new javax.swing.JButton();
jLabel1 = new javax.swing.JLabel();setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
jButton1.setText("Click Me To Start Capture ");
jButton1.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButton1ActionPerformed(evt);
}
});javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
getContentPane().setLayout(layout);
layout.setHorizontalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addGap(0, 346, Short.MAX_VALUE))
.addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
.addContainerGap()
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
.addContainerGap())
);
layout.setVerticalGroup(
layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(layout.createSequentialGroup()
.addComponent(jButton1)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jLabel1, javax.swing.GroupLayout.DEFAULT_SIZE, 466, Short.MAX_VALUE)
.addContainerGap())
);jLabel1.setText("<body style='width:200px;'" + jLabel1.getText() + "");
pack();
}//
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
setText("Sample", "App Started!");
listReaders();
DPFPTemplate template1 = getTemplate(null, 1);
setText("Success", "Finger Print gotten Finally!!");
}public void setText (String title, String msg) {
String s = new StringBuilder()
.append("").append(title).append("
\n")
.append("").append(msg).append("
")
.append("\n===================================================\n").toString();
report += s.toString();
jLabel1.setText("<body style='width:200px;'" + report + "");
this.repaint();
}public JButton getBtn () {
return this.jButton1;
}// Variables declaration - do not modify
private javax.swing.JButton jButton1;
private javax.swing.JLabel jLabel1;
// End of variables declaration
}
` -
//please sir what sdk did you use for this is it flexcode or ...?
hi please i am trying to do this fingerprint stuff using javafx and i have been running into some problems and i need help with it.
i have been reading on this trying to graps the logic behind makig such type of application and i will need help to full understand it.
plz i will like to know which sdk you used for this and how i can get it.
am seeing you using various import eg import com.digitalpersona.onetouch.processing.DPFPEnrollment;
how did you come about them is it part of the sdk?
plz i will also like to know the logic behind this too
thanks..
Once downloaded the project with all its jar files, I do not find where these packages are:
import com.digitalpersona.uareu.Engine;
import com.digitalpersona.uareu.Engine.Candidate;
import com.digitalpersona.uareu.Fid;
import com.digitalpersona.uareu.Fmd;
import com.digitalpersona.uareu.Fmd.Format;
import com.digitalpersona.uareu.Reader;
import com.digitalpersona.uareu.UareUException;
import com.digitalpersona.uareu.UareUGlobal;
Please, can someone help me?
CarlesFranquesa.
Do you import the jar file dpotapi?
it is necessary to execute all digitalPerson relative applications.
https://github.com/Eliezer090/JavaLibsPersonal
Libs necessária para esse .java
Thank You so much manniru..
this is what im looking for a long time.
i run the program with little editing and success.
Best of Luck.
another question, please
I made the DB with MYSQL. the data type for finger template I made is Blob.
I need to store it in binary.
can you advise me, please
what function i will convert it to binary? and then also verified it in binary.?
Please, can you kindly upload a read me file showing the data and their respective types being passed to the database
Sir I can't import the API references into the project, it gives error. I think I have kept the project at wrong place. where should I keep my project? Thanks