| import os | |
| from copy import deepcopy | |
| isp_json = [] | |
| path = './Examples' | |
| for img_dir in sorted(os.listdir(path)): | |
| if os.path.isdir(os.path.join(path, img_dir)): | |
| ISPP = os.path.join(path, img_dir, 'ISPP') | |
| ispp = {} | |
| ispp['Example_id'] = img_dir | |
| ispp['ISPP'] = [] | |
| img_list = [] | |
| for idx, img in enumerate(sorted(os.listdir(ISPP))): | |
| ispp['ISPP'].append([os.path.join(ISPP, img), idx / 10 if '1' in img_dir else 1 - idx / 10]) | |
| for file in os.listdir(os.path.join(path, img_dir)): | |
| if os.path.isfile(os.path.join(path, img_dir, file)): | |
| img_list.append(file) | |
| ispp['Image'] = [os.path.join(path, img_dir, file), 7] | |
| ispp['Remark'] = [] | |
| isp_json.append(deepcopy(ispp)) | |
| with open('example2.json', 'w') as f: | |
| import json | |
| json.dump(isp_json, f, indent=4) |