如何在每个字符周围创建边框?

问题描述

我有一个想要像每个字符之间画线的功能我有一些方法,例如采用带有传递参数-coordinate(x,y)序列轴的垂直直线,但无法解决该问题,并且困惑在哪里可以进行一些更改。有帮助吗?

def draw_text_on_bg(self,word,font,bg):
    """
    Draw word in the center of background
    :param word: word to draw
    :param font: font to draw word
    :param bg: background numpy image
    :return:
        np_img: word image
        text_Box_pnts: left-top,right-top,right-bottom,left-bottom
    """
    bg_height = bg.shape[0]
    bg_width = bg.shape[1]

    word_size = self.get_word_size(font,word)
    word_height = word_size[1]
    word_width = word_size[0]

    offset = font.getoffset(word)

    pil_img = Image.fromarray(np.uint8(bg))
    draw = ImageDraw.Draw(pil_img)

    # Draw text in the center of bg
    text_x = int((bg_width - word_width) / 2)
    text_y = int((bg_height - word_height) / 2)

    if self.is_bgr():
        word_color = self.get_word_color()
    else:
        word_color = self.get_gray_word_color(bg,text_x,text_y,word_height,word_width)

    if apply(self.cfg.random_space):
        text_x,word_width,word_height = self.draw_text_with_random_space(draw,word_color,bg_width,bg_height)
        np_img = np.array(pil_img).astype(np.float32)
    else:
        if apply(self.cfg.seamless_clone):
            np_img = self.draw_text_seamless(font,bg,offset)
        else:
            self.draw_text_wrapper(draw,text_x - offset[0],text_y - offset[1],word_color)
            # draw.text((text_x - offset[0],text_y - offset[1]),fill=word_color,font=font)

            np_img = np.array(pil_img).astype(np.float32)

    text_Box_pnts = [
        [text_x,text_y],[text_x + word_width,text_y + word_height],[text_x,text_y + word_height]
    ]

    return np_img,text_Box_pnts,word_color

这里是示例image data,其中尝试进行一些更改。

这是我正在寻找的示例text img data模式。请帮助我,让我完全陷入困境!

我曾经通过合成文本库repo生成文本图像数据。我需要在其中更改textrenderer / renderer.py

中提供的上述功能

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)