Skip to main content

openocry: An Open-Source Toolkit for General-OCR Research and Applications

Note: openocry is a Python library adapted from OpenOCR, packaged with a unified openocr command-line and Python API (from openocr import OpenOCR).

For More Information

Recent Updates

  • 0.1.19: Release openocry Python package based on OpenOCR (pip install openocry==0.1.19).
  • 0.1.5: Support the PDF file as an input; Parallel recognition of document elements; Add skill document
  • 0.1.3: Use a unified interface for OCR, Document Parsing, and Unirec
  • 0.0.10: Remove OpenCV version restrictions.
  • 0.0.9: Fixing torch inference bug.
  • 0.0.8: Automatic Downloading ONNX model.
  • 0.0.7: Releasing the feature of ONNX model export for wider compatibility.

Quick Start Guide

Installation

# Install from PyPI (recommended)
pip install openocry==0.1.19

# Or install from source
git clone https://github.com/GreyRaphael/openocry.git
cd openocry
python build_package.py
pip install ./build/dist/openocry-*.whl

Command Line Usage

1. Text Detection + Recognition (OCR)

End-to-end OCR for Chinese/English text detection and recognition:

# Basic usage
openocr --task ocr --input_path path/to/img

# With visualization
openocr --task ocr --input_path path/to/img --is_vis

# Process directory with custom output
openocr --task ocr --input_path ./images --output_path ./results --is_vis

# Use server mode (higher accuracy)
pip install torch torchvision
openocr --task ocr --input_path path/to/img --mode server --backend torch

2. Text Detection Only

Detect text regions without recognition:

# Basic detection
openocr --task det --input_path path/to/img

# With visualization
openocr --task det --input_path path/to/img --is_vis

# Use polygon detection (more accurate for curved text)
openocr --task det --input_path path/to/img --det_box_type poly

3. Text Recognition Only

Recognize text from cropped word/line images:

# Basic recognition
openocr --task rec --input_path path/to/img

# Use server mode (higher accuracy)
pip install torch torchvision
openocr --task rec --input_path path/to/img --mode server --backend torch

# Batch processing
openocr --task rec --input_path ./word_images --rec_batch_num 16

4. Universal Recognition (UniRec)

Recognize text, formulas, and tables using Vision-Language Model:

# Basic usage
openocr --task unirec --input_path path/to/img

# Process directory
openocr --task unirec --input_path ./images --output_path ./results

5. Document Parsing (OpenDoc)

Parse documents with layout analysis, table/formula/table recognition:

# Full document parsing with all outputs
openocr --task doc --input_path path/to/img --use_layout_detection --save_vis --save_json --save_markdown

# Parse PDF document
openocr --task doc --input_path document.pdf --use_layout_detection --save_vis --save_json --save_markdown

# Custom layout threshold
openocr --task doc --input_path path/to/img --use_layout_detection --save_vis --save_json --save_markdown --layout_threshold 0.5

Launch Interactive Demos

# Install gradio
pip install gradio

OCR Demo

Launch Gradio web interface for OCR tasks:

# Local access only
openocr --task launch_openocr_demo --server_port 7860

# Public share link
openocr --task launch_openocr_demo --server_port 7860 --share

UniRec Demo

Launch Gradio web interface for universal recognition:

openocr --task launch_unirec_demo --server_port 7861 --share

OpenDoc Demo

Launch Gradio web interface for document parsing:

openocr --task launch_opendoc_demo --server_port 7862 --share

Python API Usage

OCR Task

import json
from openocr import OpenOCR

# Initialize OCR engine
ocr = OpenOCR(task='ocr', mode='mobile')

# Process single image
results, time_dicts = ocr(
    image_path='path/to/image.jpg',
    save_dir='./output',
    is_visualize=True
)

# Access results
for result in results:
    image_name, ocr_result = result.split('\t')
    ocr_result = json.loads(ocr_result)
    print(f"✅ OCR: {image_name} results: {ocr_result}")

Detection Task

from openocr import OpenOCR

# Initialize detector
detector = OpenOCR(task='det')

# Detect text regions
results = detector(image_path='path/to/image.jpg')

# Access detection boxes
boxes = results[0]['boxes']
print(f"Found {len(boxes)} text regions")

Recognition Task

from openocr import OpenOCR

# Initialize recognizer
recognizer = OpenOCR(task='rec', mode='server', backend='torch') # pip install torch torchvision

# Recognize text
results = recognizer(image_path='path/to/word.jpg')

# Access recognition result
text = results[0]['text']
score = results[0]['score']
print(f"Text: {text}, Confidence: {score}")

UniRec Task

from openocr import OpenOCR

# Initialize UniRec
unirec = OpenOCR(task='unirec')

# Recognize text/formula/table
result_text, generated_ids = unirec(
    image_path='path/to/image.jpg',
    max_length=2048
)
print(f"Result: {result_text}")

Document Parsing Task

from openocr import OpenOCR

# Initialize OpenDoc
doc_parser = OpenOCR(
    task='doc',
    use_layout_detection=True,
)

# Parse document
result = doc_parser(image_path='path/to/document.jpg')

# Save results
doc_parser.save_to_markdown(result, './output')
doc_parser.save_to_json(result, './output')
doc_parser.save_visualization(result, './output')

Common Parameters

  • --task: Task type (ocr, det, rec, unirec, doc, launch_*_demo)
  • --input_path: Input image/PDF path or directory
  • --output_path: Output directory (default: openocr_output/{task})
  • --use_gpu: GPU usage (auto, true, false)
  • --mode: Model mode (mobile, server) - server mode has higher accuracy
  • --is_vis: Visualize results
  • --save_vis: Save visualization (doc task)
  • --save_json: Save JSON results (doc task)
  • --save_markdown: Save Markdown results (doc task)

Output Structure

Results are saved to openocr_output/{task}/ by default:

  • OCR task: ocr_results.txt + visualization images (if --is_vis)
  • Detection task: det_results.txt + visualization images (if --is_vis)
  • Recognition task: rec_results.txt
  • UniRec task: unirec_results.txt
  • Doc task: JSON files, Markdown files, visualization images (based on flags)

Metadata

Release files for openocry 0.1.23

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

Source distribution (sdist)

Source distribution for openocry 0.1.23
File Size Uploaded Provenance Actions
openocry-0.1.23.tar.gz 462.4 kB With provenance Details for openocry-0.1.23.tar.gz

Built distribution (wheel)

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

Total release size: 1.2 MB

Release files / openocry-0.1.23.tar.gz

Download URL openocry-0.1.23.tar.gz
Size 462.4 kB
Tags Source
SHA-256 checksum
How to use checksums
af32aa94111d905a2d90a628056b909637012126ee562e77a6c356800cd37e5c
BLAKE2b-256 checksum
How to use checksums
01bae0982fa9b2f610d5a3f6c3145f4060cc58f040e20418236257b4f8106725
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 18, 2026.

Transparency log

Release files / openocry-0.1.23-py3-none-any.whl

Download URL openocry-0.1.23-py3-none-any.whl
Size 714.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
473d71bb67888aef650d896231fc3afabedac5b77a46dec4bf40387bc86a65d1
BLAKE2b-256 checksum
How to use checksums
30a43d5627769288fbf838a4b1feb65277506e4b6dbdfefbd04b30f395775c67
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.12

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 18, 2026.

Transparency log

Security for openocry 0.1.23

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for openocry-0.1.23.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 18, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

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