# myhub/tr Offline Chinese OCR SDK for Scanned Documents

> myhub/tr is an offline OCR SDK with C++ and Python interfaces for detecting and recognizing Chinese text in scanned documents. It targets a documented Linux environment, while its README says maintenance will pause and lists substantial platform constraints.

**myhub/tr** — Free Offline OCR 离线的中文文本检测+识别SDK

- Repository: https://github.com/myhub/tr
- Website: https://github.com/myhub/tr
- Stars: 1,384 · Forks: 386
- Language: Python
- License: not declared
- Published: 2026-10-16 · Updated: 2026-10-16 · Language: en
- Canonical page: https://hysenlabs.com/projects/myhub-tr

## Why tr Fits Offline Scanned-Document Workloads

myhub/tr addresses a specific OCR problem: extracting Chinese text from scanned documents without sending image data to an online service. Its documented audience is developers who need a local text-detection and recognition SDK, particularly applications that already run on Linux and can ship the required model resources.

The repository describes a C++ core with Python 2 and Python 3 interfaces. The Python examples focus on detecting text lines, recognizing an existing line image, and running both stages over a complete image. This scope suits applications that need OCR as one component of a larger workflow. The README does not document layout analysis, table reconstruction, form-field extraction, or semantic document parsing, so those should not be assumed.

The project also has an unusual maintenance position. The README says that tr has largely completed its original purpose and will become research-oriented. A separate notice says maintenance will pause while the authors focus on Transformer technology. The repository is not archived, and the last push was on 2026-10-11. That repository activity does not establish a support schedule when the README explicitly describes a maintenance pause. Teams should therefore treat tr as a documented SDK whose future maintenance is uncertain.

## How tr Detects and Recognizes Text

The Python API separates detection and recognition. `tr.detect` accepts an image path and a detection flag. With `tr.FLAG_RECT`, the README says it returns tuples containing `(cx, cy, width, height, angle)`. With `tr.FLAG_ROTATED_RECT`, it returns detection results that include angle information. The geometry gives callers a center point, width, height, and angle for each detected text line.

`tr.recognize` accepts a text-line image and returns `(text, confidence)`. This separation allows an application to reuse recognition on a crop produced by another detector, or to inspect detection results before spending work on recognition. `tr.run` combines the two operations and returns a list whose entries contain the detection geometry, recognized text, and confidence.

The repository includes `ChatCRNN/`, `TransformerDecoder/`, `tr/`, and `tr_gpu/`. The C++ example initializes the SDK with `crnn.bin`, which shows that model assets are part of deployment. The README does not document the complete preprocessing pipeline, character dictionary, network graph, confidence range, or line-ordering rules. Those details matter when an application must interpret coordinates or set a confidence threshold.

The C++ example follows this sequence:

```cpp
tr_init(0, 0, "crnn.bin", NULL);

#define MAX_WIDTH 512
int unicode[MAX_WIDTH];
float prob[MAX_WIDTH];

auto ws = tr_recognize(0, (void *)"line.png", 0, 0, 0,
                       unicode, prob, MAX_WIDTH);

tr_release(0);
```

The example demonstrates initialization, recognition, buffer allocation, and release. It does not explain every argument accepted by `tr_recognize`, so native integrations should follow the repository API rather than infer missing parameters from this short example.

## Installing tr and Running the Documented Tests

The README names Ubuntu 16.04 as the build environment. It requires Python 2 or Python 3 and numpy, and explicitly excludes Windows, CentOS 6, and ARM. It also states that `opencv-python` and Pillow dependencies were removed to reduce deployment difficulty. The supported environment is therefore narrower than the broad label "offline SDK" suggests.

The repository installation command is:

```bash
git clone https://github.com/myhub/tr.git
cd ./tr
sudo python setup.py install
```

An alternative documented installation uses pip and the default branch:

```bash
sudo pip install git+https://github.com/myhub/tr.git@master
```

The README does not provide pinned versions, a virtual-environment procedure, or a modern build alternative. It also does not explain whether a release tag is preferred over `master`. The repository's `setup.py` declares package version `2.3.1`, while the release history lists `2.8.2`, `2.8.1`, and `2.6.1`. An application should record the exact repository revision and installed package metadata rather than relying on the version string alone.

The documented test commands are:

```bash
python2 demo.py
python3 test.py
python3 test-multi-thread.py
python3 test_crnn_pyqt5.py
```

The README identifies these as a Python 2 compatibility test, a visualization test, a multithreading test, and a screenshot-recognition example. It does not specify expected console output, so the test should be evaluated by whether the documented process completes and by inspecting the visual output it produces.

