Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Backslash Rendered as Boxes with Cross Inside #205

Open
Hegelim opened this issue Jun 5, 2023 · 0 comments
Open

Backslash Rendered as Boxes with Cross Inside #205

Hegelim opened this issue Jun 5, 2023 · 0 comments

Comments

@Hegelim
Copy link

Hegelim commented Jun 5, 2023

Issue

When using Synthdog to generate some data, I noticed when the character is backslash, the image would not be able to render it properly. Instead, it would render it as a box with a cross inside, such as
image

Steps to Reproduce

  1. change textbox.py as follows
"""
Donut
Copyright (c) 2022-present NAVER Corp.
MIT License
"""
import numpy as np
from synthtiger import layers
import random


class TextBox:
    def __init__(self, config):
        self.fill = config.get("fill", [1, 1])
        self.charset = """\\"""

    def generate(self, size, text,font):
        width, height = size

        char_layers, chars = [], []
        fill = np.random.uniform(self.fill[0], self.fill[1])
        width = np.clip(width * fill, height, width)
        font = {**font, "size": int(height)}
        left, top = 0, 0

        for char in text:
            if char in "\r\n":
                continue

            rand = random.uniform(0, 1)
            if rand >= 0:
                char = random.choice(self.charset)

            char_layer = layers.TextLayer(char, **font)
            char_scale = height / char_layer.height
            char_layer.bbox = [left, top, *(char_layer.size * char_scale)]
            if char_layer.right > width:
                break

            char_layers.append(char_layer)
            chars.append(char)
            left = char_layer.right

        text = "".join(chars).strip()
        if len(char_layers) == 0 or len(text) == 0:
            return None, None

        text_layer = layers.Group(char_layers).merge()

        return text_layer, text

Then run something like synthtiger -o ./outputs/SynthDoG_exp -c 50 -w 4 -v template.py SynthDoG config_en.yaml inside ./synthdog

Possible Fix

It took me a while until I came across this
https://github.com/clovaai/synthtiger/blob/c00cc7bfa07f8178009ebaa41b64680b0e392701/synthtiger/layers/text_layer.py#L25
I don't know what's the purpose of this line? Somehow it replaces backslash into some other strange character which some of the fonts have trouble rendering. Commenting it out would resolve the backslash issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant