Skip to content
Advertisement

How can I convert fingerprint jpg to WSQ use JMRTD WSQEncoder.encode

I’m using JMRTD library (https://github.com/E3V3A/JMRTD/tree/master/wsq_imageio) to encode jpg to WSQ. I set Bitmap by manually instead of decode from WSQ file.

        BufferedImage bufferedImage = ImageIO.read(fileInput.getInputStream());
        WritableRaster raster = bufferedImage.getRaster();
        DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
        Bitmap bitmap = new Bitmap(data.getData(), width, height, ppi, depth, lossyflag);

        OutputStream outputStream = new FileOutputStream("c.wsq");
        String commentText = "";
        WSQEncoder.encode(outputStream, bitmap, bitrate, commentText);

Here is my original picture jpg:

enter image description here

And below is my result WSQ file:

enter image description here

How can I fix it. Many thanks!

Advertisement

Answer

I resolved this problem, here is my code for convert jpg, png to wsq format:

// 1. Read files to BufferedImage for get width, height. Convert Bit depth to 8-gray
BufferedImage bufferedImage = ImageIO.read(fileInput.getInputStream());

// 2. Convert Bit depth to 8-gray (This is what i had to do to solve this problem)
BufferedImage img = new BufferedImage(bufferedImage.getWidth(), bufferedImage.getHeight(), BufferedImage.TYPE_BYTE_GRAY);
Graphics g = img.getGraphics();
g.drawImage(bufferedImage, 0, 0, null);
g.dispose();

// 3. Convert file format to byte[] and convert to type Bitmap
WritableRaster raster = img.getRaster();
DataBufferByte data = (DataBufferByte) raster.getDataBuffer();
Bitmap bitmap = new Bitmap(data.getData(), bufferedImage.getWidth(), bufferedImage.getHeight(), 500, 8, 1);

// 4. Create file wsq
OutputStream outputStream = new FileOutputStream("c.wsq");
double bitrate = 0.75f;
String commentText = "";

// 5. Write the input file to the generated wsq file
WSQEncoder.encode(outputStream, bitmap, bitrate, commentText);
outputStream.close();

Hope help you @ Dan Ortega

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement