Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

node-nist support type? #30

Open
zergreen opened this issue May 27, 2024 · 7 comments
Open

node-nist support type? #30

zergreen opened this issue May 27, 2024 · 7 comments
Labels
question Further information is requested

Comments

@zergreen
Copy link

I'm use node-nist and it's work on type 1,2,4 to encode and decode.
my question is this project has support other type like
Type-10 (Facial & SMT Image), Type-13 (Variable-Resolution Latent Image), Type-14 (Variable-Resolution Fingerprint Image)

and next question.

In the future is you planning to support this or not?

@ivosh ivosh added the question Further information is requested label May 27, 2024
@ivosh
Copy link
Owner

ivosh commented May 27, 2024

Hi @zergreen, Type-10, Type-13, Type-14 are all supported:
https://github.com/ivosh/node-nist?tab=readme-ov-file#limitations

What exactly is your use case and what do you think is not working?

@zergreen
Copy link
Author

zergreen commented Jun 2, 2024

I occur problem, when try to encode type 10,
Screenshot 2567-06-02 at 14 29 13

with the same image (.wsq) , I had replace to encode with type 4,(as you can see on line 25 , I replace '10' to '4'), for make sure it's work only type 4
and output not get an error anymore.
the console output:
image

And make sure, is .nist can view it's can see data by website : https://www.netxsolutions.co.uk/onlineNISTViewer.aspx

Screenshot 2567-06-02 at 14 33 07

as you can see, the record type 4 must be the fingerprint file, but I want to show you that's your code it's work only type 4, 2,1

for your information : I dont know as much what's you code configuration setting , I use as default.
it's you has a sample code to encode with other type than type 1,2,4 , that's you provide on this git.

if you had a demo or example code, can you show me , please.

@zergreen
Copy link
Author

zergreen commented Jun 2, 2024

this is my code to implement.

const fs = require("fs");
const { nistEncode, nistDecode, NistFile } = require("node-nist");

// Read the .wsq file as a binary buffer
const buffer1 = fs.readFileSync("left.wsq");
const buffer2 = fs.readFileSync("center.wsq");
const buffer3 = fs.readFileSync("right.wsq");

const nist = {
  1: {
    2: "0300",
    4: "IDN",
    5: "20190722",
    7: "ABIS",
    8: "MID00001",
    9: "SEN20190722093422-IDE-00040",
    10: "UTF-8",
    11: "1",
  },
  2: {
    4: "พงศกร",
    5: "กาเหว่าลาย",
    7: "2024-05-12",
  },
  4: [
    {
      3: "0",
      4: ["0"],
      5: "0",
      6: "1536",
      7: "2048",
      8: "1",
      9: buffer1,
    },
    {
      3: "1",
      4: ["1"],
      5: "1",
      6: "1536",
      7: "2048",
      8: "1",
      9: buffer2,
    },
    {
      3: "2",
      4: ["2"],
      5: "2",
      6: "1536",
      7: "2048",
      8: "1",
      9: buffer3,
    },
  ],
};

// Encode the data into a buffer
const encodeResult = nistEncode(nist, {});
if (encodeResult.tag === "success") {
  const buffer = encodeResult.value;

  // Save the buffer to a file
  fs.writeFile("myNistFile.nist", buffer, (err) => {
    if (err) {
      console.error("Error writing file:", err);
    } else {
      console.log("Successfully wrote .nist file to disk.");

      // Decode the NIST file
      decodeNistFile("myNistFile.nist");
    }
  });
} else {
  console.error("Error encoding NIST data:", encodeResult.error);
}

// Function to decode the NIST file
function decodeNistFile(filePath) {
  fs.readFile(filePath, (err, data) => {
    if (err) {
      console.error("Error reading file:", err);
      return;
    }

    const decodeResult = nistDecode(data);
    if (decodeResult.tag === "success") {
      const decodedData = decodeResult.value;
      console.log("Decoded NIST data:", decodedData);
    } else {
      console.error("Error decoding NIST data:", decodeResult.error);
    }
  });
}

@ivosh
Copy link
Owner

ivosh commented Jun 2, 2024

Hi @zergreen thank you for describing the issue and providing the reproducer. Especially the reproducer helped me a great deal to understand what you are trying to achieve.

My comments:

  1. Use Typescript for your code. It has many benefits and it would have already showed you the way to solve your issue.
  2. You need to understand ANSI/NIST-ITL 1-2011 standard to at least some extent so that you can put the right information into the right fields.
  3. In your reproducer, you cannot simply exchange Type-4 with Type-10 without updating the affected fields at the same time. This is not how ANSI/NIST-ITL 1-2011 standard works.

I am attaching your reproducer. Here is the error which Typescript would give you about a problem when simply changing Type-4 to Type-10 without doing anything else:

> tsc

reproducer.ts:57:33 - error TS2345: Argument of type '{ 1: { 2: string; 4: string; 5: string; 7: string; 8: string; 9: string; 10: string; 11: string; }; 2: { 4: string; 5: string; 7: string; }; 10: { 3: string; 4: string[]; 5: string; 6: string; 7: string; 8: string; 9: Buffer; }[]; }' is not assignable to parameter of type 'NistFile'.
  Types of property '10' are incompatible.
    Type '{ 3: string; 4: string[]; 5: string; 6: string; 7: string; 8: string; 9: Buffer; }[]' is not assignable to type 'NistType10Record[]'.
      Type '{ 3: string; 4: string[]; 5: string; 6: string; 7: string; 8: string; 9: Buffer; }' is missing the following properties from type 'NistType10Record': 10, 11, 12, 999

57 const encodeResult = nistEncode(nist, {});
                                   ~~~~
Found 1 error in reproducer.ts:57

and here is the reproducer converted to Typescript:

import * as fs from 'fs';
import { nistEncode, nistDecode } from 'node-nist';

// Read the .wsq file as a binary buffer
const buffer1 = fs.readFileSync('left.wsq');
const buffer2 = fs.readFileSync('center.wsq');
const buffer3 = fs.readFileSync('right.wsq');

const nist = {
  1: {
    2: '0300',
    4: 'IDN',
    5: '20190722',
    7: 'ABIS',
    8: 'MID00001',
    9: 'SEN20190722093422-IDE-00040',
    10: 'UTF-8',
    11: '1',
  },
  2: {
    4: 'พงศกร',
    5: 'กาเหว่าลาย',
    7: '2024-05-12',
  },
  10: [
    {
      3: '0',
      4: ['0'],
      5: '0',
      6: '1536',
      7: '2048',
      8: '1',
      9: buffer1,
    },
    {
      3: '1',
      4: ['1'],
      5: '1',
      6: '1536',
      7: '2048',
      8: '1',
      9: buffer2,
    },
    {
      3: '2',
      4: ['2'],
      5: '2',
      6: '1536',
      7: '2048',
      8: '1',
      9: buffer3,
    },
  ],
};

// Encode the data into a buffer
const encodeResult = nistEncode(nist, {});
if (encodeResult.tag === 'success') {
  const buffer = encodeResult.value;

  // Save the buffer to a file
  fs.writeFile('myNistFile.nist', buffer, (err) => {
    if (err) {
      console.error('Error writing file:', err);
    } else {
      console.log('Successfully wrote .nist file to disk.');

      // Decode the NIST file
      decodeNistFile('myNistFile.nist');
    }
  });
} else {
  console.error('Error encoding NIST data:', encodeResult.error);
}

// Function to decode the NIST file
const decodeNistFile = (filePath: string) => {
  fs.readFile(filePath, (err, data) => {
    if (err) {
      console.error('Error reading file:', err);
      return;
    }

    const decodeResult = nistDecode(data);
    if (decodeResult.tag === 'success') {
      const decodedData = decodeResult.value;
      console.log('Decoded NIST data:', decodedData);
    } else {
      console.error('Error decoding NIST data:', decodeResult.error);
    }
  });
};

That said, I am available to help you with either consultancy or development, depending on your needs. Contact me via email in case you are interested.

@zergreen
Copy link
Author

zergreen commented Jun 3, 2024

Thanks for your asking me. I'm so sorry to furry to you.
I face this problem around 1 month.

now, I had found way to implement this.

Screenshot 2567-06-03 at 16 30 07

by your helping guide and Claude.ai

this is my code to encode with record type 10.

import * as fs from 'fs';
import { nistEncode, nistDecode } from 'node-nist';

// Read the .wsq file as a binary buffer
const buffer1 = fs.readFileSync('left.wsq');
const buffer2 = fs.readFileSync('center.wsq');
const buffer3 = fs.readFileSync('right.wsq');

const nist = {
    1: {
      2: '0300',
      4: 'IDN',
      5: '20190722',
      7: 'ABIS',
      8: 'MID00001',
      9: 'SEN20190722093422-IDE-00040',
      10: 'UTF-8',
      11: '1',
    },
    2: {
      4: 'พงศกร',
      5: 'กาเหว่าลาย',
      7: '2024-05-12',
    },
    10: [
      {
        3: '0',
        4: '0',
        5: '0',
        6: '1536',
        7: '2048',
        8: '1',
        9: '1',
        10: '1',
        11: '1',
        12: '1',
        999: fs.readFileSync('left.wsq'),
      },
      {
        3: '1',
        4: '1',
        5: '1',
        6: '1536',
        7: '2048',
        8: '1',
        9: '1',
        10: '1',
        11: '1',
        12: '1',
        999: fs.readFileSync('right.wsq'),
      },
      {
        3: '2',
        4: '2',
        5: '2',
        6: '1536',
        7: '2048',
        8: '1',
        9: '1',
        10: '1',
        11: '1',
        12: '1',
        999: fs.readFileSync('center.wsq'),
      },
    ],
  };

