3 Star 16 Fork 5

qiaofengsheng/point_regression

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
utils.py 1.25 KB
一键复制 编辑 原始数据 按行查看 历史
qiaofengsheng 提交于 2022-01-13 22:39 . 2022年01月13日提交
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')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/qiaofengsheng/point_regression.git
git@gitee.com:qiaofengsheng/point_regression.git
qiaofengsheng
point_regression
point_regression
master

搜索帮助