> 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/models/ko/supported-models/doctr.md).

# DocTR

[DocTR](https://github.com/mindee/doctr) 문서 OCR 모델이며, 우리의 [서버리스 클라우드 API](https://docs.roboflow.com/deployment/roboflow-cloud/serverless-api).

## DocTR API

다음으로 HTTP 엔드포인트를 통해 DocTR을 직접 실행하세요 `curl`, 또는 [`inference-sdk`](https://docs.roboflow.com/reference/inference/inference-sdk) 래퍼를 사용하세요.

{% tabs %}
{% tab title="HTTP (curl)" icon="webhook" %}
{% stepper %}
{% step %}

### API 키 받기

Roboflow 계정을 만들고, [Roboflow API 설정 페이지](https://app.roboflow.com/settings/api) 에서 키를 찾아 셸에서 사용할 수 있게 하세요:

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

{% endstep %}

{% step %}

### 모델 실행

다음을 호출하세요: `/doctr/ocr` 엔드포인트를 `curl`:

```bash
curl --location 'https://serverless.roboflow.com/doctr/ocr' \
  --header 'Content-Type: application/json' \
  --header "Authorization: Bearer $ROBOFLOW_API_KEY" \
  --data '{
    "image": {"type": "url", "value": "https://media.roboflow.com/inference/license_plate_1.jpg"}
  }'
```

{% endstep %}
{% endstepper %}
{% endtab %}

{% tab title="SDK (Python)" icon="python" %}
{% stepper %}
{% step %}

### API 키 받기

Roboflow 계정을 만들고, [Roboflow API 설정 페이지](https://app.roboflow.com/settings/api) 에서 키를 찾아 셸에서 사용할 수 있게 하세요:

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

{% endstep %}

{% step %}

### 의존성을 설치하세요

이 패키지는 다음 모델을 호출합니다:

```bash
pip install -U inference-sdk supervision
```

{% endstep %}

{% step %}

### 모델 실행

텍스트가 포함된 이미지에서 DocTR을 실행하세요:

```python
import os
import supervision as sv
from inference_sdk import InferenceHTTPClient, InferenceConfiguration

# 텍스트가 포함된 샘플 이미지
image = sv.load_image_from_url("https://media.roboflow.com/inference/license_plate_1.jpg")

client = InferenceHTTPClient(
    api_url="https://serverless.roboflow.com",
    api_key=os.environ["ROBOFLOW_API_KEY"],
).configure(InferenceConfiguration(api_key_transport="header"))

result = client.ocr_image(inference_input=image, model="doctr")

print(result["result"]) # 추출된 텍스트
```

위의 코드는 추론 결과를 터미널에 출력합니다:

```
Mr
AUTPMATIC
280SE
34 T6511
```

{% endstep %}
{% endstepper %}
{% endtab %}
{% endtabs %}

## DocTR 추론 속도

다음을 사용하여 측정한 지연 시간 [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 에서 NVIDIA L4 1개, 배치 크기 1, 워밍업 후 평균.

<table data-search="false"><thead><tr><th>모델</th><th>지연 시간(ms)</th></tr></thead><tbody><tr><td><code>doctr</code></td><td>83.5</td></tr></tbody></table>

전체 문서 이미지에서 측정함(텍스트 검출과 인식 포함).

{% hint style="info" %}
설정하세요 `api_url` 를 배포 대상에 맞게:

* `https://serverless.roboflow.com` 는 서버리스 클라우드 API용입니다.
* `http://localhost:9001` 로컬 [Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 서버용입니다.
* 귀하의 [전용 배포](https://docs.roboflow.com/deployment/roboflow-cloud/dedicated-deployments) 는 비공개 엔드포인트의 URL입니다.
  {% endhint %}

## 자체 호스팅 Inference로 DocTR을 실행하세요

DocTR은 핵심 모델입니다 [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted), 따라서 자체 호스팅하는 서버에서도 실행됩니다. 로컬 서버를 시작한 다음, 동일한 `ocr_image` 호출을 해당 서버에 보내세요:

```bash
pip install inference-cli
inference server start  # http://localhost:9001을 서비스합니다
```

```python
import os
from inference_sdk import InferenceHTTPClient

client = InferenceHTTPClient(
    api_url="http://localhost:9001",
    api_key=os.environ["ROBOFLOW_API_KEY"],
)

result = client.ocr_image(inference_input="./container.jpg")
print(result)
```

응답에는 인식된 텍스트와 추론 시간이 포함됩니다:

```
{'result': 'MSKU 0439215', 'time': 3.87}
```

## 추가 읽을거리

* [OCR로 이미지에서 텍스트를 감지하는 방법](https://blog.roboflow.com/ocr-api/)
