Python Passport Validator v1.0

Introduction

In an increasingly digital world, the need for reliable and automated document verification is paramount. The Python Passport Validator v1.0 is a robust, Python-based tool designed to streamline the process of passport validation. By leveraging advanced OCR and face recognition technologies, this tool extracts, validates, and analyzes passport data directly from scanned images, making it an invaluable asset for developers, researchers, and organizations dealing with identity verification.


Key Features

  • MRZ Extraction & Parsing:

    • Utilizes Optical Character Recognition (OCR) to extract the Machine Readable Zone (MRZ) from passport images.
    • Parses MRZ data in accordance with the ICAO 9303 international standard.
  • Data Validation:

    • Implements the ICAO 9303 digit check algorithm to ensure the integrity of critical fields such as passport number, date of birth, and expiration date.
  • Country Recognition:

    • Maps ISO 3166-1 alpha-3 country codes to their official country names for clear, human-readable output.
  • Face Extraction:

    • Detects and extracts the passport holder's face from the image, saving it as a separate file (result.png).
  • Optional Data Handling:

    • Extracts and displays any optional data present in the MRZ, providing a comprehensive data snapshot.

Technology Stack

  • Language: Python
  • Core Libraries:
    • passporteye: For MRZ extraction and OCR.
    • face_recognition: For face detection and extraction.
    • pycountry: For country code mapping.
    • Pillow: For image processing and saving face crops.
    • Standard libraries: re (regular expressions), os (file operations).

Project Structure

main.py
passport_validators/
  ├── analyzer.py
  ├── face_detection.py
  └── __init__.py
README.md
LICENSE
.gitignore
  • main.py: Command-line entry point. Prompts for an image file, then runs MRZ analysis and face extraction.
  • passport_validators/analyzer.py: Contains the main class for MRZ extraction, parsing, validation, and data cleaning.
  • passport_validators/face_detection.py: Logic for detecting and saving the passport holder's face from the image.
  • README.md: User guide, usage examples, and library explanations.
  • LICENSE: GNU General Public License v3.0.

How It Works

  1. Input: The user provides a scanned image of a passport.
  2. MRZ Extraction: The tool uses OCR to locate and extract the MRZ from the image.
  3. Parsing & Validation: The MRZ is parsed according to ICAO 9303, and key fields are validated using the digit check algorithm.
  4. Country Mapping: The country code is translated to a full country name.
  5. Face Extraction: The passport holder's face is detected and saved as a separate image file.
  6. Output: All extracted and validated data, including optional fields, are displayed or saved as needed.

Example Usage

from passport_validators import analyzer, face_detection
passport_analyzer = analyzer.PassportMachineReadableZoneAnalyzer(file)
passport_analyzer.parse()
face_detection.recognize_passport_face(file)

Or simply run main.py and follow the prompt for the image file path.


Standards & Compliance

  • Adheres strictly to ICAO 9303 for MRZ layout and digit check algorithms.
  • Only parses and validates fields as per ICAO 9303; optional data is extracted but not further analyzed.

Licensing

This project is licensed under the GNU General Public License v3.0 (GPL-3.0), ensuring it remains free and open-source for the community.