Coder Social home page Coder Social logo

mrz's Introduction

mrz

Parse MRZ (Machine Readable Zone) from identity documents.

Zakodium logo

Maintained by Zakodium

NPM version build status npm download

Installation

$ npm install mrz

Example

const parse = require('mrz').parse;

let mrz = [
  'I<UTOD23145890<1233<<<<<<<<<<<',
  '7408122F1204159UTO<<<<<<<<<<<6',
  'ERIKSSON<<ANNA<MARIA<<<<<<<<<<',
];

var result = parse(mrz);
console.log(result);

API

parse(mrz)

Parses the provided MRZ. The argument can be an array of lines or a single string including line breaks. This function throws an error if the input is in an unsupported format. It will never throw an error when there are invalid fields in the MRZ. Instead, the result.valid value will be false and details about the invalid fields can be found in result.details.

result.format

String identifying the format of the parsed MRZ. Supported formats are:

  • TD1 (identity card with three MRZ lines)
  • TD2 (identity card with two MRZ lines)
  • TD3 (passport)
  • SWISS_DRIVING_LICENSE
  • FRENCH_NATIONAL_ID

result.valid

true if all fields are valid. false otherwise.

result.fields

Object mapping field names to their respective value. The value is set to null if it is invalid. The value may be different than the raw value. For example result.fields.sex will be "male" when the raw value was "M".

result.details

Array of objects describing all parsed fields. Its structure is:

  • label {string} - Full english term for the field.
  • field {string} - Name of the field in result.fields.
  • value {string} - Value of the field or null.
  • valid {boolean}
  • ranges {Array} - Array of ranges that are necessary to compute this field. Ranges are objects with line, start, end and raw.
  • line {number} - Index of the line where the field is located.
  • start {number} - Index of the start of the field in line.
  • end {number} - Index of the end of the field in line.

formats

Static mapping of supported formats.

states

Static mapping of state code to state name.

Specifications

TD1, TD2 and TD3

https://www.icao.int/publications/pages/publication.aspx?docnum=9303

Swiss driving license

http://www.astra2.admin.ch/media/pdfpub/2003-10-15_2262_f.pdf

French national id

https://fr.wikipedia.org/wiki/Carte_nationale_d%27identit%C3%A9_en_France#Codage_Bande_MRZ_(lecture_optique)

License

MIT

mrz's People

Contributors

cheminfo-bot avatar locatellidaniel avatar lpatiny avatar opatiny avatar sebastien-ahkrin avatar stropitek avatar targos avatar wadjih-bencheikh18 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

mrz's Issues

interested dev

hello!! I'm looking potentially at using this library for a project with homeland security over the next few months. I'd love to support a public repo and was wondering if you guys needed any help as well as if there are any known issues outside of what's already publically identified.

also, there might be a chance that I use this library to make a react native vision camera plugin that parses an MRZ. if I do I'll be sure to credit this library :)

X gender is not valid?

I have the passport below (fake passport) with X gender. This X gender is not appearing as a valid passport.

P<GBRSTOKES<<CASSANDRE<<<<<<<<<<<<<<<<<<<<<<
2347894037GBR7901232X2301011<<<<<<<<<<<<<<06

I noticed we use < for unspecified gender. Do you know if X is also a valid gender or is the example above an error?

Support es5

Hi,

Is there any plans to support es5 syntax? Right now Webpack Uglify throws an error as const is being used.

I am happy to put in a pr if you're happy with it.

Possibility for autoCorrection

Some symbols are difficult to differentiate in the MRZ like the '0' or 'O'.

This PR https://github.com/cheminfo/mrz/pull/21/files#diff-f76f9fb30ec34fcebf47111d3562b71aa630be9dff89cd28fbc4d812ac2b61cbR39-R41 proposes to fix some mistakes as described specifically here:

https://github.com/cheminfo/mrz/pull/21/files#diff-f76f9fb30ec34fcebf47111d3562b71aa630be9dff89cd28fbc4d812ac2b61cbR39-R41

For us it is however important that this 'autoCorrection' is optional (second arguments in the methods, options={}) and that the end-user can be aware that it has been changed in the result.details.

This 'autoCorrection' should also work all the time it can. Meaning in TD1, TD2 and TD3 as well as from letters to numbers or from numbers to letters if a field can only contain one of the 2.

Cannot parse passport name fields with spaces in them

My passport has the following MRZ text on it:

P<CANEISENBERG<CANDREW DAVID<<<<<<<<<<<<<<<<
AC773749<3CAN7612220M2710257<<<<<<<<<<<<<<00

Notice the space between ANDREW and DAVID. The regex you are using to parse the name field looks like this:

/^[A-Z<]+<*$/

It does not accept spaces and therefore fails to parse the MRZ of the passport above. Things seem to work if I add a space to the regex, like so:

/^[A-Z< ]+<*$/

Want me to make a PR?

Chinese passport validation fails

