我们使用paddleseg获取目标的轮廓信息,辅助标注bbox,可以提升标注效率和精度。
coco数据格式如下:
annotation.json的格式如下
{ “info”: […] “licenses”: […] “images”: […] “annotations”: [ ] }
解析polygen,提取有用的bbx信息
import os
import shutil
import json
import tqdm
def get_all_files(fold,suffix='.jpg'):
all_files = []
for root, dirs, files in os.walk(fold):
for file in files:
if suffix in file:
all_files.append(os.path.join(root, file))
return all_files
def gen_txt(file,bbx):
with open(file, 'w') as f:
f.write('{} {} {} {}'.format(bbx[0],bbx[1],bbx[2],bbx[3],))
def gen_bbx(file):
with open(file, 'r') as fcc_file:
fcc_data = json.load(fcc_file)
images_name=fcc_data['images']
annotations=fcc_data['annotations']
for image_info in tqdm.tqdm(images_name):
file_name=image_info['file_name']
img_id=image_info['id']
for ann in annotations:
if ann['image_id']==img_id:
gen_txt(os.path.join(out,file_name.replace('.JPG','.txt')),ann['bbox'])
file=r'F:\DATA_SET\B2C拍照\1001-\part1\label\annotations.json'
out=r'F:\DATA_SET\B2C拍照\1001-\part1\label\txt'
if not os.path.exists(out):
os.mkdir(out)
gen_bbx(file)