Skip to content

danghoangnhan/sealGenerator

Repository files navigation

SealGenerator

CI Python 3.10+ License: MIT

Synthetic seal and stamp image generator for OCR data augmentation, with pixel-perfect polygon annotations.

Features

  • 12 seal templates — round, oval, rectangular in PRC and Taiwan styles
  • Curved text layout — characters placed along elliptical arcs with precise polygon annotations
  • 11 degradation effects — ink bleeding, fading, rotation, perspective warp, noise, JPEG artifacts, and more
  • 4 export formats — PaddleOCR, COCO JSON, YOLO polygon, MMOCR
  • YAML-driven configuration — full control over templates, degradation, compositing, and export
  • Font alias system — maps logical font names to available fonts with fallback chains
  • Bilingual support — synchronized Chinese + English text for international company seals
  • Traditional + Simplified Chinese — Taiwan (正體字) and mainland wordlists included

Quick Start

# Install
pip install -e ".[dev]"

# Download free CJK fonts (optional but recommended)
python scripts/download_fonts.py

# Generate 100 seals with default settings
seal-generator generate -n 100 -o ./output

# Generate Taiwan-style seals
seal-generator generate -c configs/examples/taiwan_seals.yaml

# Generate with all formats
seal-generator generate -n 50 -o ./output -f paddleocr -f coco -f yolo

Templates

Template Style Description
round_company PRC Round company seal with star center
round_star_center PRC Star + serial number + title
round_government PRC Government seal with large star
oval_company PRC Oval company seal
oval_personal PRC Oval personal name seal
rect_personal PRC Rectangular personal seal
rect_finance PRC Rectangular finance seal
round_tw_company Taiwan Round seal with center text (印)
rect_tw_personal Taiwan Stone seal style, cinnabar red
round_tw_government Taiwan Sun emblem (青天白日) center
oval_tw_company Taiwan Oval company seal (Traditional Chinese)
round_tw_bilingual Taiwan Chinese + English bilingual seal

Configuration

Seals are configured via YAML. Example:

global:
  seed: 42
  num_images: 100
  output_dir: "./output"

templates:
  - name: "round_tw_company"
    weight: 0.5
  - name: "rect_tw_personal"
    weight: 0.3
  - name: "round_tw_bilingual"
    weight: 0.2

degradation:
  enabled: true
  pipeline:
    - name: "ink_bleeding"
      probability: 0.7
      params: { kernel_size: [3, 5], blur_sigma: [0.5, 1.5] }
    - name: "rotation"
      probability: 0.8
      params: { angle: [-15, 15] }

export:
  formats: ["paddleocr", "coco"]

See configs/examples/ for more examples.

Export Formats

Format Output Description
PaddleOCR label.txt image_path\t[{"transcription": "...", "points": [...]}]
COCO annotations.json Standard COCO with segmentation polygons
YOLO *.txt per image Normalized polygon coordinates
MMOCR labels.jsonl JSON Lines with polygon + text

Project Structure

seal_generator/
├── core/           # Geometry, text layout, canvas, renderer
├── templates/      # 12 seal template definitions
├── degradation/    # 11 image degradation effects
├── compositing/    # Background compositing
├── annotation/     # Polygon types and transforms
├── export/         # PaddleOCR, COCO, YOLO, MMOCR exporters
├── utils/          # Font loading, RNG, I/O
├── config.py       # Pydantic v2 configuration models
├── pipeline.py     # Main orchestrator
└── cli.py          # Click CLI
configs/            # YAML configuration examples
resources/          # Fonts, wordlists, backgrounds
wiki/               # GitHub Wiki documentation
tests/              # pytest test suite

Development

# Install with dev dependencies
pip install -e ".[dev]"

# Run tests
pytest -v

# Lint
ruff check seal_generator/ tests/

License

MIT

About

Synthetic seal/stamp image generator for OCR data augmentation. 12 templates (PRC + Taiwan), curved text layout, 11 degradation effects, export to PaddleOCR/COCO/YOLO/MMOCR.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages