Skip to main content

MRZ Passport Reader from Image

This project is an implementation of a Machine-Readable Zone (MRZ) reader from images using segmentation, face detection, and Optical Character Recognition (OCR). It leverages TensorFlow Lite models for segmentation, a Caffe model for face detection, and EasyOCR for text recognition.


Features

  • MRZ Detection: Automatically detects and segments the MRZ region in passport images.
  • Face Detection: Identifies and crops the face from the passport image.
  • OCR with EasyOCR: Extracts text from the segmented MRZ region.
  • Preprocessing: Optional preprocessing steps including skew correction, shadow removal, and background clearing to improve OCR accuracy.

Installation

Prerequisites

  • Python 3.10 or higher
  • Git installed

Install from GitHub

git clone https://github.com/devnbugs/xmrzapp.git
cd xmrzapp
pip install -e .


## Example Usage
```python

import cv2
from xmrz_reader import MRZReader

# Initialize the MRZReader
reader = MRZReader(
    facedetection_protxt="./xmrzapp/weights/face_detector/deploy.prototxt",
    facedetection_caffemodel="./xmrzapp/weights/face_detector/res10_300x300_ssd_iter_140000.caffemodel",
    segmentation_model="./xmrzapp/weights/mrz_detector/mrz_seg.tflite",
    easy_ocr_params={"lang_list": ["en"], "gpu": False}
)

# Load an image
image_path = "path_to_your_image.jpg"

# Perform MRZ reading with optional preprocessing and face detection
text_results, segmented_image, detected_face = reader.predict(
    image_path,
    do_facedetect=True,
    preprocess_config={
        "do_preprocess": False,
        "skewness": False,
        "delete_shadow": False,
        "clear_background": False
    }
)

# Display results
print("Recognized Text:")
for bbox, text, confidence in text_results:
    print(f"Bounding Box: {bbox}")
    print(f"Recognized Text: {text}")
    print(f"Confidence: {confidence:.2f}")
    print("-" * 50)

if detected_face is not None:
    print("Face detected in the image.")

# Show images
cv2.imshow("Segmented Image", segmented_image)
if detected_face is not None:
    cv2.imshow("Detected Face", detected_face)
cv2.waitKey(0)
cv2.destroyAllWindows()

Example Result





After you give this image to the models , you will take this result P<GBRUNITED<KINGDOM<FIVE<<JODIE<PIPPA<<<<<<<1071857032GBR8501178F1601312<<<<<<<<<<<<<<02 as a string. This study is a basic solution . Your image which you give should be clear, and it should cover whole area.



Metadata

Release files for xmrzapp 25.10.9

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for xmrzapp 25.10.9
File Size Uploaded
xmrzapp-25.10.9.tar.gz 16.0 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for xmrzapp 25.10.9
File Interpreter ABI Platform
xmrzapp-25.10.9-py3-none-any.whl Python 3 none any Details

Total release size: 30.9 MB

Release files / xmrzapp-25.10.9.tar.gz

Download URL xmrzapp-25.10.9.tar.gz
Size 16.0 MB
Tags Source
SHA-256 checksum
How to use checksums
1c805f34c6850e4e9f6f753537f9fda9bb8560591bceca35798817f5a9b3432a
BLAKE2b-256 checksum
How to use checksums
ada6c2c612e06e1feb3aa71a6390293396a1c77fedc6b182a678bb36a9336dbb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release files / xmrzapp-25.10.9-py3-none-any.whl

Download URL xmrzapp-25.10.9-py3-none-any.whl
Size 14.9 MB
Tags Python 3
SHA-256 checksum
How to use checksums
3520ee3b6591ffb0ec73ec5e94de36b5911fbf73117cc82bfe7523b6d806764c
BLAKE2b-256 checksum
How to use checksums
1e349c0860b395b30960c8282e5a8e44240d389abaabdfb53adc9a641ec20e97
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.13.7

Release history Release notifications | RSS feed

This release

25.10.9 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page