|
''' |
|
@File : mv_featurelines.py |
|
@Author : Jiapeng Zhou |
|
@Desc : move part of featurelines to another annotation labelme json files (bottom_curve are good, but left_cuff arenot) |
|
''' |
|
|
|
import os, os.path as osp, sys, pdb, json, shutil, argparse |
|
|
|
def parse_args(): |
|
parser = argparse.ArgumentParser() |
|
parser.add_argument('--src-dir', type=str) |
|
parser.add_argument('--dst-dir', type=str) |
|
args = parser.parse_args() |
|
return args |
|
|
|
def main(): |
|
args = parse_args() |
|
src_dir = args.src_dir |
|
dst_dir = args.dst_dir |
|
src_files = sorted([osp.join(src_dir, f) for f in os.listdir(src_dir) if f.endswith('.json')]) |
|
dst_files = sorted([osp.join(dst_dir, f) for f in os.listdir(dst_dir) if f.endswith('.json')]) |
|
assert len(src_files) == len(dst_files), 'src_files and dst_files should have same length' |
|
for idx, (src_file, dst_file) in enumerate(zip(src_files, dst_files)): |
|
with open(src_file) as fp: |
|
src_json = json.load(fp) |
|
with open(dst_file) as fp: |
|
dst_json = json.load(fp) |
|
src_shapes = src_json['shapes'] |
|
dst_shapes = dst_json['shapes'] |
|
|
|
for src_shape in src_shapes: |
|
if src_shape['label'] == 'bottom_curve': |
|
dst_shapes.append(src_shape) |
|
dst_json['shapes'] = dst_shapes |
|
|
|
with open(dst_file, 'w') as fp: |
|
json.dump(dst_json, fp) |
|
print('finish {}/{}'.format(idx+1, len(src_files))) |
|
|
|
|
|
if __name__ == '__main__': |
|
main() |