Yesianrohn/OCR-Data
收藏Hugging Face2026-04-12 更新2026-04-12 收录
下载链接:
https://hf-mirror.com/datasets/Yesianrohn/OCR-Data
下载链接
链接失效反馈官方服务:
资源简介:
---
license: apache-2.0
task_categories:
- object-detection
- image-to-text
language:
- zh
- en
tags:
- ocr
- text-detection
- text-recognition
- document-understanding
- scene-text
- handwritten-chinese
pretty_name: OCR Text Detection and Recognition Dataset
size_categories:
- 100K<n<1M
---
# OCR Text Detection and Recognition Dataset
## Dataset Description
A large-scale, multi-source OCR dataset aggregating **14 public benchmarks** for text detection and recognition in both scene images and handwritten documents. Each image is paired with:
- **Transcribed text** for each text region
- **Bounding boxes** (axis-aligned rectangles) for each text region
- **Polygon coordinates** (precise boundary points) for each text region
The dataset is stored in HuggingFace Parquet format with images embedded as raw bytes, enabling efficient streaming and zero-setup loading. Each source benchmark is stored as a separate **split**, so you can load individual subsets or combine them freely.
### Included Benchmarks
| Split | Source | Description |
|-------|--------|-------------|
| `ART` | [ART](https://rrc.cvc.uab.es/?ch=14) | Arbitrary-shaped text in natural scenes |
| `cocotext` | [COCO-Text](https://bgshih.github.io/cocotext/) | Text annotations on MS-COCO images |
| `CTW` | [CTW](https://ctwdataset.github.io/) | Chinese text in the wild |
| `hiertext` | [HierText](https://github.com/google-research-datasets/hiertext) | Hierarchical text in scene images |
| `LSVT` | [LSVT](https://rrc.cvc.uab.es/?ch=16) | Large-scale Street View Text |
| `MTWI` | [MTWI](https://tianchi.aliyun.com/competition/entrance/231651) | Multi-type web images |
| `openvino` | [OpenVINO](https://github.com/openvinotoolkit/open_model_zoo) | Text detection training data |
| `RCTW` | [RCTW-17](https://rctw.vlrlab.net/) | Reading Chinese text in the wild |
| `ReCTS` | [ReCTS](https://rrc.cvc.uab.es/?ch=12) | Reading Chinese text on signboards |
| `SCUT_HCCDoc` | [SCUT-HCCDoc](https://github.com/HCIILAB/SCUT-HCCDoc_Dataset_Release) | Handwritten Chinese text in documents |
| `ShopSign` | [ShopSign](https://github.com/chongshengzhang/shopsign) | Chinese shop sign text |
| `TextOCR` | [TextOCR](https://textvqa.org/textocr/) | Text in natural images (TextVQA) |
| `UberText` | [UberText](https://s3-us-west-2.amazonaws.com/uber-common-public/ubertext/index.html) | Text from Bing Street View imagery |
| `MLT2019` | [MLT 2019](https://rrc.cvc.uab.es/?ch=15) | Multi-lingual scene text |
## Dataset Structure
### Features
| Feature | Type | Description |
|---------|------|-------------|
| `image` | `Image` | The document/scene image (embedded as raw bytes) |
| `texts` | `Sequence[string]` | List of transcribed text strings, one per text region |
| `bboxes` | `Sequence[Sequence[float64]]` | Axis-aligned bounding boxes `[x_min, y_min, x_max, y_max]` for each text region |
| `polygons` | `Sequence[Sequence[float64]]` | Polygon coordinates as flat arrays `[x1, y1, x2, y2, ...]` for each text region |
| `num_text_regions` | `int32` | Total number of text regions in the image |
### Schema
All splits share an identical Arrow/Parquet schema with HuggingFace metadata, so `datasets` will automatically decode the `image` column into PIL Image objects.
## Usage
### Quick Start
```python
from datasets import load_dataset
# Load the full dataset (all splits)
ds = load_dataset("Yesianrohn/OCR-Data")
# Access a specific split
art = ds["ART"]
# View the first example
example = art[0]
print(f"Number of text regions: {example['num_text_regions']}")
print(f"Texts: {example['texts']}")
print(f"Bounding boxes: {example['bboxes']}")
```
### Load a Single Split
```python
from datasets import load_dataset
# Load only the LSVT split
lsvt = load_dataset("Yesianrohn/OCR-Data", split="LSVT")
print(f"LSVT contains {len(lsvt)} examples")
```
### Display an Image with Annotations
```python
from datasets import load_dataset
from PIL import Image, ImageDraw
ds = load_dataset("Yesianrohn/OCR-Data", split="ReCTS")
example = ds[0]
image = example["image"]
draw = ImageDraw.Draw(image)
for text, bbox in zip(example["texts"], example["bboxes"]):
x_min, y_min, x_max, y_max = bbox
draw.rectangle([x_min, y_min, x_max, y_max], outline="red", width=2)
draw.text((x_min, y_min - 12), text, fill="red")
image.show()
```
### Streaming Mode (No Download Required)
```python
from datasets import load_dataset
ds = load_dataset("Yesianrohn/OCR-Data", split="hiertext", streaming=True)
for example in ds:
print(example["texts"])
break # just peek at the first example
```
### Combine Multiple Splits
```python
from datasets import load_dataset, concatenate_datasets
ds = load_dataset("Yesianrohn/OCR-Data")
combined = concatenate_datasets([ds["ART"], ds["LSVT"], ds["MTWI"]])
print(f"Combined dataset size: {len(combined)}")
```
### Convert to Pandas DataFrame (without images)
```python
from datasets import load_dataset
ds = load_dataset("Yesianrohn/OCR-Data", split="CTW")
df = ds.to_pandas()
# Note: the 'image' column will contain PIL Image objects
print(df[["texts", "num_text_regions"]].head())
```
## How to Build This Parquet Dataset
Below is a minimal example showing how to programmatically construct a Parquet file that matches this dataset's schema. You can adapt it to any data source.
### Parquet Schema
Each Parquet file follows this Arrow schema with HuggingFace metadata:
```
image: struct { bytes: binary, path: string }
texts: list<string>
bboxes: list<list<float64>> // each inner list is [x_min, y_min, x_max, y_max]
polygons: list<list<float64>> // each inner list is [x1, y1, x2, y2, ...]
num_text_regions: int32
```
The `image` column uses the HuggingFace `Image` feature convention — a struct with raw `bytes` and a `path` filename — so the `datasets` library will automatically decode it into a PIL Image.
### Build a Parquet File from Scratch
```python
import json
import pyarrow as pa
import pyarrow.parquet as pq
# ---- 1. Define Arrow schema with HuggingFace metadata ----
image_type = pa.struct([
pa.field("bytes", pa.binary()),
pa.field("path", pa.string()),
])
hf_features = {
"image": {"_type": "Image"},
"texts": {"feature": {"dtype": "string", "_type": "Value"}, "_type": "Sequence"},
"bboxes": {"feature": {"feature": {"dtype": "float64", "_type": "Value"}, "_type": "Sequence"}, "_type": "Sequence"},
"polygons": {"feature": {"feature": {"dtype": "float64", "_type": "Value"}, "_type": "Sequence"}, "_type": "Sequence"},
"num_text_regions": {"dtype": "int32", "_type": "Value"},
}
schema = pa.schema([
pa.field("image", image_type),
pa.field("texts", pa.list_(pa.string())),
pa.field("bboxes", pa.list_(pa.list_(pa.float64()))),
pa.field("polygons", pa.list_(pa.list_(pa.float64()))),
pa.field("num_text_regions", pa.int32()),
], metadata={"huggingface": json.dumps({"info": {"features": hf_features}})})
# ---- 2. Prepare your data (one record per image) ----
records = []
for img_path, annotations in your_data_iterator():
with open(img_path, "rb") as f:
img_bytes = f.read()
texts, bboxes, polygons = [], [], []
for ann in annotations:
texts.append(ann["text"])
pts = ann["polygon"] # [x1,y1,x2,y2,...,xN,yN]
polygons.append(pts)
xs, ys = pts[0::2], pts[1::2]
bboxes.append([min(xs), min(ys), max(xs), max(ys)])
records.append({
"image": {"bytes": img_bytes, "path": os.path.basename(img_path)},
"texts": texts,
"bboxes": bboxes,
"polygons": polygons,
"num_text_regions": len(texts),
})
# ---- 3. Write to Parquet (chunked for memory efficiency) ----
CHUNK = 200
with pq.ParquetWriter("my_split.parquet", schema, compression="snappy") as writer:
for i in range(0, len(records), CHUNK):
chunk = records[i : i + CHUNK]
batch = pa.record_batch({
"image": pa.array([r["image"] for r in chunk], type=image_type),
"texts": pa.array([r["texts"] for r in chunk], type=pa.list_(pa.string())),
"bboxes": pa.array([r["bboxes"] for r in chunk], type=pa.list_(pa.list_(pa.float64()))),
"polygons": pa.array([r["polygons"] for r in chunk], type=pa.list_(pa.list_(pa.float64()))),
"num_text_regions": pa.array([r["num_text_regions"] for r in chunk], type=pa.int32()),
}, schema=schema)
writer.write_batch(batch)
```
### Key Points
- **Image Encoding:** Store raw JPEG/PNG bytes directly — do not re-encode. The HuggingFace `datasets` library handles decoding at load time.
- **Bounding Boxes:** Computed as axis-aligned rectangles from polygon vertices: `[min(xs), min(ys), max(xs), max(ys)]`.
- **Memory Efficiency:** Write in chunks (e.g. 200 records) via `ParquetWriter` to avoid loading all images into memory at once.
- **HuggingFace Metadata:** The `{"huggingface": ...}` key in schema metadata tells the Dataset Viewer how to render each column (especially the `Image` type).
- **Split Naming:** Each `.parquet` file becomes a split. The filename (without extension) is the split name. HuggingFace requires split names to match `\w+(\.\w+)*`, so replace hyphens with underscores.
### Upload to HuggingFace Hub
```bash
pip install huggingface_hub datasets
huggingface-cli login
# Edit upload_to_hf.py with your REPO_ID and DATASET_DIR, then:
python upload_to_hf.py
```
## Citation
If you use this dataset, please cite:
```bibtex
TBD
```
## License
This dataset is released under the [Apache 2.0 License](https://www.apache.org/licenses/LICENSE-2.0).
---
license: Apache-2.0 许可证
task_categories:
- 目标检测
- 图像到文本
language:
- 中文
- 英文
tags:
- OCR(光学字符识别,Optical Character Recognition)
- 文本检测
- 文本识别
- 文档理解
- 场景文本
- 手写中文
pretty_name: OCR文本检测与识别数据集
size_categories: 样本规模:10万 < 样本数量 < 100万
---
# OCR文本检测与识别数据集
## 数据集概览
本数据集为大规模多源OCR(光学字符识别)数据集,整合了14个公开基准数据集,涵盖自然场景图像与手写文档中的文本检测与识别任务。每张图像配套包含以下标注信息:
- 每个文本区域的转录文本
- 每个文本区域的边界框(轴对齐矩形)
- 每个文本区域的多边形坐标(精确边界点)
本数据集以HuggingFace Parquet格式存储,图像以原始字节嵌入其中,可实现高效流式加载且无需额外配置即可读取。每个源基准数据集对应一个独立的**拆分(split)**,用户可按需加载单个子集或自由组合多个子集。
### 包含的基准数据集
| 拆分名称 | 数据源 | 描述 |
|-------|--------|-------------|
| `ART` | [ART](https://rrc.cvc.uab.es/?ch=14) | 自然场景中的任意形状文本 |
| `cocotext` | [COCO-Text](https://bgshih.github.io/cocotext/) | MS-COCO图像上的文本标注 |
| `CTW` | [CTW](https://ctwdataset.github.io/) | 野外中文文本 |
| `hiertext` | [HierText](https://github.com/google-research-datasets/hiertext) | 自然场景图像中的层级文本 |
| `LSVT` | [LSVT](https://rrc.cvc.uab.es/?ch=16) | 大规模街景文本 |
| `MTWI` | [MTWI](https://tianchi.aliyun.com/competition/entrance/231651) | 多类型网络图像文本 |
| `openvino` | [OpenVINO](https://github.com/openvinotoolkit/open_model_zoo) | 文本检测训练数据集 |
| `RCTW` | [RCTW-17](https://rctw.vlrlab.net/) | 野外中文文本读取数据集 |
| `ReCTS` | [ReCTS](https://rrc.cvc.uab.es/?ch=12) | 招牌上的中文文本读取 |
| `SCUT_HCCDoc` | [SCUT-HCCDoc](https://github.com/HCIILAB/SCUT-HCCDoc_Dataset_Release) | 文档中的手写中文文本 |
| `ShopSign` | [ShopSign](https://github.com/chongshengzhang/shopsign) | 中文店铺招牌文本 |
| `TextOCR` | [TextOCR](https://textvqa.org/textocr/) | 自然图像中的文本(TextVQA) |
| `UberText` | [UberText](https://s3-us-west-2.amazonaws.com/uber-common-public/ubertext/index.html) | Bing街景图像中的文本 |
| `MLT2019` | [MLT 2019](https://rrc.cvc.uab.es/?ch=15) | 多语言场景文本 |
## 数据集结构
### 数据特征
| 特征名称 | 数据类型 | 描述 |
|---------|------|-------------|
| `image` | `Image` | 文档或场景图像,以原始字节形式嵌入 |
| `texts` | `Sequence[string]` | 文本区域对应的转录文本字符串列表,每个元素对应一个文本区域 |
| `bboxes` | `Sequence[Sequence[float64]]` | 每个文本区域的轴对齐边界框,格式为`[x_min, y_min, x_max, y_max]` |
| `polygons` | `Sequence[Sequence[float64]]` | 每个文本区域的多边形坐标,以扁平数组形式存储,格式为`[x1, y1, x2, y2, ...]` |
| `num_text_regions` | `int32` | 图像中文本区域的总数量 |
### 数据架构
所有拆分均采用统一的Arrow/Parquet架构并附带HuggingFace元数据,因此`datasets`库可自动将`image`列解码为PIL图像对象。
## 使用方法
### 快速上手
python
from datasets import load_dataset
# 加载完整数据集(包含所有拆分)
ds = load_dataset("Yesianrohn/OCR-Data")
# 访问指定拆分
art = ds["ART"]
# 查看第一条样本
example = art[0]
print(f"文本区域总数:{example['num_text_regions']}")
print(f"转录文本:{example['texts']}")
print(f"边界框:{example['bboxes']}")
### 加载单个拆分
python
from datasets import load_dataset
# 仅加载LSVT拆分
lsvt = load_dataset("Yesianrohn/OCR-Data", split="LSVT")
print(f"LSVT数据集包含{len(lsvt)}条样本")
### 可视化带标注的图像
python
from datasets import load_dataset
from PIL import Image, ImageDraw
ds = load_dataset("Yesianrohn/OCR-Data", split="ReCTS")
example = ds[0]
image = example["image"]
draw = ImageDraw.Draw(image)
for text, bbox in zip(example["texts"], example["bboxes"]):
x_min, y_min, x_max, y_max = bbox
draw.rectangle([x_min, y_min, x_max, y_max], outline="red", width=2)
draw.text((x_min, y_min - 12), text, fill="red")
image.show()
### 流式加载(无需下载)
python
from datasets import load_dataset
ds = load_dataset("Yesianrohn/OCR-Data", split="hiertext", streaming=True)
for example in ds:
print(example["texts"])
break # 仅查看第一条样本
### 合并多个拆分
python
from datasets import load_dataset, concatenate_datasets
ds = load_dataset("Yesianrohn/OCR-Data")
combined = concatenate_datasets([ds["ART"], ds["LSVT"], ds["MTWI"]])
print(f"合并后的数据集规模:{len(combined)}")
### 转换为Pandas DataFrame(不包含图像)
python
from datasets import load_dataset
ds = load_dataset("Yesianrohn/OCR-Data", split="CTW")
df = ds.to_pandas()
# 注意:`image`列将包含PIL图像对象
print(df[["texts", "num_text_regions"]].head())
## 如何构建该Parquet数据集
以下为如何通过编程方式构建符合本数据集架构的Parquet文件的极简示例,您可将其适配至任意数据源。
### Parquet数据架构
每个Parquet文件遵循以下Arrow架构并附带HuggingFace元数据:
image: struct { bytes: binary, path: string }
texts: list<string>
bboxes: list<list<float64>> // 每个内部列表格式为 [x_min, y_min, x_max, y_max]
polygons: list<list<float64>> // 每个内部列表格式为 [x1, y1, x2, y2, ...]
num_text_regions: int32
`image`列遵循HuggingFace `Image`特征约定:采用包含原始字节`bytes`与文件名`path`的结构体,因此`datasets`库可自动将其解码为PIL图像对象。
### 从零构建Parquet文件
python
import json
import pyarrow as pa
import pyarrow.parquet as pq
import os
# ---- 1. 定义带HuggingFace元数据的Arrow架构 ----
image_type = pa.struct([
pa.field("bytes", pa.binary()),
pa.field("path", pa.string()),
])
hf_features = {
"image": {"_type": "Image"},
"texts": {"feature": {"dtype": "string", "_type": "Value"}, "_type": "Sequence"},
"bboxes": {"feature": {"feature": {"dtype": "float64", "_type": "Value"}, "_type": "Sequence"}, "_type": "Sequence"},
"polygons": {"feature": {"feature": {"dtype": "float64", "_type": "Value"}, "_type": "Sequence"}, "_type": "Sequence"},
"num_text_regions": {"dtype": "int32", "_type": "Value"},
}
schema = pa.schema([
pa.field("image", image_type),
pa.field("texts", pa.list_(pa.string())),
pa.field("bboxes", pa.list_(pa.list_(pa.float64()))),
pa.field("polygons", pa.list_(pa.list_(pa.float64()))),
pa.field("num_text_regions", pa.int32()),
], metadata={"huggingface": json.dumps({"info": {"features": hf_features}})})
# ---- 2. 准备数据(每张图像对应一条记录) ----
records = []
for img_path, annotations in your_data_iterator():
with open(img_path, "rb") as f:
img_bytes = f.read()
texts, bboxes, polygons = [], [], []
for ann in annotations:
texts.append(ann["text"])
pts = ann["polygon"] # 格式为 [x1,y1,x2,y2,...,xN,yN]
polygons.append(pts)
xs, ys = pts[0::2], pts[1::2]
bboxes.append([min(xs), min(ys), max(xs), max(ys)])
records.append({
"image": {"bytes": img_bytes, "path": os.path.basename(img_path)},
"texts": texts,
"bboxes": bboxes,
"polygons": polygons,
"num_text_regions": len(texts),
})
# ---- 3. 写入Parquet文件(按块写入以提升内存效率) ----
CHUNK = 200
with pq.ParquetWriter("my_split.parquet", schema, compression="snappy") as writer:
for i in range(0, len(records), CHUNK):
chunk = records[i : i + CHUNK]
batch = pa.record_batch({
"image": pa.array([r["image"] for r in chunk], type=image_type),
"texts": pa.array([r["texts"] for r in chunk], type=pa.list_(pa.string())),
"bboxes": pa.array([r["bboxes"] for r in chunk], type=pa.list_(pa.list_(pa.float64()))),
"polygons": pa.array([r["polygons"] for r in chunk], type=pa.list_(pa.list_(pa.float64()))),
"num_text_regions": pa.array([r["num_text_regions"] for r in chunk], type=pa.int32()),
}, schema=schema)
writer.write_batch(batch)
### 关键注意事项
- **图像编码:直接存储原始JPEG/PNG字节流,请勿重复编码。HuggingFace `datasets`库会在加载时自动完成解码操作。**
- **边界框计算:从多边形顶点提取轴对齐矩形,计算公式为`[min(xs), min(ys), max(xs), max(ys)]`。**
- **内存效率优化:通过`ParquetWriter`按块写入数据(例如每200条记录为一块),避免一次性将所有图像加载至内存中。**
- **HuggingFace元数据:架构元数据中的`{"huggingface": ...}`字段可告知数据集查看器如何渲染各列(尤其是`Image`类型列)。**
- **拆分命名:每个`.parquet`文件对应一个拆分。文件名(不含扩展名)即为拆分名称。HuggingFace要求拆分名称需符合`w+(.w+)*`格式,因此请将连字符替换为下划线。**
### 上传至HuggingFace Hub
bash
pip install huggingface_hub datasets
huggingface-cli login
# 编辑upload_to_hf.py文件,填入您的REPO_ID与DATASET_DIR,然后运行:
python upload_to_hf.py
## 引用信息
若您使用本数据集,请引用:
bibtex
TBD
## 许可证
本数据集采用[Apache 2.0许可证](https://www.apache.org/licenses/LICENSE-2.0)发布。
提供机构:
Yesianrohn