// Encode the data into a buffer
const encodeResult = nistEncode(nist, {});
if (encodeResult.tag === 'success') {
  const buffer = encodeResult.value;

  // Save the buffer to a file
  fs.writeFile('myNistFile.nist', buffer, (err) => {
    if (err) {
      console.error('Error writing file:', err);
    } else {
      console.log('Successfully wrote .nist file to disk.');

      // Decode the NIST file
      decodeNistFile('myNistFile.nist');
    }
  });
} else {
  console.error('Error encoding NIST data:', encodeResult.error);
}

// Function to decode the NIST file
const decodeNistFile = (filePath: string) => {
  fs.readFile(filePath, (err, data) => {
    if (err) {
      console.error('Error reading file:', err);
      return;
    }

    const decodeResult = nistDecode(data);
    if (decodeResult.tag === 'success') {
      const decodedData = decodeResult.value;
      console.log('Decoded NIST data:', decodedData);
    } else {
      console.error('Error decoding NIST data:', decodeResult.error);
    }
  });
};

and so do on this is my script for decode.

import * as fs from 'fs';
import { nistDecode } from 'node-nist';

// Function to decode the NIST file
const decodeNistFile = (filePath: string) => {
  fs.readFile(filePath, (err, data) => {
    if (err) {
      console.error('Error reading file:', err);
      return;
    }

    const decodeResult = nistDecode(data);
    if (decodeResult.tag === 'success') {
      const decodedData = decodeResult.value;
      console.log('Decoded NIST data:', decodedData);

      // Access and process the Type-10 records
      const type10Records = decodedData[10];
      if (type10Records && type10Records.length > 0) {
        type10Records.forEach((record, index) => {
          console.log(`Type-10 Record ${index + 1}:`);
          console.log('  Field 3 (Image Type):', record[3]);
          console.log('  Field 4 (Source Agency):', record[4]);
          console.log('  Field 5 (Capture Date):', record[5]);
          console.log('  Field 6 (Horizontal Line Length):', record[6]);
          console.log('  Field 7 (Vertical Line Length):', record[7]);
          console.log('  Field 8 (Scale Units):', record[8]);
          console.log('  Field 9 (Transmitted Data):', record[9]);
          console.log('  Field 10 (Compression Algorithm):', record[10]);
          console.log('  Field 11 (Compression Ratio):', record[11]);
          console.log('  Field 12 (Color Space):', record[12]);
          console.log('  Field 999 (Image Data):', record[999]);

          // Save the facial image data to a file
          const imageData = record[999];
          if (imageData) {
            fs.writeFileSync(`facial_image_${index + 1}.png`, imageData);
            console.log(`Saved facial image ${index + 1} as facial_image_${index + 1}.png`);
          }
        });
      } else {
        console.log('No Type-10 records found in the NIST file.');
      }
    } else {
      console.error('Error decoding NIST data:', decodeResult.error);
    }
  });
};


// Usage example
const filePath = 'myNistFile.nist';
decodeNistFile(filePath);
Screenshot 2567-06-03 at 07 18 27

as from the left side it's has three file with .wsq and .png , If we use .wsq we must to decode it.

I had just know record type 10 is support file image directly encode.

@ivosh thanks for your reply me, If you not guidance me, I must struggle and give up to this project.

so do on , I will provide you with the project that's I had to implement with your program library node-nist.

thanks you so much. to make this library

@zergreen
Copy link
Author

zergreen commented Jun 3, 2024

Sample of My Web Software Service , That's has implement with your library.

For people who interest, And want to try node-nist, I will publish my project on my GitHub. In soon. It's nearly to 100% work.
In soon coming.

Screenshot 2567-06-03 at 07 27 06 Screenshot 2567-06-03 at 07 28 04 Screenshot 2567-06-03 at 07 28 09 Screenshot 2567-06-03 at 07 28 15 Screenshot 2567-06-03 at 07 29 32 Screenshot 2567-06-03 at 07 29 51 Screenshot 2567-06-03 at 07 43 13

@ivosh
Copy link
Owner

ivosh commented Jun 3, 2024

@zergreen Thank you for sharing details about your project.
What is actually your use case and the customer?
Are you implementing a NIST file viewer and editor or is your project a part of a larger ecosystem?
What would be the source of the NIST files? For example do you have some AFIS systems to connect to?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants