You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -8,19 +8,9 @@ Generating text image samples to train an OCR software. Now supporting non-latin
8
8
9
9
## What do I need to make it work?
10
10
11
-
I use Archlinux so I cannot tell if it works on Windows yet.
11
+
Just install the pip package using `pip install trdg`. Afterwards, you can use `trdg` from the CLI. I recommend using a virtualenv instead of installing with `sudo`.
12
12
13
-
```
14
-
Python 3.X
15
-
OpenCV 4 (Works with 3.2, probably works with 2.4)
16
-
Pillow
17
-
Numpy
18
-
Requests
19
-
BeautifulSoup
20
-
tqdm
21
-
```
22
-
23
-
You can simply use `pip install -r requirements.txt` too.
13
+
If you want to add another language, you can clone the repository instead. Simply run `pip install -r requirements.txt`
- Move `run.py` to an executable python file ([`trdg/bin/trdg`](trdg/bin/trdg))
38
30
- Add `--font` to use only one font for all the generated images (Thank you @JulienCoutault!)
39
31
- Add `--fit` and `--margins` for finer layout control
40
32
- Change the text orientation using the `-or` parameter
41
-
- Change the space width using the `-sw` parameter
42
33
- Specify text color range using `-tc '#000000,#FFFFFF'`, please note that the quotes are **necessary**
43
-
- Explicit alignment when using `-al` with fixed width (0: Left, 1: Center, 2: Right)
44
34
- Add support for Simplified and Traditional Chinese
45
35
46
36
## How does it work?
47
37
48
38
Words will be randomly chosen from a dictionary of a specific language. Then an image of those words will be generated by using font, background, and modifications (skewing, blurring, etc.) as specified.
49
39
50
-
### Basic
40
+
### Basic (Python module)
41
+
42
+
The usage as a Python module is very similar to the CLI, but it is more flexible if you want to include it directly in your training pipeline, and will consume less space and memory. There are 4 generators that can be used.
51
43
52
-
`python run.py -w 5 -f 64`
44
+
```py
45
+
from TextRecognitionDataGenerator.generators import (
46
+
GeneratorFromDict,
47
+
GeneratorFromRandom,
48
+
GeneratorFromStrings,
49
+
GeneratorFromWikipedia,
50
+
)
51
+
52
+
# The generators use the same arguments as the CLI, only as parameters
You get 1,000 randomly generated images with random text on them like:
55
75
@@ -59,9 +79,11 @@ You get 1,000 randomly generated images with random text on them like:
59
79

60
80

61
81
82
+
By default, they will be generated to `out/` in the current working directory.
83
+
62
84
### Text skewing
63
85
64
-
What if you want random skewing? Add `-k` and `-rk` (`python run.py -w 5 -f 64 -k 5 -rk`)
86
+
What if you want random skewing? Add `-k` and `-rk` (`trdg -c 1000 -w 5 -f 64 -k 5 -rk`)
65
87
66
88

67
89

@@ -114,16 +136,13 @@ It uses a Tensorflow model trained using [this excellent project](https://github
114
136
115
137
The text is chosen at random in a dictionary file (that can be found in the *dicts* folder) and drawn on a white background made with Gaussian noise. The resulting image is saved as [text]\_[index].jpg
116
138
117
-
There are a lot of parameters that you can tune to get the results you want, therefore I recommend checking out `python run.py -h` for more information.
139
+
There are a lot of parameters that you can tune to get the results you want, therefore I recommend checking out `trdg -h` for more information.
118
140
119
141
## Create images with Chinese text
120
142
121
-
It is simple! Just do `python run.py -l cn -c 1000 -w 5`!
143
+
It is simple! Just do `trdg -l cn -c 1000 -w 5`!
122
144
123
145
Generated texts come both in simplified and traditional Chinese scripts.
124
-
You may have to edit `texts/cn.txt` to include some meaningful words instead of random glyphs.
125
-
126
-
Here are examples of what I could make with it:
127
146
128
147
Traditional:
129
148
@@ -148,7 +167,7 @@ If you want to add a new non-latin language, the amount of work is minimal.
148
167
149
168
1. Create a new folder with your language [two-letters code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
150
169
2. Add a .ttf font in it
151
-
3. Edit `run.py` to add an if statement in `load_fonts()`
170
+
3. Edit `bin/trdg` to add an if statement in `load_fonts()`
152
171
4. Add a text file in `dicts` with the same two-letters code
153
172
5. Run the tool as you normally would but add `-l` with your two-letters code
0 commit comments