2. The results are `fake_bg.jpg`, `fake_text.jpg` and `fake_fusion.jpg` as shown in the figure above. Above them:
* Note: The language options is correspond to the corpus. Currently, the tool only supports English, Simplified Chinese and Korean.
*`fake_text.jpg` is the generated image with the same font style as `Style Input`;
*`fake_bg.jpg` is the generated image of `Style Input` after removing foreground.
For example, enter the following image and corpus `PaddleOCR`.
*`fake_fusion.jpg` is the final result, that is synthesised by `fake_text.jpg` and `fake_bg.jpg`.
<divalign="center">
<imgsrc="examples/style_images/2.jpg"width="300">
</div>
The result `fake_fusion.jpg` will be generated.
<divalign="center">
<imgsrc="doc/images/4.jpg"width="300">
</div>
What's more, the medium result `fake_bg.jpg` will also be saved, which is the background output.
<divalign="center">
<imgsrc="doc/images/7.jpg"width="300">
</div>
`fake_text.jpg`*`fake_text.jpg` is the generated image with the same font style as `Style Input`.
3. If want to generate image by other `Style Input` or `Text Input`, you can modify the `tools/synth_image.py`:
*`img = cv2.imread("examples/style_images/1.jpg")`: the path of `Style Input`;
*`corpus = "PaddleOCR"`: the `Text Input`;
* Notice:modify the language option(`language = "en"`) to adapt `Text Input`, that support `en`, `ch`, `ko`.
4. We also provide `batch_synth_images` mothod, that can combine corpus and pictures in pairs to generate a batch of data.
<divalign="center">
<imgsrc="doc/images/8.jpg"width="300">
</div>
#### Batch synthesis
#### Batch synthesis
Before the start, you need to prepare some data as material.
In actual application scenarios, it is often necessary to synthesize pictures in batches and add them to the training set. StyleText can use a batch of style pictures and corpus to synthesize data in batches. The synthesis process is as follows:
First, you should have the style reference data for synthesis tasks, which are generally used as datasets for OCR recognition tasks.
1. The referenced dataset can be specifed in `configs/dataset_config.yml`:
1. The referenced dataset can be specifed in `configs/dataset_config.yml`:
*`StyleSampler`:
*`method`: The method of `StyleSampler`.
*`image_home`: The directory of pictures.
*`label_file`: The list of pictures path if `with_label` is `false`, otherwise, the label file path.
*`with_label`: The `label_file` is label file or not.
*`CorpusGenerator`:
*`Global`:
*`method`: The mothod of `CorpusGenerator`. If `FileCorpus` used, you need modify `corpus_file` and `language` accordingly, if `EnNumCorpus`, other configurations is not needed.
*`output_dir:`:Output synthesis data path.
*`language`: The language of the corpus. Needed if method is not `EnNumCorpus`.
*`StyleSampler`:
*`corpus_file`: The corpus file path. Needed if method is not `EnNumCorpus`.
*`image_home`:style images' folder.
*`label_file`:Style images' file list. If label is provided, then it is the label file path.
*`with_label`:Whether the `label_file` is label file list.
*`CorpusGenerator`:
*`method`:Method of CorpusGenerator,supports `FileCorpus` and `EnNumCorpus`. If `EnNumCorpus` is used,No other configuration is needed,otherwise you need to set `corpus_file` and `language`.
*`language`:Language of the corpus.
*`corpus_file`: Filepath of the corpus.
We provide a general dataset containing Chinese, English and Korean (50,000 images in all) for your trial ([download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/style_text/chkoen_5w.tar)), some examples are given below :
We provide a general dataset containing Chinese, English and Korean (50,000 images in all) for your trial ([download link](https://paddleocr.bj.bcebos.com/dygraph_v2.0/style_text/chkoen_5w.tar)), some examples are given below :
...
@@ -112,22 +131,13 @@ We provide a general dataset containing Chinese, English and Korean (50,000 imag
...
@@ -112,22 +131,13 @@ We provide a general dataset containing Chinese, English and Korean (50,000 imag
We take two scenes as examples, which are metal surface English number recognition and general Korean recognition, to illustrate practical cases of using StyleText to synthesize data to improve text recognition. The following figure shows some examples of real scene images and composite images:
We take two scenes as examples, which are metal surface English number recognition and general Korean recognition, to illustrate practical cases of using StyleText to synthesize data to improve text recognition. The following figure shows some examples of real scene images and composite images:
<divalign="center">
<divalign="center">
<imgsrc="doc/images/6.png"width="800">
<imgsrc="doc/images/11.png"width="800">
</div>
</div>
...
@@ -141,40 +151,41 @@ After adding the above synthetic data for training, the accuracy of the recognit
...
@@ -141,40 +151,41 @@ After adding the above synthetic data for training, the accuracy of the recognit
<aname="Code_structure"></a>
<aname="Code_structure"></a>
### Code Structure
### Code Structure
```
```
style_text_rec
style_text_rec
|-- arch
|-- arch // Network module files.
| |-- base_module.py
| |-- base_module.py
| |-- decoder.py
| |-- decoder.py
| |-- encoder.py
| |-- encoder.py
| |-- spectral_norm.py
| |-- spectral_norm.py
| `-- style_text_rec.py
| `-- style_text_rec.py
|-- configs
|-- configs // Config files.
| |-- config.yml
| |-- config.yml
| `-- dataset_config.yml
| `-- dataset_config.yml
|-- engine
|-- engine // Synthesis engines.
| |-- corpus_generators.py
| |-- corpus_generators.py // Sample corpus from file or generate random corpus.
| |-- predictors.py
| |-- predictors.py // Predict using network.
| |-- style_samplers.py
| |-- style_samplers.py // Sample style images.
| |-- synthesisers.py
| |-- synthesisers.py // Manage other engines to synthesis images.
| |-- text_drawers.py
| |-- text_drawers.py // Generate standard input text images.
| `-- writers.py
| `-- writers.py // Write synthesis images and labels into files.