-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCardClassifier.py
More file actions
53 lines (41 loc) · 1.74 KB
/
Copy pathCardClassifier.py
File metadata and controls
53 lines (41 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
import os
import shutil
import pandas as pd
# 读取CSV文件
df = pd.read_csv('cards.csv')
place = r'./assets\cards_pic'
output_place = r'./assets\cards_pic_classified'
# 创建字典存储每个faction的信息
faction_data = {}
# 遍历DataFrame,按faction分组
for index, row in df.iterrows():
faction = row['data-faction']
data_id = row['data-id']
provision = row['data-provision']
power = row['data-power']
# 如果faction不存在,添加到字典中
if faction not in faction_data:
faction_data[faction] = []
# 添加数据到对应faction的列表中
faction_data[faction].append((data_id, provision, power))
# 对每个faction的数据进行排序
for faction, data_list in faction_data.items():
# 排序数据
sorted_data = sorted(data_list, key=lambda x: (-x[1], -x[2], x[0]))
# 创建faction文件夹
faction_folder = fr'{output_place}\faction_{faction}'
os.makedirs(faction_folder, exist_ok=True)
# 创建子文件夹:一个用于图像,一个用于描述
image_subfolder = os.path.join(faction_folder, 'images')
desc_subfolder = os.path.join(faction_folder, 'descriptions')
os.makedirs(image_subfolder, exist_ok=True)
os.makedirs(desc_subfolder, exist_ok=True)
# 移动和重命名文件
for i, (data_id, _, _) in enumerate(sorted_data):
image_file = fr'{place}\card_image_{data_id}.png'
desc_file = fr'{place}\card_description_{data_id}.png'
new_image_name = fr'{i+1}_image_{data_id}.png'
new_desc_name = fr'{i+1}_desc_{data_id}.png'
shutil.copy(image_file, os.path.join(image_subfolder, new_image_name))
shutil.copy(desc_file, os.path.join(desc_subfolder, new_desc_name))
print("分类和重命名完成")