-
Notifications
You must be signed in to change notification settings - Fork 156
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
Add relics name image generator | 遗器套装名称生成 #577
base: dev
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 需要配套的识别代码,表示生成的图片是可以使用的
- 图片放在 assets/{server}/relics 下会被 button_extract 提取为 assets,但它们是单纯的模板,需要解决
dev_tools/text_draw.py
Outdated
def crop_to_text_edge(original_image): | ||
gray = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
复用 get_bbox()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
多行文字直接取第一行来匹配特征足够了,第二行可以丢弃
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dev_tools/text_draw.py
Outdated
image = np.ones((50, 370, 3), dtype=np.uint8) * 255 | ||
|
||
image_pil = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
这是刚创建的纯白色图片,BGR2RGB没有意义因为转换后也是纯白的
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dev_tools/text_draw.py
Outdated
image = cv2.cvtColor(np.array(image_pil), cv2.COLOR_RGB2BGR) | ||
|
||
crop_image = crop_to_text_edge(image) | ||
cv2.imencode('.png', crop_image)[1].tofile(image_path) | ||
logger.info(f'{name} generated') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
可以直接使用 pillow 保存图片,不需要通过 opencv
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
dev_tools/text_draw.py
Outdated
def relics_name_image_generator(): | ||
font_en = ImageFont.truetype("./dev_tools/zh-cn.ttf", 20) | ||
font_cn = ImageFont.truetype("./dev_tools/zh-cn.ttf", 20) | ||
output_path_cn = './assets/cn/relics/name/' | ||
output_path_en = './assets/en/relics/name/' | ||
|
||
with open('./tasks/relics/keywords/relics.py', 'r', encoding='utf-8') as file: | ||
content = file.read() | ||
|
||
cn_pattern = re.compile(r"cn='([^']*)'") | ||
en_pattern = re.compile(r"en='([^']*)'") | ||
name_pattern = re.compile(r"name='([^']*)'") | ||
|
||
cn_values = cn_pattern.findall(content) | ||
en_values = en_pattern.findall(content) | ||
name_values = name_pattern.findall(content) | ||
|
||
text_image_generator(cn_values, name_values, font=font_cn, output_path=output_path_cn) | ||
text_image_generator(en_values, name_values, font=font_en, output_path=output_path_en) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- 封装为类,方便日后复用类生成其他文字
with open('./tasks/relics/keywords/relics.py'
改成 local importtasks/relics/keywords/relics.py
- 需要抽象出语言和字体参数
- 图片生成作为开发工具不会经常运行,每次运行前清空目标文件夹以保证图片最新
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
tasks/relics/keywords/relics.py
Outdated
Passerby_of_Wandering_Cloud = ItemConfig( | ||
id=1, | ||
name='Passerby_of_Wandering_Cloud', | ||
cn='云无留迹的过客', | ||
cht='雲無留跡的過客', | ||
en='Passerby of Wandering Cloud', | ||
jp='流雲無痕の過客', | ||
es='Transeúnte de la nube pasajera', | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- ItemConfig 改名叫 RelicSet
- ItemConfig 类的代码未添加入 git
- 既然生成了套装,那把套装的游戏内id,来源副本id,也提取出来
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
模板图片转为单通道
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
Merge branch 'LmeSzinc:master' into master
Relics name picture will not be extract as buttons
Modify from [LmeSzinc#594](url) 问题:游戏界面背景为白色时,二值化不正确,导致无法识别。
配套的识别代码在写了,现在的主要问题就是当游戏背景为白色的时候,二值化不正确导致无法识别。背景过于白的时候,findContours也都不对了。 |
…arize 转换为HSV色彩空间,生成橙色和白色掩膜 (遗器信息文字是橙色和纯白色的) 以实现正确的二值化。然后遗器套装就可以正确识别了。
issue-569
先解包遗器套装名称到./tasks/relics/keywords/relics.py 然后生成图片
判断图片是否存在 不存在则用ImageDraw.Draw绘制 然后findContours裁切 图片文件名称是解包出来的name 用下划线分割
生成的图片放在./assets/cn/relics/name/和./assets/en/relics/name/