javafingerprintdigital-persona-sdk

Is there way to extract fingerprint data to an image?


I am using Digital Persona U.Are.U 4500 and I have installed the finger print SDK from the hardware. I am using the Java API and was able to run the sample codes in Java. Right now, I am trying save the fingerprint data as an image. Is there any way that I can save it as an image, any kind of format as long as I can save it in my computer and view it as an image. Thanks!

I realized that the 'evt.capture_result.image' has a data type of Fid. I think this might help me, but I don't know how to convert Fid file to bytes[]. Or am I wrong about this?

This is the capture class, I was hoping to change a little bit of the code here.

package fp;

import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JPanel;

import com.digitalpersona.javapos.services.biometrics.CaptureThread; 
import com.digitalpersona.uareu.*;
import com.digitalpersona.uareu.Fid.Fiv;
import static sun.security.krb5.Confounder.bytes;

public class Capture extends JPanel implements ActionListener {
private static final long serialVersionUID = 2;
private static final String ACT_BACK = "back";

private JDialog       m_dlgParent;
private CaptureThread m_capture;
private Reader        m_reader;
private ImagePanel    m_image;
    private Fid           m_fid; //fid
    private Fiv           m_fiv; //fiv
private boolean       m_bStreaming;

private Capture(Reader reader, boolean bStreaming){
    m_reader = reader;
    m_bStreaming = bStreaming;

    m_capture = new CaptureThread(m_reader, m_bStreaming, Fid.Format.ANSI_381_2004, Reader.ImageProcessing.IMG_PROC_DEFAULT);

    final int vgap = 5;
    BoxLayout layout = new BoxLayout(this, BoxLayout.Y_AXIS);
    setLayout(layout);

    m_image = new ImagePanel();
    Dimension dm = new Dimension(380, 380);
    m_image.setPreferredSize(dm);
    add(m_image);
    add(Box.createVerticalStrut(vgap));

    JButton btnBack = new JButton("Back");
    btnBack.setActionCommand(ACT_BACK);
    btnBack.addActionListener(this);
    add(btnBack);
    add(Box.createVerticalStrut(vgap));}
private void StartCaptureThread(){
    m_capture = new CaptureThread(m_reader, m_bStreaming, Fid.Format.ANSI_381_2004, Reader.ImageProcessing.IMG_PROC_DEFAULT);
    m_capture.start(this);
}

private void StopCaptureThread(){
    if(null != m_capture) m_capture.cancel();
}

private void WaitForCaptureThread(){
    if(null != m_capture) m_capture.join(1000);
}

public void actionPerformed(ActionEvent e){
    if(e.getActionCommand().equals(ACT_BACK)){
        //event from "back" button
        //cancel capture
        StopCaptureThread();
    }
    else if(e.getActionCommand().equals(CaptureThread.ACT_CAPTURE)){
        //event from capture thread
        CaptureThread.CaptureEvent evt = (CaptureThread.CaptureEvent)e;
        boolean bCanceled = false;

        if(null != evt.capture_result){
            if(null != evt.capture_result.image && Reader.CaptureQuality.GOOD == evt.capture_result.quality){
                //display image
                m_image.showImage(evt.capture_result.image);


                            }
            else if(Reader.CaptureQuality.CANCELED == evt.capture_result.quality){
                //capture or streaming was canceled, just quit
                bCanceled = true;
            }
            else{
                //bad quality
                MessageBox.BadQuality(evt.capture_result.quality);
            }
        }
        else if(null != evt.exception){
            //exception during capture
            MessageBox.DpError("Capture",  evt.exception);
            bCanceled = true;
        }
        else if(null != evt.reader_status){
            MessageBox.BadStatus(evt.reader_status);
            bCanceled = true;
        }

        if(!bCanceled){
            if(!m_bStreaming){
                //restart capture thread
                WaitForCaptureThread();
                StartCaptureThread();

            }
        }
        else{
            //destroy dialog
            m_dlgParent.setVisible(false);
        }
    }
}

private void doModal(JDialog dlgParent){
    //open reader
    try{
        m_reader.Open(Reader.Priority.COOPERATIVE);
    }
    catch(UareUException e){ MessageBox.DpError("Reader.Open()", e); }

    boolean bOk = true;
    if(m_bStreaming){
        //check if streaming supported
        Reader.Capabilities rc = m_reader.GetCapabilities();
        if(!rc.can_stream){
            MessageBox.Warning("This reader does not support streaming");
            bOk = false;
        }
    }

    if(bOk){
        //start capture thread
        StartCaptureThread();

        //bring up modal dialog
        m_dlgParent = dlgParent;
        m_dlgParent.setContentPane(this);
        m_dlgParent.pack();
        m_dlgParent.setLocationRelativeTo(null);
        m_dlgParent.toFront();
        m_dlgParent.setVisible(true);
        m_dlgParent.dispose();

        //cancel capture
        StopCaptureThread();

        //wait for capture thread to finish
        WaitForCaptureThread();

    }

    //close reader
    try{
        m_reader.Close();
    }
    catch(UareUException e){ MessageBox.DpError("Reader.Close()", e); }
}

public static void Run(Reader reader, boolean bStreaming){
    JDialog dlg = new JDialog((JDialog)null, "Put your finger on the reader", true);
    Capture capture = new Capture(reader, bStreaming);
    capture.doModal(dlg);
}

}

Added by the OP in a comment responding to @LaurentY:

I think I found a way to save in image format using the class you have given me, by adding the code below after repaint ();

//saving file 
File png = new File ("C://Users//HP//Documents//.Fingerprints Iseng//"+x+".png");
try 
{ 
    ImageIO.write(m_image,"png",png); 
} 
catch (IOException ex) 
{ 
    Logger.getLogger(ImagePanel.class.getName()).log(Level.SEVERE, null, ex); 
} 
System.out.println("Done Saving.."); 

Solution

  • I think your code come from this repository https://github.com/ankit4u3/Digital-Persona

    In this repository there's a class to show image from Fid: https://github.com/ankit4u3/Digital-Persona/blob/master/src/ImagePanel.java

    Here the code:

    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    
    import javax.swing.JPanel;
    
    import com.digitalpersona.uareu.Fid;
    import com.digitalpersona.uareu.Fid.Fiv;
    
    public class ImagePanel extends JPanel {
        private static final long serialVersionUID = 5;
        private BufferedImage m_image;
    
        public void showImage(Fid image) {
            Fiv view = image.getViews()[0];
            m_image = new BufferedImage(view.getWidth(), view.getHeight(),
                    BufferedImage.TYPE_BYTE_GRAY);
            m_image.getRaster().setDataElements(0, 0, view.getWidth(),
                    view.getHeight(), view.getImageData());
            repaint();
        }
    
        @Override
        public void paint(Graphics g) {
            g.drawImage(m_image, 0, 0, null);
        }
    
    }