RapidOCR-ONNXRuntime

1.4.4 · active · verified Sun Apr 12

RapidOCR-ONNXRuntime is a Python library providing cross-platform Optical Character Recognition (OCR) capabilities, leveraging the ONNX Runtime inference engine for high-speed and efficient offline deployments. It converts PaddleOCR models to the ONNX format, offering a performant solution for text recognition. The library supports multiple programming languages, with its Python interface primarily integrated into the broader RapidOCR ecosystem. The current PyPI version is 1.4.4, released in January 2025, and the associated GitHub project is actively maintained with frequent updates.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the RapidOCR engine and perform OCR on an image. The `RapidOCR` class handles model loading and inference using the ONNX Runtime backend provided by `rapidocr-onnxruntime`. The example downloads an image from a URL, processes it, and prints the detected text along with bounding box information.

from rapidocr import RapidOCR
from PIL import Image
import requests
from io import BytesIO

# Initialize the OCR engine
engine = RapidOCR()

# Example image URL (replace with your image path or URL)
img_url = "https://www.modelscope.cn/models/RapidAI/RapidOCR/resolve/master/resources/test_files/ch_en_num.jpg"

# Download and open the image
response = requests.get(img_url)
image = Image.open(BytesIO(response.content))

# Perform OCR
result = engine(image)

# Print the OCR results
print(result)

# Optionally, visualize the result (requires OpenCV installed and a display environment)
# import cv2
# import numpy as np
# image_np = np.array(image)
# for box, text, score in result:
#     box = np.array(box).astype(np.int32).reshape((-1, 1, 2))
#     cv2.polylines(image_np, [box], True, (0, 255, 0), 2)
#     cv2.putText(image_np, text, (box, box - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2)
# cv2.imshow("OCR Result", image_np)
# cv2.waitKey(0)
# cv2.destroyAllWindows()

view raw JSON →