DataProcessToolProgram/tools/SpacetySliceDataTools/DotaOperator.py

81 lines
2.4 KiB
Python
Raw Normal View History

2025-08-22 17:26:51 +00:00
import os
import argparse
"""
Dota数据集标注
每条标注数据应包含
+ 8 个数值表示目标的四个角点的坐标x1, y1, x2, y2, x3, y3, x4, y4按顺时针或逆时针顺序排列无需进行归一化处理
+倒数第二列为标注的目标类别名称jun_ship等
+最后一列为识别目标的难易程度difficulty
提供数据集标注
"""
class DotaObj(object):
def __init__(self, x1, y1, x2, y2, x3, y3, x4, y4,clsname,difficulty):
self.x1=x1
self.y1=y1
self.x2=x2
self.y2=y2
self.x3=x3
self.y3=y3
self.x4=x4
self.y4=y4
self.clsname=clsname
self.difficulty=difficulty
def __str__(self):
return "{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}".format(
self.x1,self.y1,
self.x2,self.y2,
self.x3,self.y3,
self.x4,self.y4,
self.clsname,self.difficulty
)
def createDota(x1, y1, x2, y2, x3, y3, x4, y4,clsname,difficulty):
return DotaObj(x1, y1, x2, y2, x3, y3, x4, y4,clsname,difficulty) # 8+2
def readDotaFile(dotafilepath):
content=None
with open(dotafilepath,'r',encoding="utf-8") as fp:
content=fp.read()
contentlines=content.split("\n")
# 逐行分解
result=[]
for linestr in contentlines:
linestr=linestr.replace("\t"," ")
linestr=linestr.replace(" "," ")
linemetas=linestr.split(" ")
if(len(linemetas)>=10):
x1=float(linemetas[0])
y1=float(linemetas[1])
x2=float(linemetas[2])
y2=float(linemetas[3])
x3=float(linemetas[4])
y3=float(linemetas[5])
x4=float(linemetas[6])
y4=float(linemetas[7])
clsname=linemetas[8]
difficulty=linemetas[9]
result.append(createDota(x1, y1, x2, y2, x3, y3, x4, y4, clsname,difficulty))
else:
print("parse result: ", linestr)
return result
def writerDotaFile(dotalist,filepath):
with open(filepath,'a',encoding="utf-8") as fp:
for dota in dotalist:
if isinstance(dota,DotaObj):
fp.write("{}\n".format(str(dota)))
else:
fp.write("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9}\n".format(
dota[0],dota[1],dota[2],dota[3],dota[4],dota[5],dota[6],dota[7],dota[8],dota[9]
))