textbaker 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (34) hide show
  1. textbaker-0.1.0/LICENSE +21 -0
  2. textbaker-0.1.0/PKG-INFO +380 -0
  3. textbaker-0.1.0/README.md +333 -0
  4. textbaker-0.1.0/pyproject.toml +141 -0
  5. textbaker-0.1.0/setup.cfg +4 -0
  6. textbaker-0.1.0/tests/test_cli.py +200 -0
  7. textbaker-0.1.0/tests/test_configs.py +256 -0
  8. textbaker-0.1.0/tests/test_generator.py +334 -0
  9. textbaker-0.1.0/tests/test_random_state.py +109 -0
  10. textbaker-0.1.0/tests/test_ui_config.py +113 -0
  11. textbaker-0.1.0/textbaker/__init__.py +130 -0
  12. textbaker-0.1.0/textbaker/__main__.py +10 -0
  13. textbaker-0.1.0/textbaker/app/__init__.py +5 -0
  14. textbaker-0.1.0/textbaker/app/main_window.py +1168 -0
  15. textbaker-0.1.0/textbaker/cli.py +815 -0
  16. textbaker-0.1.0/textbaker/core/__init__.py +48 -0
  17. textbaker-0.1.0/textbaker/core/configs.py +264 -0
  18. textbaker-0.1.0/textbaker/core/defs.py +92 -0
  19. textbaker-0.1.0/textbaker/core/generator.py +589 -0
  20. textbaker-0.1.0/textbaker/core/image_processing.py +352 -0
  21. textbaker-0.1.0/textbaker/ui_config.py +73 -0
  22. textbaker-0.1.0/textbaker/utils/__init__.py +5 -0
  23. textbaker-0.1.0/textbaker/utils/helpers.py +22 -0
  24. textbaker-0.1.0/textbaker/utils/logging.py +46 -0
  25. textbaker-0.1.0/textbaker/utils/random_state.py +72 -0
  26. textbaker-0.1.0/textbaker/widgets/__init__.py +11 -0
  27. textbaker-0.1.0/textbaker/widgets/dialogs.py +362 -0
  28. textbaker-0.1.0/textbaker/widgets/graphics.py +419 -0
  29. textbaker-0.1.0/textbaker.egg-info/PKG-INFO +380 -0
  30. textbaker-0.1.0/textbaker.egg-info/SOURCES.txt +32 -0
  31. textbaker-0.1.0/textbaker.egg-info/dependency_links.txt +1 -0
  32. textbaker-0.1.0/textbaker.egg-info/entry_points.txt +5 -0
  33. textbaker-0.1.0/textbaker.egg-info/requires.txt +20 -0
  34. textbaker-0.1.0/textbaker.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Ramkrishna Acharya
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,380 @@
1
+ Metadata-Version: 2.4
2
+ Name: textbaker
3
+ Version: 0.1.0
4
+ Summary: Synthetic Text Dataset Generator for OCR Training
5
+ Author: Ramkrishna Acharya
6
+ Maintainer: Ramkrishna Acharya
7
+ License: MIT
8
+ Project-URL: Homepage, https://github.com/q-viper/text-baker
9
+ Project-URL: Documentation, https://q-viper.github.io/text-baker
10
+ Project-URL: Repository, https://github.com/q-viper/text-baker
11
+ Project-URL: Issues, https://github.com/q-viper/text-baker/issues
12
+ Keywords: ocr,dataset,synthetic,text,image-generation,machine-learning
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3
19
+ Classifier: Programming Language :: Python :: 3.9
20
+ Classifier: Programming Language :: Python :: 3.10
21
+ Classifier: Programming Language :: Python :: 3.11
22
+ Classifier: Programming Language :: Python :: 3.12
23
+ Classifier: Topic :: Scientific/Engineering :: Image Processing
24
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
25
+ Requires-Python: >=3.9
26
+ Description-Content-Type: text/markdown
27
+ License-File: LICENSE
28
+ Requires-Dist: numpy>=1.21.0
29
+ Requires-Dist: opencv-python>=4.5.0
30
+ Requires-Dist: PySide6>=6.4.0
31
+ Requires-Dist: loguru>=0.6.0
32
+ Requires-Dist: typer[all]>=0.9.0
33
+ Requires-Dist: rich>=13.0.0
34
+ Requires-Dist: pydantic>=2.0.0
35
+ Requires-Dist: pyyaml>=6.0.0
36
+ Provides-Extra: dev
37
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
38
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
39
+ Requires-Dist: pytest-qt>=4.0.0; extra == "dev"
40
+ Requires-Dist: ruff>=0.1.0; extra == "dev"
41
+ Requires-Dist: mypy>=0.990; extra == "dev"
42
+ Provides-Extra: docs
43
+ Requires-Dist: mkdocs>=1.5.0; extra == "docs"
44
+ Requires-Dist: mkdocs-material>=9.0.0; extra == "docs"
45
+ Requires-Dist: mkdocstrings[python]>=0.24.0; extra == "docs"
46
+ Dynamic: license-file
47
+
48
+ # ๐Ÿž TextBaker
49
+
50
+ [![CI](https://github.com/q-viper/text-baker/actions/workflows/ci.yml/badge.svg)](https://github.com/q-viper/text-baker/actions/workflows/ci.yml)
51
+ [![PyPI version](https://badge.fury.io/py/textbaker.svg)](https://badge.fury.io/py/textbaker)
52
+ [![Python 3.9+](https://img.shields.io/badge/python-3.9+-blue.svg)](https://www.python.org/downloads/)
53
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
54
+
55
+ **Synthetic Text Dataset Generator for OCR Training**
56
+
57
+ TextBaker is a powerful tool for generating synthetic text images by combining character datasets with backgrounds and applying various transformations. Perfect for training OCR models, data augmentation, and creating synthetic datasets.
58
+
59
+ ![TextBaker Demo](assets/icon.png)
60
+
61
+ ## โœจ Features
62
+
63
+ - ๐ŸŽจ **GUI Application** - Interactive interface for real-time text generation
64
+ - ๐Ÿ–ฅ๏ธ **CLI Tool** - Batch processing from command line
65
+ - ๐Ÿ“š **Python Library** - Programmatic API for integration
66
+ - ๐Ÿ”„ **Transformations** - Rotation, perspective, scale, shear
67
+ - ๐ŸŽญ **Textures** - Apply texture overlays to text
68
+ - ๐Ÿ–ผ๏ธ **Backgrounds** - Composite text on background images
69
+ - ๐ŸŽฒ **Random Generation** - Generate random text with configurable parameters
70
+ - ๐Ÿ”ง **YAML/JSON Configs** - Save and load configurations
71
+ - ๐ŸŽฏ **Reproducible** - Seed-based random generation for reproducibility
72
+
73
+ ## ๐Ÿ“ฆ Installation
74
+
75
+ ### From PyPI
76
+
77
+ ```bash
78
+ pip install textbaker
79
+ ```
80
+
81
+ ### From Source
82
+
83
+ ```bash
84
+ git clone https://github.com/q-viper/text-baker.git
85
+ cd text-baker
86
+ pip install -e .
87
+ ```
88
+
89
+ ### With Development Dependencies
90
+
91
+ ```bash
92
+ pip install -e ".[dev]"
93
+ ```
94
+
95
+ ## ๐Ÿš€ Quick Start
96
+
97
+ ### GUI Application
98
+
99
+ Launch the interactive GUI:
100
+
101
+ ```bash
102
+ textbaker
103
+ ```
104
+
105
+ Or with pre-configured paths:
106
+
107
+ ```bash
108
+ textbaker -d ./dataset -o ./output -b ./backgrounds -t ./textures
109
+ ```
110
+
111
+ ### Command Line
112
+
113
+ Generate text images from the command line:
114
+
115
+ ```bash
116
+ # Generate specific texts
117
+ textbaker generate "Hello" "World" -d ./dataset -o ./output
118
+
119
+ # Generate 100 random samples
120
+ textbaker generate -n 100 --seed 42 -d ./dataset
121
+
122
+ # Apply transformations
123
+ textbaker generate "Hello" --rotation "-15,15" --perspective "0,0.1"
124
+
125
+ # With backgrounds and textures
126
+ textbaker generate "Hello" -b ./backgrounds -t ./textures --texture-opacity 0.8
127
+ ```
128
+
129
+ ### Python Library
130
+
131
+ ```python
132
+ from textbaker import TextGenerator, GeneratorConfig, TransformConfig
133
+
134
+ # Simple usage
135
+ generator = TextGenerator()
136
+ result = generator.generate("Hello")
137
+ generator.save(result)
138
+
139
+ # With custom configuration
140
+ config = GeneratorConfig(
141
+ seed=42,
142
+ dataset={"dataset_dir": "./my_dataset"},
143
+ transform=TransformConfig(
144
+ rotation_range=(-15, 15),
145
+ perspective_range=(0, 0.1),
146
+ scale_range=(0.9, 1.1),
147
+ ),
148
+ output={"output_dir": "./output"},
149
+ )
150
+
151
+ generator = TextGenerator(config)
152
+
153
+ # Generate specific text
154
+ result = generator.generate("TextBaker")
155
+ print(f"Generated: {result.text}, Labels: {result.labels}")
156
+
157
+ # Generate random text
158
+ result = generator.generate_random(length=5)
159
+
160
+ # Batch generation
161
+ results = generator.batch_generate(["Hello", "World", "Test"])
162
+ ```
163
+
164
+ ## ๐Ÿ“ Dataset Structure
165
+
166
+ Organize your character images in folders named by the character:
167
+
168
+ ```
169
+ dataset/
170
+ โ”œโ”€โ”€ A/
171
+ โ”‚ โ”œโ”€โ”€ sample1.png
172
+ โ”‚ โ”œโ”€โ”€ sample2.png
173
+ โ”‚ โ””โ”€โ”€ ...
174
+ โ”œโ”€โ”€ B/
175
+ โ”‚ โ””โ”€โ”€ ...
176
+ โ”œโ”€โ”€ 0/
177
+ โ”‚ โ””โ”€โ”€ ...
178
+ โ””โ”€โ”€ special_char/
179
+ โ””โ”€โ”€ ...
180
+ ```
181
+
182
+ Each character folder should contain PNG images (preferably with transparency) of that character in various styles.
183
+
184
+ ## โš™๏ธ Configuration
185
+
186
+ ### YAML Configuration
187
+
188
+ Create a config file:
189
+
190
+ ```bash
191
+ textbaker init-config -o config.yaml
192
+ ```
193
+
194
+ Example `config.yaml`:
195
+
196
+ ```yaml
197
+ seed: 42
198
+ dataset:
199
+ dataset_dir: ./dataset
200
+ recursive: true
201
+ extensions: [".png", ".jpg"]
202
+ transform:
203
+ rotation_range: [-15, 15]
204
+ perspective_range: [0, 0.1]
205
+ scale_range: [0.9, 1.1]
206
+ shear_range: [0, 0]
207
+ color:
208
+ random_color: true
209
+ color_range_r: [0, 255]
210
+ color_range_g: [0, 255]
211
+ color_range_b: [0, 255]
212
+ texture:
213
+ enabled: true
214
+ texture_dir: ./textures
215
+ opacity: 0.8
216
+ background:
217
+ enabled: true
218
+ background_dir: ./backgrounds
219
+ output:
220
+ output_dir: ./output
221
+ format: png
222
+ ```
223
+
224
+ Use with CLI:
225
+
226
+ ```bash
227
+ textbaker generate "Hello" --config config.yaml
228
+ ```
229
+
230
+ Or in Python:
231
+
232
+ ```python
233
+ from textbaker import GeneratorConfig, TextGenerator
234
+
235
+ config = GeneratorConfig.from_file("config.yaml")
236
+ generator = TextGenerator(config)
237
+ ```
238
+
239
+ ## ๐ŸŽจ GUI Features
240
+
241
+ - **Character Selection** - Select which characters to use
242
+ - **Real-time Preview** - See generated text instantly
243
+ - **Drag & Drop** - Position text on canvas
244
+ - **Resize & Rotate** - Interactive handles for transformation
245
+ - **Texture Picker** - Select texture regions interactively
246
+ - **Background Selection** - Choose random backgrounds
247
+ - **Export** - Save generated images and configurations
248
+
249
+ ### Keyboard Shortcuts
250
+
251
+ | Shortcut | Action |
252
+ |----------|--------|
253
+ | Mouse Wheel | Zoom in/out |
254
+ | Space + Drag | Pan view |
255
+ | Click + Drag | Move text |
256
+ | Corner handles | Resize text |
257
+ | Center handle | Rotate text |
258
+
259
+ ## ๐Ÿ”ง CLI Commands
260
+
261
+ ```bash
262
+ # Show help
263
+ textbaker --help
264
+
265
+ # Launch GUI
266
+ textbaker gui
267
+
268
+ # Generate images
269
+ textbaker generate --help
270
+
271
+ # Create config file
272
+ textbaker init-config --help
273
+ ```
274
+
275
+ ### Generate Command Options
276
+
277
+ | Option | Description |
278
+ |--------|-------------|
279
+ | `-d, --dataset` | Path to character dataset |
280
+ | `-o, --output` | Output directory |
281
+ | `-b, --background` | Background images directory |
282
+ | `-t, --texture` | Texture images directory |
283
+ | `-n, --count` | Number of random samples |
284
+ | `--seed` | Random seed for reproducibility |
285
+ | `-r, --rotation` | Rotation range (e.g., "-15,15") |
286
+ | `-p, --perspective` | Perspective range (e.g., "0,0.1") |
287
+ | `--scale` | Scale range (e.g., "0.9,1.1") |
288
+ | `--random-color` | Enable random coloring |
289
+ | `--color` | Fixed color (e.g., "255,0,0") |
290
+ | `--config` | Load from config file |
291
+
292
+ ## ๐Ÿ“– API Reference
293
+
294
+ ### TextGenerator
295
+
296
+ ```python
297
+ class TextGenerator:
298
+ def __init__(self, config: GeneratorConfig = None): ...
299
+ def generate(self, text: str) -> GenerationResult: ...
300
+ def generate_random(self, length: int = None) -> GenerationResult: ...
301
+ def batch_generate(self, texts: list[str]) -> list[GenerationResult]: ...
302
+ def save(self, result: GenerationResult, filename: str = None) -> Path: ...
303
+ @property
304
+ def available_characters(self) -> list[str]: ...
305
+ ```
306
+
307
+ ### GenerationResult
308
+
309
+ ```python
310
+ @dataclass
311
+ class GenerationResult:
312
+ image: np.ndarray # BGRA image array
313
+ text: str # Generated text
314
+ labels: list[str] # Character labels
315
+ seed: int # Seed used
316
+ params: dict # Generation parameters
317
+ ```
318
+
319
+ ### Configuration Classes
320
+
321
+ - `GeneratorConfig` - Main configuration
322
+ - `TransformConfig` - Transformation settings
323
+ - `ColorConfig` - Color settings
324
+ - `TextureConfig` - Texture settings
325
+ - `BackgroundConfig` - Background settings
326
+ - `DatasetConfig` - Dataset settings
327
+ - `OutputConfig` - Output settings
328
+
329
+ ## ๐Ÿงช Development
330
+
331
+ ### Setup
332
+
333
+ ```bash
334
+ git clone https://github.com/q-viper/text-baker.git
335
+ cd text-baker
336
+ pip install -e ".[dev]"
337
+ ```
338
+
339
+ ### Run Tests
340
+
341
+ ```bash
342
+ pytest tests/ -v
343
+ ```
344
+
345
+ ### Run Linting
346
+
347
+ ```bash
348
+ ruff check .
349
+ ruff format .
350
+ ```
351
+
352
+ ### Build Documentation
353
+
354
+ ```bash
355
+ mkdocs serve
356
+ ```
357
+
358
+ ## ๐Ÿ“„ License
359
+
360
+ MIT License - see [LICENSE](LICENSE) for details.
361
+
362
+ ## ๐Ÿค Contributing
363
+
364
+ Contributions are welcome! Please feel free to submit a Pull Request.
365
+
366
+ 1. Fork the repository
367
+ 2. Create your feature branch (`git checkout -b feature/amazing-feature`)
368
+ 3. Commit your changes (`git commit -m 'Add amazing feature'`)
369
+ 4. Push to the branch (`git push origin feature/amazing-feature`)
370
+ 5. Open a Pull Request
371
+
372
+ ## ๐Ÿ‘ค Author
373
+
374
+ **Ramkrishna Acharya** ([@q-viper](https://github.com/q-viper))
375
+
376
+ ## ๐Ÿ™ Acknowledgments
377
+
378
+ - Built with [PySide6](https://doc.qt.io/qtforpython-6/)
379
+ - Image processing with [OpenCV](https://opencv.org/)
380
+ - CLI powered by [Typer](https://typer.tiangolo.com/)