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
Copy file name to clipboardExpand all lines: README.md
+34-16Lines changed: 34 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -27,20 +27,27 @@ tqdm
27
27
- Change the text orientation using the `-or` parameter
28
28
- Change the space width using the `-sw` parameter
29
29
- 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)
31
31
- Add support for Simplified and Traditional Chinese
32
32
33
33
## 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
+
34
39
`python run.py -w 5 -f 64`
35
40
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:
37
42
38
43

39
44

40
45

41
46

42
47

43
48
49
+
### Text skewing
50
+
44
51
What if you want random skewing? Add `-k` and `-rk` (`python run.py -w 5 -f 64 -k 5 -rk`)
45
52
46
53

@@ -49,13 +56,24 @@ What if you want random skewing? Add `-k` and `-rk` (`python run.py -w 5 -f 64 -
49
56

50
57

51
58
59
+
### Text distortion
60
+
You can also add distorsion to the generated text with `-d` and `-do`
61
+
62
+

63
+

64
+

65
+
66
+
### Text blurring
67
+
52
68
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):
53
69
54
70

55
71

56
72

57
73

58
74
75
+
### Background
76
+
59
77
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).
60
78
61
79

@@ -65,6 +83,8 @@ Maybe you want another background? Add `-b` to define one of the three available
65
83
66
84
When using picture background (3). A picture from the pictures/ folder will be randomly selected and the text will be written on it.
67
85
86
+
### Handwritten
87
+
68
88
Or maybe you are working on an OCR for handwritten text? Add `-hw`! (Experimental)
69
89
70
90

@@ -77,21 +97,18 @@ It uses a Tensorflow model trained using [this excellent project](https://github
77
97
78
98
**The project does not require TensorFlow to run if you aren't using this feature**
79
99
80
-
You can also add distorsion to the generated text with `-d` and `-do`
81
-
82
-

83
-

84
-

100
+
### Dictionary
85
101
86
102
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
87
103
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.
89
105
90
-
## How to create images with Chinese (both simplified and traditional) text
106
+
## Create images with Chinese text
91
107
92
108
It is simple! Just do `python run.py -l cn -c 1000 -w 5`!
93
109
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.
95
112
96
113
Here are examples of what I could make with it:
97
114
@@ -103,21 +120,20 @@ Simplified:
103
120
104
121

105
122
106
-
## Can I add my own font?
123
+
## Add new fonts
107
124
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.
109
126
110
-
|||
127
+
| Directory | Languages |
111
128
|:----|:-----|
112
129
| fonts/latin | English, French, Spanish, German |
113
130
| fonts/cn | Chinese |
114
-
|||
115
131
116
-
Simply add / remove fonts until you get the desired output.
132
+
Simply add/remove fonts until you get the desired output.
117
133
118
134
If you want to add a new non-latin language, the amount of work is minimal.
119
135
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)
121
137
2. Add a .ttf font in it
122
138
3. Edit `run.py` to add an if statement in `load_fonts()`
123
139
4. Add a text file in `dicts` with the same two-letters code
@@ -127,6 +143,8 @@ It only supports .ttf for now.
0 commit comments