TextRecognitionDataGenerator icon indicating copy to clipboard operation
TextRecognitionDataGenerator copied to clipboard

Handwritten Text Too Small/Skewed

Open abdksyed opened this issue 3 years ago • 3 comments

Hi,

I am trying to create handwritten text.

But the images being generated are way too small. For the same command for printed text the images are fine, giving same command.

# For Handwritten
trdg --input_file my_dict.txt --count 3  --name_format 2 -hw

# For Printed
trdg --input_file my_dict.txt --count 3  --name_format 2 

Printed Text:

image image image

For the same Data Handwritten Text image image image

I tried to increase the size by giving --format 64 and --width 128 for handwritten text. But suddenly the text is curly. image image image

abdksyed avatar Nov 19 '21 14:11 abdksyed

I have same issues, any updates? @Belval

dhea1323 avatar May 17 '22 04:05 dhea1323

The issue is with deriving the width of the image under data generator.py. I commented out the new width derivation and simply replaced that with the width of image which we get after applying distortion. This resolved the issue for me. Following is the code snippet

        ##################################
        # Resize image to desired format #
        ##################################

        # Horizontal text
        if orientation == 0:
            # new_width = int(
            #     distorted_img.size[0]
            #     * (float(size - vertical_margin) / float(distorted_img.size[1]))
            # )
            new_width = distorted_img.size[0]
            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
            )
            background_width = width if width > 0 else new_width + horizontal_margin
            background_height = size

riteshKumarUMass avatar Nov 22 '22 19:11 riteshKumarUMass

@riteshKumarUMass , Thank you. This really helps!

cramraj8 avatar Jul 22 '23 18:07 cramraj8