npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

document-mrz-scanner

v1.0.0

Published

Detect and extract MRZ (Machine Readable Zone) information from various types of document images, including identity documents, driver's licenses, passports, and more.

Downloads

17

Readme

document-mrz-scanner 🛂

Detect and extract MRZ (Machine Readable Zone) information using tesseract from various types of document images, including identity documents, driver's licenses, passports, and more.

Installation

Before you can use this module, you need to install tesseract dependency.

Linux

To install Tesseract run this command:

sudo apt-get install tesseract-ocr

Mac (Homebrew)

To install Tesseract run this command:

brew install tesseract

The tesseract directory can then be found using brew info tesseract , e.g. /usr/local/Cellar/tesseract/5.3.3/share/tessdata/

Other platforms

You can find the installation instructions here

yarn add document-mrz-scanner

Configration

Copy fast.traineddata file from node_modules/document-mrz-scanner/tessdata to tessdata directory of tesseract installation. To find the location of the tessdata directory run tesseract --list-langs and look for the tessdata directory. Once you have found the tessdata directory, copy the fast.traineddata file to the tessdata directory.

In the example above, the tessdata directory is /usr/local/Cellar/tesseract/5.3.3/share/tessdata/

Usage

Install the package:

yarn add document-mrz-scanner

Code usage

const documentMrzScanner = require('document-mrz-scanner');

const buffer = fs.readFileSync(path.join(__dirname, 'passport-test.png'));

const documentInformation = await mrzScanner.scan(buffer);

The scan function accepts a buffer of the image file and returns a promise that resolves to the MRZ data.

Example (Passport)

Passport

Output

{
  "format": "TD3",
  "details": [
    {
      "label": "Document code",
      "field": "documentCode",
      "value": "P",
      "valid": true,
      "ranges": [Array],
      "line": 0,
      "start": 0,
      "end": 1,
      "autocorrect": []
    },
    {
      "label": "Issuing state",
      "field": "issuingState",
      "value": null,
      "valid": false,
      "ranges": [Array],
      "line": 0,
      "start": 2,
      "end": 5,
      "autocorrect": [],
      "error": "invalid state code: UTO"
    },
    {
      "label": "Last name",
      "field": "lastName",
      "value": "ERIKSSON",
      "valid": true,
      "ranges": [Array],
      "line": 0,
      "start": 5,
      "end": 13,
      "autocorrect": []
    },
    {
      "label": "First name",
      "field": "firstName",
      "value": "ANNA MARIA",
      "valid": true,
      "ranges": [Array],
      "line": 0,
      "start": 15,
      "end": 25,
      "autocorrect": []
    },
    {
      "label": "Document number",
      "field": "documentNumber",
      "value": "L898902C3",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 0,
      "end": 9,
      "autocorrect": []
    },
    {
      "label": "Document number check digit",
      "field": "documentNumberCheckDigit",
      "value": "6",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 9,
      "end": 10,
      "autocorrect": []
    },
    {
      "label": "Nationality",
      "field": "nationality",
      "value": null,
      "valid": false,
      "ranges": [Array],
      "line": 1,
      "start": 10,
      "end": 13,
      "autocorrect": [],
      "error": "invalid state code: UTO"
    },
    {
      "label": "Birth date",
      "field": "birthDate",
      "value": "740812",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 13,
      "end": 19,
      "autocorrect": []
    },
    {
      "label": "Birth date check digit",
      "field": "birthDateCheckDigit",
      "value": "2",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 19,
      "end": 20,
      "autocorrect": []
    },
    {
      "label": "Sex",
      "field": "sex",
      "value": "female",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 20,
      "end": 21,
      "autocorrect": []
    },
    {
      "label": "Expiration date",
      "field": "expirationDate",
      "value": "120415",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 21,
      "end": 27,
      "autocorrect": []
    },
    {
      "label": "Expiration date check digit",
      "field": "expirationDateCheckDigit",
      "value": "9",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 27,
      "end": 28,
      "autocorrect": []
    },
    {
      "label": "Personal number",
      "field": "personalNumber",
      "value": "ZE184226B",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 28,
      "end": 37,
      "autocorrect": []
    },
    {
      "label": "Personal number check digit",
      "field": "personalNumberCheckDigit",
      "value": "1",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 42,
      "end": 43,
      "autocorrect": []
    },
    {
      "label": "Composite check digit",
      "field": "compositeCheckDigit",
      "value": "0",
      "valid": true,
      "ranges": [Array],
      "line": 1,
      "start": 43,
      "end": 44,
      "autocorrect": []
    }
  ],
  "fields": {
    "documentCode": "P",
    "issuingState": null,
    "lastName": "ERIKSSON",
    "firstName": "ANNA MARIA",
    "documentNumber": "L898902C3",
    "documentNumberCheckDigit": "6",
    "nationality": null,
    "birthDate": "740812",
    "birthDateCheckDigit": "2",
    "sex": "female",
    "expirationDate": "120415",
    "expirationDateCheckDigit": "9",
    "personalNumber": "ZE184226B",
    "personalNumberCheckDigit": "1",
    "compositeCheckDigit": "0"
  },
  "valid": false
}

License

MIT ©