> For the complete documentation index, see [llms.txt](https://docs.roboflow.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.roboflow.com/roboflow/roboflow-hi/deploy/supported-models/trocr.md).

# TrOCR

TrOCR Microsoft का transformer-आधारित OCR model है। इसे line-level text recognition के लिए प्रशिक्षित किया गया है, इसलिए सर्वोत्तम परिणामों के लिए अपने input को एक ही text region तक crop करें।

{% hint style="info" %}
TrOCR Serverless Hosted API पर उपलब्ध नहीं है। इसे एक पर चलाएँ [Dedicated Deployment](/roboflow/roboflow-hi/deploy/dedicated-deployments.md) या [self-hosted Inference](https://inference.roboflow.com/).
{% endhint %}

## कोड नमूना

{% stepper %}
{% step %}

### अपनी API Key प्राप्त करें

एक Roboflow खाता बनाएं, अपनी key यहाँ पर ढूँढें [Roboflow API settings page](https://app.roboflow.com/settings/api) और इसे अपने shell में उपलब्ध कराएँ:

```bash
export ROBOFLOW_API_KEY="your-key-here"
```

{% endstep %}

{% step %}

### निर्भरताएँ इंस्टॉल करें

ये packages image को fetch करते हैं और API को call करते हैं:

```bash
pip install requests opencv-python
```

{% endstep %}

{% step %}

### मॉडल चलाएँ

सेट करें `URL` को अपने Dedicated Deployment URL या local Inference server पर।

```python
import base64
import os
import cv2
import numpy as np
import requests

URL = "https://your-deployment.roboflow.cloud"
content = requests.get("https://media.roboflow.com/inference/license_plate_1.jpg").content
image = cv2.imdecode(np.frombuffer(content, np.uint8), cv2.IMREAD_COLOR)
_, buffer = cv2.imencode(".jpg", image)
image_base64 = base64.b64encode(buffer).decode("utf-8")

response = requests.post(
    f"{URL}/ocr/trocr",
    json={
        "api_key": os.environ["ROBOFLOW_API_KEY"],
        "image": {"type": "base64", "value": image_base64},
    },
)
print(response.json()["result"])
```

{% endstep %}
{% endstepper %}

ऊपर दिया गया code पहचाने गए text को terminal पर print करता है:

```
कुल
```

## Inference speed

Latency मापी गई [Roboflow Inference](https://inference.roboflow.com/) 1x NVIDIA L4 पर, batch size 1, warmup के बाद का औसत।

<table data-search="false"><thead><tr><th>मॉडल</th><th>विलंबता (ms)</th></tr></thead><tbody><tr><td><code>trocr</code></td><td>114.4</td></tr></tbody></table>

TrOCR एक ही cropped text line को पहचानता है, इसलिए यह latency एक line crop के लिए है, पूरे page के लिए नहीं।

{% hint style="info" %}
सेट करें `URL` को अपने deployment target से मिलाएँ:

* `http://localhost:9001` एक local [Inference](https://inference.roboflow.com/) server.
* आपका [Dedicated Deployment](/roboflow/roboflow-hi/deploy/dedicated-deployments.md) एक private endpoint के लिए URL.
  {% endhint %}
