> 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).

## 코드 샘플

다음을 사용해 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' \
  --data '{
    "api_key": "'"$ROBOFLOW_API_KEY"'",
    "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

# 텍스트가 포함된 샘플 이미지
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"],
)

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

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

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

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

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

## 추론 속도

다음을 사용해 측정한 지연 시간 [Roboflow Inference](https://docs.roboflow.com/deployment/self-hosted/self-hosted) 1x NVIDIA L4, 배치 크기 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` Serverless Hosted 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은 핵심 모델입니다 [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/)
