def OBB2HBB(srcpath, dstpath): filenames = util.GetFileFromThisRootDir(srcpath) if not os.path.exists(dstpath): os.makedirs(dstpath) for file in filenames: with open(file, 'r') as f_in: with open( os.path.join( dstpath, os.path.basename(os.path.splitext(file)[0]) + '.txt'), 'w') as f_out: lines = f_in.readlines() splitlines = [x.strip().split() for x in lines] for index, splitline in enumerate(splitlines): imgname = splitline[0] score = splitline[1] poly = splitline[2:] poly = list(map(float, poly)) xmin, xmax, ymin, ymax = min(poly[0::2]), max( poly[0::2]), min(poly[1::2]), max(poly[1::2]) rec_poly = [xmin, ymin, xmax, ymax] outline = imgname + ' ' + score + ' ' + ' '.join( map(str, rec_poly)) if index != (len(splitlines) - 1): outline = outline + '\n' f_out.write(outline)
def filemove(srcpath, dstpath, num_process=32): pool = Pool(num_process) filelist = util.GetFileFromThisRootDir(srcpath) name_pairs = [] for file in filelist: basename = os.path.basename(file.strip()) dstname = os.path.join(dstpath, basename) name_tuple = (file, dstname) name_pairs.append(name_tuple) pool.map(filemove, name_pairs)
def getnamelist(srcpath, dstfile): filelist = util.GetFileFromThisRootDir(srcpath) with open(dstfile, 'w') as f_out: for file in filelist: basename = util.mybasename(file) f_out.write(basename + '\n')