Skip to main content

A lightweight offline OCR library using Google ML Kit TFLite models

Project description

OpenMLkit OCR

A lightweight, offline Python OCR (Optical Character Recognition) library utilizing highly optimized, mobile-ready Google ML Kit TFLite models. It performs text detection using a Region Proposal Network (RPN) and line recognition using a CRNN-CTC architecture.


Features

  • Fully Offline: Runs entirely local, no API keys or internet connection required after downloading models.
  • Multilingual Support: Supports 15+ languages and scripts (Cyrillic/Russian, Latin/English, Chinese, Japanese, Korean, Arabic, Hebrew, and various Indian scripts).
  • Auto-downloading: Automatically downloads and caches required models from Hugging Face if they are not present locally.
  • High Quality Stitching: Handles wide text lines without squishing by dividing them into overlapping chunks and merging them using fuzzy suffix-prefix alignment.

Installation

Install the package directly using pip:

pip install openmlkitOCR

Or install from source:

git clone https://github.com/0cve0/OpenMLkitOCR.git
cd OpenMLkitOCR
pip install -e .

Quick Start

import os
import cv2
from openmlkit import OpenMLKitOCR

# Configure Hugging Face model source (or use defaults)
os.environ["OPENMLKIT_MODEL_REPO"] = "0cve0/OpenMLKitOCR"

# Initialize OCR pipeline for Cyrillic (Russian) text
ocr = OpenMLKitOCR(lang='ru')

# Load image
img = cv2.imread("scratch/russian_test.png")

# Run OCR (detect and recognize text)
results = ocr.run(img, score_threshold=0.35)

# Output results
for r in results:
    print(f"Box: {r['box']} -> Text: {r['text']}")

Project Structure

  • openmlkit/ - Core Python package directory.
    • detector.py - RPN text detection logic.
    • recognizer.py - CRNN text recognition logic.
    • labelmap.py - Parse binary protobuf label maps.
    • pipeline.py - OCR pipeline joining detection, tiling, and recognition.

License

This project is licensed under the Apache 2.0 License. The model weights are subject to Google's terms and licenses for ML Kit.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

openmlkitocr-1.0.1.tar.gz (16.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

openmlkitocr-1.0.1-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

Details for the file openmlkitocr-1.0.1.tar.gz.

File metadata

  • Download URL: openmlkitocr-1.0.1.tar.gz
  • Upload date:
  • Size: 16.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for openmlkitocr-1.0.1.tar.gz
Algorithm Hash digest
SHA256 a3dfed61dee4cc427a1754fa18a9373777ae6b25943a685981363943ab777596
MD5 4670ea70806bc6f5f031eb924e4ffe1e
BLAKE2b-256 a22668b828976a1c0866c54bef2bfe90baa05514197af11bd857156b597f7b22

See more details on using hashes here.

File details

Details for the file openmlkitocr-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: openmlkitocr-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 16.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.5

File hashes

Hashes for openmlkitocr-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 36602a729875ae0095847d7faa8d0d95a58ed7412c3102f3071254a2266b9c8a
MD5 518420f3611b3819357d2767b6c5e260
BLAKE2b-256 c2a74918986b7659b639ff8b8d938bf2a68a2a4bc0c8df7473e4abc740b03cfa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page