OCR text recognition rec data synthesis production

When doing text recognition, often due to the lack of rec training data, you need to generate some data to add to the training. Here I use  TextRecognitionDataGenerator  to generate the data I need.

1. How to use:

Download the code repository:

git clone https://github.com/Belval/TextRecognitionDataGenerator

# 安装一下依赖库
pip3 install -r requirements.txt
pip3 install -r requirements-hw.txt
cd TextRecognitionDataGenerator/trdg
python run.py -c 10

10 text line samples can be generated and saved in the out directory.

2. Errors encountered:

When running python run.py -c 10, the following error occurs:

AttributeError: module 'PIL.Image' has no attribute 'Resampling'

The reason is that PIL.Image does not have the property Resampling.

3. Solution:

First upgrade your pillow version:

pip install --upgrade pillow -i https://pypi.tuna.tsinghua.edu.cn/simple

I upgraded my version from 7.1.0 to 8.4.0, and then ran python run.py -c 10 and found that the same error still exists, because my version 8.4.0 still does not have this Resampling attribute. But pillow can no longer be upgraded, because I use python3.6 version, python3.6 supports pillow 8.4.0 at most

To further solve the problem:

Open the trdg/data_generator.py file, find about line 133, and modify the code:

Just remove Resampling from Image.Resampling.LANCZOS and Image.Resampling.NEAREST.

resized_img = distorted_img.resize(
                (new_width, size - vertical_margin), Image.Resampling.LANCZOS
            )
resized_mask = distorted_mask.resize(
                (new_width, size - vertical_margin), Image.Resampling.NEAREST
            )


# 改成
resized_img = distorted_img.resize(
                (new_width, size - vertical_margin), Image.LANCZOS
            )
resized_mask = distorted_mask.resize(
                (new_width, size - vertical_margin), Image.NEAREST
            )

 

Guess you like

Origin blog.csdn.net/u012505617/article/details/129832948