自己的数据标签为txt文件,格式如下:
Scene/Video/video0067/image_2860.png 7 1 368 342 100 91 1 468 355 64 72 1 700 216 43 46 1 712 149 35 38 1 771 115 28 32 1 790 140 21 20 1 643 65 11 13
图片路径 该图中框数(根据框数,后面的数5个一组,依次为:标志位 左上角x点 左上角y点 框宽 框高)
txt to coco annotations json代码如下:
# -*- coding: UTF-8 -*-
import cv2
import json
import sys
# process bar
def process_bar(count, total, status=''):
bar_len = 60
filled_len = int(round(bar_len * count / float(total)))
percents = round(100.0 * count / float(total), 1)
bar = '=' * filled_len + '-' * (bar_len - filled_len)
sys.stdout.write('[%s] %s%s ...%s\r' % (bar, percents, '%', status))
sys.stdout.flush()
root_path = "data_with_box_example/"
images, categories, annotations = [], [], []
category_dict = {"people": 1}
for cat_n in category_dict:
categories.append({"supercategory": "", "id": category_dict[cat_n], "name": cat_n})
with open("l