Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions .github/workflows/pages.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,29 @@
name: Sphinx Pages

# Controls when the action will run. Triggers the workflow on push or pull request
# events but only for the master branch
on:
push:
branches: [ master ]

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest

steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout@v2
- uses: actions/checkout@v5

- name: Set up Python
uses: actions/setup-python@v2
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: '3.8'
python-version: "3.10"

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools wheel
pip3 install -r requirements.txt
run: uv sync --locked --no-dev --extra docs

- name: Make html
- name: Build docs
run: |
cd docs
make html
uv run make html

- name: Push to gh-pages branch
run: |
cd docs/_build/html
Expand Down
16 changes: 7 additions & 9 deletions .github/workflows/pytest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,15 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v5

- name: Set up Python
uses: actions/setup-python@v2
- name: Install uv
uses: astral-sh/setup-uv@v7
with:
python-version: '3.8'
python-version: "3.10"

- name: Install dependencies
run: |
python3 -m pip install --upgrade pip setuptools wheel
pip3 install -r requirements.txt
run: uv sync --locked

- name: Run test
run: pytest
- name: Run tests
run: uv run pytest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ notebook
.ipynb

text_renderer.egg-info/
.venv/
workspace
workspace2
node_modules/
Expand Down
1 change: 1 addition & 0 deletions .python-version
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.10
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,30 @@ Generate text line images for training deep learning OCR model (e.g. [CRNN](http

## Prerequisites

- Python 3.7+
- Python 3.10+
- Operating System: Linux, macOS, or Windows

## Installation

```bash
git clone https://github.com/oh-my-ocr/text_renderer
cd text_renderer
pip install -r requirements.txt
uv sync
```

Or with pip:

```bash
pip install '.[tools]' # includes font viewer and utility scripts
pip install '.[docs]' # includes Sphinx for building documentation
```

## Run Example

Run the following command to generate images using example data:

```bash
python main.py \
uv run python main.py \
--config example_data/example.py \
--dataset img \
--num_processes 2 \
Expand All @@ -54,7 +61,7 @@ python main.py \

> **Note for Windows users:** Use `^` instead of `\` for line continuation, or write the command on a single line:
> ```cmd
> python main.py --config example_data/example.py --dataset img --num_processes 2 --log_period 10
> uv run python main.py --config example_data/example.py --dataset img --num_processes 2 --log_period 10
> ```

The data is generated in the `example_data/output` directory. A `labels.json` file contains all annotations in the following format:
Expand Down Expand Up @@ -265,18 +272,21 @@ Setup [Commitizen](http://commitizen.github.io/cz-cli/) for commit message


## Font Viewer
Start font viewer

Install the tools extra, then start font viewer:

```bash
streamlit run tools/font_viewer.py -- web /path/to/fonts_dir
uv sync --extra tools
uv run streamlit run tools/font_viewer.py -- web /path/to/fonts_dir
```
![image](./image/font_viewer.png)

## Build docs

```bash
uv sync --extra docs
cd docs
make html
uv run make html
open _build/html/index.html
```

Expand Down
56 changes: 56 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"

[project]
name = "text_renderer"
version = "0.1.0"
description = "Generate text line images for training deep learning OCR models"
readme = "README.md"
license = "MIT"
requires-python = ">=3.10"
dependencies = [
"albumentations>=1.3.0,<2.0",
"fontTools>=4.12.1",
"lmdb>=0.98",
"loguru>=0.6.0",
"numpy>=1.21.5,<2.3",
"opencv-python>=4.5.0",
"pillow>=8.0.0",
"scipy>=1.7.3,<1.16",
"tenacity>=8.0.0",
"tqdm>=4.60.0",
]

[project.optional-dependencies]
docs = [
"recommonmark>=0.6.0",
"sphinx>=3.1.2",
"sphinx-markdown-tables>=0.0.3",
"sphinx-rtd-theme>=0.5.0",
]
tools = [
"fire>=0.4.0",
"rich>=10.0.0",
"streamlit>=1.0.0",
"typer>=0.4.0",
]

[dependency-groups]
dev = [
"pre-commit>=3.0.0",
"pytest>=6.0.0",
]

[tool.black]
line-length = 88

[tool.isort]
profile = "black"
line_length = 88

[tool.pytest.ini_options]
testpaths = ["text_renderer/tests"]

[tool.mypy]
ignore_missing_imports = true
21 changes: 0 additions & 21 deletions requirements.txt

This file was deleted.

25 changes: 9 additions & 16 deletions tools/prepare_effect_layout_example.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import os
import shutil
from pathlib import Path

import pandas as pd

CURRENT_DIR = Path(os.path.abspath(os.path.dirname(__file__)))
CURRENT_DIR = Path(__file__).resolve().parent

if __name__ == "__main__":
effect_layout_image_dir = (
Expand All @@ -18,15 +15,11 @@
shutil.copy(img_p, img_save_path)
shutil.rmtree(subdir)

markdown_data = []
for img_p in effect_layout_image_dir.glob("*.jpg"):
markdown_data.append(
{
"Name": img_p.stem,
"Example": f"![{img_p.name}](https://github.com/oh-my-ocr/text_renderer/raw/master/example_data/effect_layout_image/{img_p.name})",
}
)
markdown_data.sort(key=lambda x: x["Name"])
df = pd.DataFrame(markdown_data)
markdown_table = df.to_markdown()
print(markdown_table)
rows = []
for img_p in sorted(effect_layout_image_dir.glob("*.jpg"), key=lambda p: p.stem):
url = f"https://github.com/oh-my-ocr/text_renderer/raw/master/example_data/effect_layout_image/{img_p.name}"
rows.append(f"| {img_p.stem} | ![{img_p.name}]({url}) |")

print("| Name | Example |")
print("|------|---------|")
print("\n".join(rows))
13 changes: 0 additions & 13 deletions update.sh

This file was deleted.

Loading