代码拉取完成,页面将自动刷新
from PIL import Image
import math,os
from xml.etree import ElementTree as ET
def keep_image_size_open(path, size=(256, 256)):
img = Image.open(path)
temp = max(img.size)
mask = Image.new('RGB', (temp, temp), (0, 0, 0))
mask.paste(img, (0, 0))
mask = mask.resize(size)
return mask
def make_data_center_txt(xml_dir):
with open('data_center.txt', 'a') as f:
f.truncate(0)
path=r'data/images'
xml_names = os.listdir(xml_dir)
for xml in xml_names:
xml_path = os.path.join(xml_dir, xml)
in_file = open(xml_path)
tree = ET.parse(in_file)
root = tree.getroot()
image_path = root.find('path')
polygon = root.find('outputs/object/item/polygon')
data = []
c_data = []
data_str = ''
print(xml)
for i in polygon:
data.append(int(i.text))
data_str = data_str + ' ' + str(i.text)
for i in range(0, len(data), 2):
c_data.append((data[i], data[i + 1]))
data_str = os.path.join(path,image_path.text.split('\\')[-1]) +data_str
f.write(data_str + '\n')
if __name__ == '__main__':
make_data_center_txt('data/xml')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。