GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — pascal2coco/pascal2coco.py at master · opencvfun/pascal2coco Expand file tree/ Copy pathpascal2coco.pyMore file actions 78 lines (70 loc) · 2.71 KB / Copy pathpascal2coco.pyFile metadata and controls78 lines (70 loc) · 2.71 KB 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 import json import xml.etree.ElementTree as ET import os def load_load_image_labels(LABEL_PATH, class_name=[]): # temp=[] images=[] type="instances" annotations=[] #assign your categories which contain the classname and calss id #the order must be same with the class_nmae categories = [ { "id" : 1, "name" : "xxx", "supercategory" : "none" }, { "id": 2, "name": "xxx", "supercategory": "none" }, ] # load ground-truth from xml annotations id_number=0 for image_id, label_file_name in enumerate(os.listdir(LABEL_PATH)): print(str(image_id)+' '+label_file_name) label_file=LABEL_PATH + label_file_name image_file = label_file_name.split('.')[0] + '.jpg' tree = ET.parse(label_file) root = tree.getroot() size=root.find('size') width = float(size.find('width').text) height = float(size.find('height').text) images.append({ "file_name": image_file, "height": height, "width": width, "id": image_id })# id of the image. referenced in the annotation "image_id" for anno_id, obj in enumerate(root.iter('object')): name = obj.find('name').text bbox=obj.find('bndbox') cls_id = class_name.index(name) xmin = float(bbox.find('xmin').text) ymin = float(bbox.find('ymin').text) xmax = float(bbox.find('xmax').text) ymax = float(bbox.find('ymax').text) xlen = xmax-xmin ylen = ymax-ymin annotations.append({ "segmentation" : [[xmin, ymin, xmin, ymax, xmax, ymax, xmax, ymin],], "area" : xlen*ylen, "iscrowd": 0, "image_id": image_id, "bbox" : [xmin, ymin, xlen, ylen], "category_id": cls_id, "id": id_number, "ignore":0 }) # print([image_file,image_id, cls_id, xmin, ymin, xlen, ylen]) id_number += 1 return {"images":images,"annotations":annotations,"categories":categories} if __name__=='__main__': LABEL_PATH='your pascal voc annotation path' classes=['background','add your class name'] label_dict = load_load_image_labels(LABEL_PATH,classes) jsonfile='/home/xxx/train.json'#the json file which you want to save the coco format annotations with open('/home/wjl/DataSet/707dataset/label/train.json','w') as json_file: json_file.write(json.dumps(label_dict, ensure_ascii=False)) json_file.close() |
| You are visitor 01402792 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |