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

Add relics name image generator | 遗器套装名称生成 #577

Open
wants to merge 19 commits into
base: dev
Choose a base branch
from

Conversation

antecanis8
Copy link

issue-569
先解包遗器套装名称到./tasks/relics/keywords/relics.py 然后生成图片
判断图片是否存在 不存在则用ImageDraw.Draw绘制 然后findContours裁切 图片文件名称是解包出来的name 用下划线分割
生成的图片放在./assets/cn/relics/name/和./assets/en/relics/name/

Copy link
Owner

@LmeSzinc LmeSzinc left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 需要配套的识别代码,表示生成的图片是可以使用的
  2. 图片放在 assets/{server}/relics 下会被 button_extract 提取为 assets,但它们是单纯的模板,需要解决

Comment on lines 10 to 11
def crop_to_text_edge(original_image):
gray = cv2.cvtColor(original_image, cv2.COLOR_BGR2GRAY)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

复用 get_bbox()

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

多行文字直接取第一行来匹配特征足够了,第二行可以丢弃

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 56 to 58
image = np.ones((50, 370, 3), dtype=np.uint8) * 255

image_pil = Image.fromarray(cv2.cvtColor(image, cv2.COLOR_BGR2RGB))
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这是刚创建的纯白色图片,BGR2RGB没有意义因为转换后也是纯白的

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 65 to 69
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')
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

可以直接使用 pillow 保存图片,不需要通过 opencv

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 72 to 90
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)
Copy link
Owner

@LmeSzinc LmeSzinc Jul 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. 封装为类,方便日后复用类生成其他文字
  2. with open('./tasks/relics/keywords/relics.py' 改成 local import tasks/relics/keywords/relics.py
  3. 需要抽象出语言和字体参数
  4. 图片生成作为开发工具不会经常运行,每次运行前清空目标文件夹以保证图片最新

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Comment on lines 6 to 14
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',
)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. ItemConfig 改名叫 RelicSet
  2. ItemConfig 类的代码未添加入 git
  3. 既然生成了套装,那把套装的游戏内id,来源副本id,也提取出来

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

模板图片转为单通道

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@LmeSzinc LmeSzinc added the feature request / 功能请求 New feature or requests label Jul 15, 2024
@LmeSzinc LmeSzinc changed the base branch from master to dev July 15, 2024 17:21
@LmeSzinc LmeSzinc added the good first issue / 首次贡献 Good for newcomers label Jul 17, 2024
@antecanis8
Copy link
Author

配套的识别代码在写了,现在的主要问题就是当游戏背景为白色的时候,二值化不正确导致无法识别。背景过于白的时候,findContours也都不对了。
图片被 button_extract 提取为 assets 已经解决,在button_extract 的AssetsImage.parse加了判断

…arize

转换为HSV色彩空间,生成橙色和白色掩膜 (遗器信息文字是橙色和纯白色的) 以实现正确的二值化。然后遗器套装就可以正确识别了。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants