Spaces:
Sleeping
Sleeping
File size: 1,387 Bytes
7a253ad db5ea6e 7a253ad db5ea6e 4af5f5f 7a253ad db5ea6e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
---
title: TonAI-OCR
app_file: app.py
sdk: gradio
colorFrom: red
colorTo: blue
sdk_version: 4.44.0
---
# TonAI Text Recognition
### A simple OCR Python library
![ONNX](https://a11ybadges.com/badge?logo=onnx) ![Python](https://a11ybadges.com/badge?logo=python) ![PyPI](https://a11ybadges.com/badge?logo=pypi)
## Installation
install via PyPi
```
pip install ton-ocr
```
## Usage example
```
import cv2
import numpy as np
from ton_ocr import TonOCRPipeline
image_path = "stuffs/example.jpg"
image = cv2.imread(image_path)
ocr = TonOCRPipeline()
results = ocr.predict(image)
for result in results:
bbox = result.box # text bounding box
text = result.text # text string
score = result.score # OCR's confidence
img = result.img # cropped text image
# Draw the bounding polygon
points = np.array(bbox, np.int32)
points = points.reshape((-1, 1, 2))
color = (0, 255, 255)
is_closed = True
thickness = 2
cv2.polylines(image, [points], is_closed, color, thickness)
# Add OCR text to the image
font = cv2.FONT_HERSHEY_SIMPLEX
font_scale = 1
text_color = (0, 0, 255)
text_thickness = 2
first_point = tuple(points[0][0])
cv2.putText(image, text, first_point, font, font_scale, text_color, text_thickness)
cv2.imshow('Image Window', image)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
|