> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dreamto.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# 富文本 OCR（提取文字图层的内容和样式）

> 图层分解时额外返回常规文字图层的文字内容、逐行位置和字体、颜色、加粗等近似样式。

图层分解时，Seedream 5.5 可以为**常规文字图层**额外返回富文本 OCR 结果，包括文字内容、逐行位置和近似的视觉样式。设计工具或应用可以把这些数据和拆出来的图层结合起来，实现改文案、本地化、模板复用等能力。文字的编辑和图层的合成由你的工具或应用完成。

![Seedream 5.5 分解图片后返回底图、独立图层和常规文字的 OCR 结果，应用可据此编辑文字](https://arkdocs-en.tos-ap-southeast-1.volces.com/flowcharts/image-generation/seedream-5-5-ocr-workflow-overview.svg)

[观看演示视频](https://arkdocs-en.tos-ap-southeast-1.volces.com/videos/image-generation/seedream-5-5-ocr-demo-en.mp4)

## 效果示例

下面的例子分解一张海报并获取文字图层的 OCR 结果。请求设置 `max_images: 15`，返回 13 张图片：1 张底图 + 12 个图层，其中 9 个文字图层带 OCR 结果。

| 输入 | 文字图层 | OCR 结果 |
| - | - | - |
| ![待分解和识别的海报](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/ocr-test2.png) | ![包含 Presented By 和姓名的文字图层](https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/seedream-5-5-ocr-regular-text-layer-20261103.png) | **文字**：第 1 行 `Presented By :`，第 2 行 `Anna Katrina Marchesi` **位置（绝对像素坐标）**：第 1 行 `[1196, 629, 1358, 658]`，第 2 行 `[1195, 651, 1427, 681]` **相似字体**：两行均为 Helvetica Neue **颜色**：第 1 行 `#193366`，第 2 行 `#46597E` **加粗**：第 1 行 `true`，第 2 行 `false` |

> [!TIP]
>
> 可以下载官方的[完整示例包（ZIP，约 6.7 MB）](https://arkdocs-en.tos-ap-southeast-1.volces.com/files/image-generation/seedream-5-5-ocr-interactive-example-20261104-v4.zip)，包含输入海报、底图、全部图层、OCR 数据和一个可交互页面：保持目录结构解压后，用浏览器打开 `seedream-55-ocr-preview.html`，选择文字图层即可查看每行的文字、坐标和样式，并实时预览修改文字、颜色和加粗的效果。

## 开启 OCR 识别

在图层分解请求里同时设置：

* `layer_decomposition: true`：开启图层分解；
* `layer_decomposition_options.text_recognition: true`：请求返回常规文字图层的 OCR 结果。

```bash cURL theme={null}
curl -X POST "https://api.dreamto.ai/api/v3/images/generations" \
  -H "Authorization: Bearer $DREAMTO_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "model": "seedream-5.5",
    "prompt": "把图片中的元素拆分成独立的图层。",
    "image": "https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/ocr-test2.png",
    "size": "auto",
    "layer_decomposition": true,
    "layer_decomposition_options": {
      "max_images": 15,
      "text_recognition": true
    },
    "output_format": "png",
    "response_format": "url",
    "watermark": true
  }'
```

```python Python theme={null}
import os

import requests

URL = "https://api.dreamto.ai/api/v3/images/generations"
HEADERS = {"Authorization": f"Bearer {os.environ['DREAMTO_API_KEY']}"}

payload = {
    "model": "seedream-5.5",
    "prompt": "把图片中的元素拆分成独立的图层。",
    "image": "https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/ocr-test2.png",
    "size": "auto",
    "layer_decomposition": True,
    "layer_decomposition_options": {
        "max_images": 15,
        "text_recognition": True
    },
    "output_format": "png",
    "response_format": "url",
    "watermark": True
}

result = requests.post(URL, headers=HEADERS, json=payload, timeout=600).json()
for image in result["data"]:
    print(image["url"])
```

```python OpenAI SDK theme={null}
import os

from openai import OpenAI

client = OpenAI(base_url="https://api.dreamto.ai/api/v3", api_key=os.environ["DREAMTO_API_KEY"])

response = client.images.generate(
    model="seedream-5.5",
    prompt="把图片中的元素拆分成独立的图层。",
    size="auto",
    output_format="png",
    response_format="url",
    extra_body={
        "image": "https://arkdocs-en.tos-ap-southeast-1.volces.com/images/image-generation/ocr-test2.png",
        "layer_decomposition": True,
        "layer_decomposition_options": {
            "max_images": 15,
            "text_recognition": True
        },
        "watermark": True,
    },
)
for item in response.data:
    print(item)
```

## OCR 响应字段

当前文字图层的 OCR 结果在 `data[].text_recognition` 中返回，包含完整纯文本，以及按文字行和样式片段组织的位置、文字和样式信息。

| 字段 | 说明 |
| - | - |
| `text_recognition` | 当前文字图层的富文本 OCR 结果。 |
| `text_recognition.text` | 完整纯文本，按从上到下、从左到右排列，行之间用 `\n` 分隔。 |
| `text_recognition.lines[]` | 按顺序排列的文字行，每行包含位置和样式片段。 |
| `lines[].bounding_box` | 该行在输出底图坐标系中的边界框，包含绝对坐标 `absolute` 和归一化坐标 `normalized`，用于把文字还原到底图或目标画布上的对应位置。 |
| `bounding_box.absolute` | 边界框的绝对像素坐标 `[左, 上, 右, 下]`，输出底图左上角为 `(0, 0)`。 |
| `bounding_box.normalized` | 按输出底图宽高换算成 0 \~ 1000 的整数坐标 `[左, 上, 右, 下]`，用于计算文字行在目标画布上的位置。 |
| `lines[].runs[]` | 该行的样式片段，每个片段内样式一致：整行样式相同时只有一个片段，行内字体、颜色、加粗等有变化时拆成多个。 |
| `runs[].text` | 该片段的文字，不含换行符。 |
| `runs[].style` | 该片段的近似视觉样式，包含下面八个字段。样式由模型自动识别，可能与原设计稿的精确属性不同。 |
| `style.similar_font_family` | 根据外观匹配到的最相近字体名称；无法识别或置信度不足时返回 `unknown`。 |
| `style.foreground_color` | 文字颜色，大写 `#RRGGBB` 格式，不含透明通道。 |
| `style.bold` | 是否识别为加粗。 |
| `style.italic` | 是否识别为斜体：只有字形本身向右倾斜时为 `true`，旋转或透视造成的倾斜不算。 |
| `style.underline` | 是否识别到文字下划线；独立的分隔线、表格线或装饰线不算。 |
| `style.strikethrough` | 是否识别到删除线。 |
| `style.shadow` | 是否识别到明显的投影、阴影或发光偏移；正常的抗锯齿过渡不算。 |
| `style.translucent` | 文字本身是否明显半透明、能透出背景的纹理或颜色；浅灰、浅蓝等不透明的浅色文字不算。 |

### 文字图层响应示例

下面是上例中包含 `Presented By :` 和 `Anna Katrina Marchesi` 的文字图层（`z_index: 6`）在 `data[]` 中的一项。

```json theme={null}
{
  "url": "https://files.dreamto.ai/images/seedream_layer_6_9b21.png",
  "size": "1166x899",
  "output_format": "png",
  "background": "transparent",
  "z_index": 6,
  "name": "Presenter text",
  "description": "Two lines of dark blue presenter text",
  "bounding_box": {
    "absolute": [
      1142,
      528,
      1474,
      784
    ],
    "normalized": [
      643,
      529,
      830,
      786
    ]
  },
  "text_recognition": {
    "text": "Presented By : \nAnna Katrina Marchesi",
    "lines": [
      {
        "bounding_box": {
          "absolute": [
            1196,
            629,
            1358,
            658
          ],
          "normalized": [
            673,
            630,
            765,
            659
          ]
        },
        "runs": [
          {
            "text": "Presented By : ",
            "style": {
              "similar_font_family": "Helvetica Neue",
              "foreground_color": "#193366",
              "bold": true,
              "italic": false,
              "underline": false,
              "strikethrough": false,
              "shadow": false,
              "translucent": false
            }
          }
        ]
      },
      {
        "bounding_box": {
          "absolute": [
            1195,
            651,
            1427,
            681
          ],
          "normalized": [
            673,
            652,
            803,
            682
          ]
        },
        "runs": [
          {
            "text": "Anna Katrina Marchesi",
            "style": {
              "similar_font_family": "Helvetica Neue",
              "foreground_color": "#46597E",
              "bold": false,
              "italic": false,
              "underline": false,
              "strikethrough": false,
              "shadow": false,
              "translucent": false
            }
          }
        ]
      }
    ]
  }
}
```

## 限制

* **识别范围**：只有常规文字图层返回 OCR 结果，支持识别的字体见 [OCR 支持字体](https://docs.dreamto.ai/image/models/seedream-5-5/ocr-supported-fonts.md)。底图、非文字图层、艺术字和手写体不返回 `text_recognition`。
* **字体识别**：`similar_font_family` 是近似匹配，不保证与原字体一致；无法识别或置信度不足时返回 `unknown`。
* **样式识别**：样式信息是近似值，`false` 表示模型没有识别到对应样式。
* 开启 OCR 不改变计费方式，仍按返回的图片张数计费，见 [精细图层分解](https://docs.dreamto.ai/image/models/seedream-5-5/layer-decomposition.md)。


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.