vott导出标注文件python代码
import json import cv2 import os from bounding_box import bounding_box as bbox_plot Img_Dir = 'F:/vott/target/vott-json-export' Save_Dir = 'F:/vott/result' Draw_Tags = ['person'] def make_video(img_dir, img_size=(1920, 1080), fps=5): file_path = os.path.join(Save_Dir, "demo.mp4") filelist = os.listdir(img_dir) fourcc = cv2.VideoWriter_fourcc('D', 'I', 'V', 'X') video = cv2.VideoWriter(file_path, fourcc, fps, img_size) for item in filelist: if item.endswith('.jpg'): item = img_dir + '/' + item img = cv2.imread(item) video.write(img) video.release() def draw_one_img(img_name, img_timestamp, labels_list): img_path = os.path.join(Img_Dir, img_name) img = cv2.imread(img_path, cv2.IMREAD_COLOR) for label in labels_list: tag = label['tags'][0] if not tag in Draw_Tags: continue bbox = label['boundingBox'] left = bbox['left'] top = bbox['top'] right = left + bbox['width'] bottom = top + bbox['height'] bbox_plot.add(img, left, top, right, bottom, tag, 'red') save_name = 'time%s.jpg' % format(img_timestamp, '.2f').replace('.', '') save_path = os.path.join(Save_Dir, save_name) cv2.imwrite(save_path, img) print(save_name, 'ok~') def main(): lb_json = os.path.join(Img_Dir, 'video-export.json') with open(lb_json, 'r',encoding='utf-8') as f: labels_dict = json.load(f) assets = labels_dict['assets'] size = None for k, v in assets.items(): img_name = v['asset']['name'] img_timestamp = v['asset']['timestamp'] if size is None: w = v['asset']['size']['width'] h = v['asset']['size']['height'] size = (w, h) labels_list = v['regions'] draw_one_img(img_name, img_timestamp, labels_list) make_video(Save_Dir, img_size=size) if __name__ == '__main__': main()