Skip to content

Commit 13b22cc

Browse files
bactBelval
authored andcommitted
Update README.md
1 parent 48f36a7 commit 13b22cc

1 file changed

Lines changed: 34 additions & 16 deletions

File tree

README.md

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,20 +27,27 @@ tqdm
2727
- Change the text orientation using the `-or` parameter
2828
- Change the space width using the `-sw` parameter
2929
- Specify text color range using `-tc '#000000,#FFFFFF'`, please note that the quotes are **necessary**
30-
- Explicit alignement when using `-al` with fixed width (0: Left, 1: Center, 2: Right)
30+
- Explicit alignment when using `-al` with fixed width (0: Left, 1: Center, 2: Right)
3131
- Add support for Simplified and Traditional Chinese
3232

3333
## How does it work?
34+
35+
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.
36+
37+
### Basic
38+
3439
`python run.py -w 5 -f 64`
3540

36-
You get 1000 randomly generated images with random text on them like:
41+
You get 1,000 randomly generated images with random text on them like:
3742

3843
![1](samples/1.jpg "1")
3944
![2](samples/2.jpg "2")
4045
![3](samples/3.jpg "3")
4146
![4](samples/4.jpg "4")
4247
![5](samples/5.jpg "5")
4348

49+
### Text skewing
50+
4451
What if you want random skewing? Add `-k` and `-rk` (`python run.py -w 5 -f 64 -k 5 -rk`)
4552

4653
![6](samples/6.jpg "6")
@@ -49,13 +56,24 @@ What if you want random skewing? Add `-k` and `-rk` (`python run.py -w 5 -f 64 -
4956
![9](samples/9.jpg "9")
5057
![10](samples/10.jpg "10")
5158

59+
### Text distortion
60+
You can also add distorsion to the generated text with `-d` and `-do`
61+
62+
![23](samples/24.jpg "0")
63+
![24](samples/25.jpg "1")
64+
![25](samples/26.jpg "2")
65+
66+
### Text blurring
67+
5268
But scanned document usually aren't that clear are they? Add `-bl` and `-rbl` to get gaussian blur on the generated image with user-defined radius (here 0, 1, 2, 4):
5369

5470
![11](samples/11.jpg "0")
5571
![12](samples/12.jpg "1")
5672
![13](samples/13.jpg "2")
5773
![14](samples/14.jpg "4")
5874

75+
### Background
76+
5977
Maybe you want another background? Add `-b` to define one of the three available backgrounds: gaussian noise (0), plain white (1), quasicrystal (2) or picture (3).
6078

6179
![15](samples/15.jpg "0")
@@ -65,6 +83,8 @@ Maybe you want another background? Add `-b` to define one of the three available
6583

6684
When using picture background (3). A picture from the pictures/ folder will be randomly selected and the text will be written on it.
6785

86+
### Handwritten
87+
6888
Or maybe you are working on an OCR for handwritten text? Add `-hw`! (Experimental)
6989

7090
![18](samples/18.jpg "0")
@@ -77,21 +97,18 @@ It uses a Tensorflow model trained using [this excellent project](https://github
7797

7898
**The project does not require TensorFlow to run if you aren't using this feature**
7999

80-
You can also add distorsion to the generated text with `-d` and `-do`
81-
82-
![23](samples/24.jpg "0")
83-
![24](samples/25.jpg "1")
84-
![25](samples/26.jpg "2")
100+
### Dictionary
85101

86102
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
87103

88-
There are a lot of parameters that you can tune to get the results you want, therefore I recommand checking out `python run.py -h` for more informations.
104+
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.
89105

90-
## How to create images with Chinese (both simplified and traditional) text
106+
## Create images with Chinese text
91107

92108
It is simple! Just do `python run.py -l cn -c 1000 -w 5`!
93109

94-
Unfortunately I do not speak Chinese so you may have to edit `texts/cn.txt` to include some meaningful words instead of random glyphs.
110+
Generated texts come both in simplified and traditional Chinese scripts.
111+
You may have to edit `texts/cn.txt` to include some meaningful words instead of random glyphs.
95112

96113
Here are examples of what I could make with it:
97114

@@ -103,21 +120,20 @@ Simplified:
103120

104121
![28](samples/28.jpg "1")
105122

106-
## Can I add my own font?
123+
## Add new fonts
107124

108-
Yes, the script picks a font at random from the *fonts* directory.
125+
The script picks a font at random from the *fonts* directory.
109126

110-
|||
127+
| Directory | Languages |
111128
|:----|:-----|
112129
| fonts/latin | English, French, Spanish, German |
113130
| fonts/cn | Chinese |
114-
|||
115131

116-
Simply add / remove fonts until you get the desired output.
132+
Simply add/remove fonts until you get the desired output.
117133

118134
If you want to add a new non-latin language, the amount of work is minimal.
119135

120-
1. Create a new folder with your language two-letters code
136+
1. Create a new folder with your language [two-letters code](https://en.wikipedia.org/wiki/List_of_ISO_639-1_codes)
121137
2. Add a .ttf font in it
122138
3. Edit `run.py` to add an if statement in `load_fonts()`
123139
4. Add a text file in `dicts` with the same two-letters code
@@ -127,6 +143,8 @@ It only supports .ttf for now.
127143

128144
## Benchmarks
129145

146+
Number of images generated per second.
147+
130148
- Intel Core i7-4710HQ @ 2.50Ghz + SSD (-c 1000 -w 1)
131149
- `-t 1` : 363 img/s
132150
- `-t 2` : 694 img/s

0 commit comments

Comments
 (0)