We are using this awesome library to validate a few legit Chinese e-passports (TD3). I used the library's tests suite to verify many other countries but these Chinese ones all fail on the `personal number check digit´. Also notice on this example the document type is PO not just P.

I'm afraid I can't share any example as it's PII, so is there any way I can provide you more infomation without disclosing the individual?

image

Recover from last name being blank.

In some nationalities, it is valid for the last name to be blank. A bug in the parser results in an error.

Do you think this is something that could be fixed?

Add typedef for the result field

Currently the result is not really typed

image

The fields depends on the type of ID card and MRZ being analysed and it would be nice to have the type information in the result.

Linked to:

@mat2718 would you like to make a PR

Help with picture processing before extracting MRZ

Hi Guys,

I went over the resources you published and I was able to find a lot of solutions for some of the issues we are having with MRZ extraction.
I am contacting you to see if maybe you have find some good solutions for pre-processing an ID picture before the MRZ can be read. I have found that many users struggle to take a good enough picture of their IDs.
I am looking for somebody to help us setup a demo for a project.

In a Nutshell, We are setting up a demo for a project to ensure that only people above a certain age can register to an event and purchase tickets (for example: to a concert, to a festival etc.).
Our idea is to ask the user during the registration process to upload its ID containing an MRZ and that we check if the person is over 16, 18 etc.

Our requirements:
• The picture of the ID needs to be processed by our system and cannot be sent to an external system for security reasons (for example: not to https://www.ocrsdk.com).
• Our biggest constraint is that we cannot use a mobile APP (no Android APP, no IOS APP). At the moment our environment is spring with NGINX (Angular6, material design)
• The solution needs to work as a step in a normal registration website.
• We need to guarantee that the date of birth used for the check:
○ It is ok to stop the registration because the quality is not good enough
○ However it would be an automatic failure for our project if the extracted date of birth is wrong and we allow a 14 years old to register an over 18 event.

Our issues so far:
• There are plenty of solutions that work great with mobile APPs (ios, android). These solutions allow detecting that an image resolution is decent, that it is not blurry etc. However, we cannot ask a user to install an app for our project and are stuck with the Web approach.
• I am struggling to pre-process the picture so that it can be decent enough for the OCR (un-skew, rotate, resize)

Our demo would be:
1. User goes to our public website (does not exist yet)
2. User is requested to take or upload a picture in its web browser
a. ALT: If possible, he gets an hint if the picture is decent enough straight away (not to skewed, not to blurry, not too close, not too far etc.). He is asked to retry if the picture quality if not sufficient
3. The MRZ is processed (locally if possible or by our server).
4. The MRZ data is sent to our backend
5. The fields are pre-populated with the extracted information .
6. The front end blocks the registration if the user does not meet the minimum age requirement.

In a nutshell, we are looking for somebody who could help us with the part of consistent image processing and extraction of the MRZ. I was hoping that you could give us some pointers or even help us build this element of the demo for a fee. Alternatively if you could recommend us to somebody else that would be also great.

Cheers,

Miguel

Build fails with "unexpected token: punc ()" due to trailing commas

ERROR in 8.223393375e8f60301275.js from Terser
Unexpected token: punc ()) [./node_modules/mrz/src/parsers/swissDrivingLicense/checkSeparator.js:7,0][8.223393375e8f60301275.js:52,4]

This happens due to the trailing comma in function parameters, mostly (``throw new Error(text,)`), when target build is prior to es8.
Is there any reason to limit the usage of mrz to es8 builds and above?

I have personally fixed this with npx patch-package

Thanks

Invalid MRZ

The following example seems wrong

const MRZ = [
'I<UTOD23145890<1240<XYZ<<<<<<<',
'7408122F1204159UTO<<<<<<<<<<<8',
'ERIKSSON<<ANNA<MARIA<<<<<<<<<<',
];

While 1240 is correct and the 0 is the check digit, characters after the '<' (in this case XYZ) are not expected to be there.

We should add an example that fails (the current one) and a new one with the following MRZ

      'I<UTOD23145890<1240<<<<<<<<<<<',
      '7408122F1204159UTO<<<<<<<<<<<8',
      'ERIKSSON<<ANNA<MARIA<<<<<<<<<<',

Incompatibility with @types/mrz 3.1.1

Hi all.

I just updated mrz to the latest version and my typescript compiler now complains about the following error:
Namespace '"[...]/node_modules/mrz/lib/index"' has no exported member 'Result'.

my package.json contains the following entries:

"dependencies": {
		"mrz": "^3.3.0",
		[...]
	},
"devDependencies": {
		"@types/mrz": "^3.1.1",
		"typescript": "~4.9.5",
                 [...]
	}

and the faulting code is this one:

import * as mrz from 'mrz';

@Injectable({
	providedIn: 'root'
})
export class MrzReaderService {

  parse(mrzString: string): mrz.Result & { error?: string } {
    [...]
  }

[...]

}

Is there a solution to this problem other than using 'any' instead of 'mrz.Result' in the method parse( )?

Thanks a lot.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.