图像OCR文字识别
更新时间:2026-06-15
简介
基于 EasyOCR 的多语言OCR识别组件,支持中英文混合场景下的文本检测与识别。
功能描述
- 支持 100+ 种语言识别(需配置对应语言模型)
- BOS URL
- Base64编码
- 二进制流
- Numpy数组
- GPU 加速推理
- 模型量化(默认开启)
- 批量处理优化
- 简体中文(ch_sim)
- 英文(en)
- 日文(ja)
- 韩文(ko)
- 法文(fr)
- 德文(de)
算子参数
输入
| 输入 | 含义 |
|---|---|
| images | 包含图像数据的数组,支持URL/base64/二进制格式 |
输出
| 输出 | 含义 |
|---|---|
| result | pyarrow.Array: 包含OCR识别结果的数组,元素类型为字符串 |
参数
| 参数名称 | 类型 | 默认值 | 描述 |
|---|---|---|---|
| image_src_type | str | 'image_url' | 输入图像的格式类型,支持: - bos/http 地址 (image_url) - base64 编码 (image_base64) - 二进制流 (image_binary) 可选值: ["image_url", "image_base64", "image_binary"] 默认值: "image_url" |
| model_path | str | '/opt/aihc/models' | 模型存储路径。 默认值: "/opt/aihc/models" |
| model_name | str | 'EasyOCR' | 使用的模型名称,当前仅支持 "EasyOCR"。 默认值: "EasyOCR" |
| quantize | bool | True | 是否启用模型量化加速推理。 默认值: True |
| lang_list | list[str] | ['en', 'ch_sim'] | 支持识别的语言列表,详见 https://www.jaided.ai/easyocr/ 默认值: ["en", "ch_sim"] |
| batch_size | int | 16 | GPU 推理批次大小(可根据显存调整)。 默认值: 16 |
调用示例
Python
1from __future__ import annotations
2
3import os
4
5import daft
6from daft import col
7
8from daft.aihc.common.udf import aihc_udf
9from daft.aihc.functions.image.image_easyocr import ImageEasyOcr
10
11if __name__ == "__main__":
12 if os.getenv("DAFT_RUNNER", "native") == "ray":
13 import ray
14 ray.init(dashboard_host="0.0.0.0", ignore_reinit_error=True)
15 daft.set_runner_ray()
16 daft.set_execution_config(actor_udf_ready_timeout=6000, min_cpu_per_task=0)
17
18 # TODO: 根据实际场景准备样本数据
19 samples = {"images": [...]}
20 ds = daft.from_pydict(samples)
21 constructor_kwargs = {
22 "image_src_type": 'image_url',
23 "model_path": '/opt/aihc/models',
24 "model_name": 'EasyOCR',
25 "quantize": True,
26 "lang_list": ['en', 'ch_sim'],
27 }
28 ds = ds.with_column(
29 "result",
30 aihc_udf(
31 ImageEasyOcr,
32 construct_args=constructor_kwargs,
33 num_cpus=1,
34 concurrency=4,
35 batch_size=8,
36 )(col("images")),
37 )
38 ds.show()
评价此篇文章