## A First Python Call on Local Images

The README gives a direct first-use example using local image paths. Run it from a checkout containing the referenced files, or replace the paths with images available in the deployment:

```python
import tr

print(tr.detect("imgs/web.png", tr.FLAG_RECT))
print(tr.detect("imgs/id_card.jpeg", tr.FLAG_ROTATED_RECT))
print(tr.recognize("imgs/line.png"))
print(tr.run("imgs/id_card.jpeg"))
```

The first call demonstrates ordinary detection. The second requests rotated detection. The third recognizes a cropped line and prints its text and confidence. The fourth runs detection and recognition over an identity-card image and prints geometry, text, and confidence.

An application that draws results should preserve the center, width, height, and angle returned by the detector. An application that filters uncertain results must choose its own threshold because the README does not define confidence calibration or a recommended threshold. The examples show data shapes, not guaranteed recognition quality for every scan, font, language variant, or image orientation.

The repository also provides a PyQt5 screenshot example, but the README does not document its dependencies beyond the broader Python and numpy requirements. It should be treated as a sample application rather than a supported GUI framework for every Linux desktop.

## GPU Deployment, Licensing, and the Tesseract Alternative

The GPU path is documented as a separate deployment mode. The README instructs users to copy the contents of `tr_gpu` into `tr` and requires CUDA 10.1 with cuDNN 7.6.5. It says the GPU version temporarily supports older graphics cards because newer cards require higher CUDA versions. This is a specific compatibility boundary, not a general claim of support for current NVIDIA hardware.

The documented container route uses an ONNX Runtime image:

```bash
docker pull mcr.microsoft.com/azureml/onnxruntime:v1.3.0-cuda10.1-cudnn7
sudo nvidia-docker run -v /path/to/tr:/path/to/tr --rm -it mcr.microsoft.com/azureml/onnxruntime:v1.3.0-cuda10.1-cudnn7
```

The volume maps the local repository into the container. The README does not document GPU model requirements, memory limits, supported container architectures, or throughput, so a deployment would need to validate those points separately.

The repository license is not identified in the repository documentation. The README includes a disclaimer covering crashes, memory leaks, and losses caused by abnormal use, but that disclaimer does not state redistribution or commercial-use rights. Before embedding tr in a distributed product, an organization must resolve the license status with the repository owner or an authoritative package record.

Tesseract is the real alternative named by the README. The difference is architectural and operational: tr is documented as a C++ OCR core with Python bindings, model resources, text-line detection, and recognition, while Tesseract is identified as another open-source OCR option. The README does not compare accuracy, installation, or platform support, so tr is most relevant when its local SDK shape is more important than an established support and deployment path.

## Conclusion

Engineers with an Ubuntu 16.04-based deployment and a need for an offline Chinese OCR SDK should first verify that its maintenance pause is acceptable. Teams needing Windows support, modern CUDA combinations, or a current support commitment should not adopt tr without a replacement plan. Before integration, check the exact checkout, model files, Python version, and the behavior of tr.detect, tr.recognize, and tr.run on representative scans.

## FAQ

### Does myhub/tr support Windows?

No. The README explicitly says that tr does not support Windows, CentOS 6, or ARM.

### Does myhub/tr work offline?

Yes. The project describes itself as an offline text-recognition SDK and its examples use local image paths and local model resources.

### Does myhub/tr support GPU recognition?

A GPU version is documented, but it requires CUDA 10.1 and cuDNN 7.6.5 and is described as limited to older graphics cards.

### What Python API does myhub/tr provide?

The README documents `tr.detect`, `tr.recognize`, and `tr.run`, together with `tr.FLAG_RECT` and `tr.FLAG_ROTATED_RECT`. Detection returns geometry, recognition returns text and confidence, and `tr.run` combines both stages.

### Is myhub/tr actively maintained?

The README says maintenance will pause while the authors focus on Transformer technology. The repository is not archived, and its last push was on 2026-10-11, but the documented maintenance notice should be considered before adoption.

## Sources

- [Issues](https://github.com/myhub/tr/issues)
- [myhub/tr on GitHub](https://github.com/myhub/tr)
- [Project website](https://github.com/myhub/tr)
- [README](https://github.com/myhub/tr/blob/master/README.md)
- [Releases](https://github.com/myhub/tr/releases)

---

Hysen Labs editorial analysis, written from the project's own repository and release notes. Cite the canonical page: https://hysenlabs.com/projects/myhub-tr
