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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file openmlkitocr-1.0.0.tar.gz.
File metadata
- Download URL: openmlkitocr-1.0.0.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
23b8cd92e1487193c8354af4ae5c09fe60a2be064716f536ab36f286d39c6c66
|
|
| MD5 |
549bd59fb271f8c8ec26b5c1ff1dd4a1
|
|
| BLAKE2b-256 |
6a25b899b0662b16830c685d05ebbf59f42979574bcfa59b79497e0766ca326e
|
File details
Details for the file openmlkitocr-1.0.0-py3-none-any.whl.
File metadata
- Download URL: openmlkitocr-1.0.0-py3-none-any.whl
- Upload date:
- Size: 16.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b2c74e651128643a72eb7a3a3629e6d5235f41b0ee10954446de81d78c66070c
|
|
| MD5 |
b61150e68da1d0a6f7abb0496606bcd6
|
|
| BLAKE2b-256 |
1e8e15a5d9fb8bf92b6068e196f94bef50ffd344bdbb3df382fb07a57e2e7f9e
|