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.3.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.3-py3-none-any.whl (16.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: openmlkitocr-1.0.3.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.3.tar.gz
Algorithm Hash digest
SHA256 323a325abfb645b4f51e5a8dc832c53474a6a6fb17d9f6d49659bf396126feed
MD5 44996077ed1c5fe1ac13067e28c6f519
BLAKE2b-256 a97570c73943366b98e22f90a557bcd7f3be06947489751f19fd04281e630ba8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: openmlkitocr-1.0.3-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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e0c3a506a23f0554a80b870b3779fa8a81dd945d08a7aad02f82aa157f621f8a
MD5 f6fdde607f46f1fb74bf17c0669eb7ea
BLAKE2b-256 bab40234f4946af69278bf0858694c651c0a456036e77d1bc7419ddabeace7e9

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