oh-my-ocr / text_renderer

https://oh-my-ocr.github.io/text_renderer/README.html
MIT License
802 stars 161 forks source link

关于生成图片中文本的颜色 #34

Closed ShulinHE closed 3 years ago

ShulinHE commented 3 years ago

请问我想生成白色的文本,但是好像没有成功,是为什么呢? 我在example.py的基础上改动了: def base_cfg( name: str, corpus, corpus_effects=None, layout_effects=None, layout=None, gray=True ): return GeneratorCfg( num_image=50, save_dir=OUT_DIR / name, render_cfg=RenderCfg( bg_dir=BG_DIR, perspective_transform=perspective_transform, gray=gray, layout_effects=layout_effects, layout=layout, corpus=corpus, corpus_effects=corpus_effects, text_color_cfg=FixedTextColorCfg(), # SimpleTextColorCfg(), ), ) 并且把FixedTextColorCfg改了: class FixedTextColorCfg(TextColorCfg):

For generate effect/layout example

def get_color(self, bg_img: PILImage) -> Tuple[int, int, int, int]:
    alpha = 255
    text_color = (255, 255, 255, alpha)

    return text_color
Sanster commented 3 years ago

生成出来是什么样的?

ShulinHE commented 3 years ago

大概是这样的

show
Sanster commented 3 years ago

RenderCfg 的 text_color_cfg 优先级比 CorpusCfg 低,修改 CorpusCfg 的配置

image

ShulinHE commented 3 years ago

谢谢您抽空解决我的问题。我还有一个小疑问,请问这里生成的线条的颜色可以定义么?我自己试图看了一下源码,水平不足,陷入困境。

Sanster commented 3 years ago

https://github.com/oh-my-ocr/text_renderer/blob/master/example_data/example.py#L73

ShulinHE commented 3 years ago

谢谢大佬,问题完美解决了