Convert Fingerprint Image to Template with Java

Issue

I am trying to convert a fingerprint image with format jpg to a template using the library
SourceAFIS
https://sourceafis.machinezoo.com/

But I am receiving a few bytes that doesn’t look like template (Minutiae data), any suggestions to achieve this goal?

   File[] images = directory.listFiles();
            File desiredfile = null;
            for (File file : images) {
                if (file.getName().equals("images.jpg")) {
                    desiredfile = file;
                    break;
                }
            }
     FingerprintTemplate template = null;
                        if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.O) {
                            template = new FingerprintTemplate(
                                    new FingerprintImage(
                                            Files.readAllBytes(desiredfile.toPath()),
                                            new FingerprintImageOptions()
                                                    .dpi(500)));
                        }
                        fileLogger.log("template " + template.toByteArray());

Conclusion:
It seems the minutiae data is hidden and we can not see the actual bytes, the library aims to use the template object for matching process.

Solution

Code should be like this.

Make sure to replace "path/to/fingerprint/images.jpg" with the actual path to your fingerprint image. The code now includes error handling for file-related operations and logs the template size to the console.

public class FingerprintConverter {
        public static void main(String[] args) {
            // Replace "path/to/fingerprint/images.jpg" with the actual image file path
            String imagePath = "path/to/fingerprint/images.jpg";
            
            Path imagePath = Paths.get(imagePath);
            if (!Files.exists(imagePath) || !Files.isRegularFile(imagePath) || !Files.isReadable(imagePath)) {
                System.err.println("Invalid image file: " + imagePath);
                return;
            }
    
            try {
                byte[] imageBytes = Files.readAllBytes(imagePath);
    
                // Step 3: Extract the fingerprint template
                FingerprintImage fingerprintImage = new FingerprintImage(
                        imageBytes,
                        new FingerprintImageOptions().dpi(500)
                );
    
                FingerprintTemplate template = new FingerprintTemplate(fingerprintImage);
    
                // Logging template information
                System.out.println("Template size: " + template.toByteArray().length + " bytes");
    
            } catch (IOException e) {
                System.err.println("Error reading image file: " + e.getMessage());
            }
        }
    }

Answered By – Bhavik Nathani

Answer Checked By – Cary Denson (FlutterFixes Admin)

Leave a Reply

Your email address will not be published. Required fields are marked *