Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Path: blob/master/DOTA_devkit/results_obb2hbb.py
Views: 475
import os1import argparse2import shutil34def parse_args():5parser = argparse.ArgumentParser(description='Train a detector')6parser.add_argument('--srcpath', default=r'/OrientedRepPoints/tools/parse_pkl/evaluation_results/OBB_results/')7parser.add_argument('--dstpath', default='/OrientedRepPoints/tools/parse_pkl/evaluation_results/HBB_results/',8help='dota version')9args = parser.parse_args()1011return args121314def GetFileFromThisRootDir(dir,ext = None):15allfiles = []16needExtFilter = (ext != None)17for root,dirs,files in os.walk(dir):18for filespath in files:19filepath = os.path.join(root, filespath)20extension = os.path.splitext(filepath)[1][1:]21if needExtFilter and extension in ext:22allfiles.append(filepath)23elif not needExtFilter:24allfiles.append(filepath)25return allfiles2627def custombasename(fullname):28return os.path.basename(os.path.splitext(fullname)[0])2930def OBB2HBB(srcpath, dstpath):31filenames = GetFileFromThisRootDir(srcpath)32if os.path.exists(dstpath):33shutil.rmtree(dstpath) # delete output folderX34os.makedirs(dstpath)3536for file in filenames: # eg: /.../task1_plane.txt3738basename = custombasename(file) # 只留下文件名 eg:'task1_plane'39class_basename = basename.split('_')[-1]40with open(file, 'r') as f_in:41with open(os.path.join(dstpath, 'Task2_' + class_basename + '.txt'), 'w') as f_out:42lines = f_in.readlines()43splitlines = [x.strip().split() for x in lines] # list: n*[]44for index, splitline in enumerate(splitlines):45imgname = splitline[0]46score = splitline[1]47poly = splitline[2:]48poly = list(map(float, poly))49xmin, xmax, ymin, ymax = min(poly[0::2]), max(poly[0::2]), min(poly[1::2]), max(poly[1::2])50rec_poly = [xmin, ymin, xmax, ymax]51outline = imgname + ' ' + score + ' ' + ' '.join(map(str, rec_poly))52if index != (len(splitlines) - 1):53outline = outline + '\n'54f_out.write(outline)5556if __name__ == '__main__':57args = parse_args()58OBB2HBB(args.srcpath, args.dstpath)596061