利用检测结果实现半自动标注

编程入门 行业动态 更新时间:2024-10-22 07:25:00

利用检测结果实现半自动标注

利用检测结果实现半自动标注

1. 将目标检测结果保存为xml格式

#-----------------------------------------------------------------------------------#
#   下面定义了xml里面的组成模块,无需改动。
#-----------------------------------------------------------------------------------#
headstr = """\
<annotation><folder>VOC</folder><filename>%s</filename><source><database>My Database</database><annotation>COCO</annotation><image>flickr</image><flickrid>NULL</flickrid></source><owner><flickrid>NULL</flickrid><name>company</name></owner><size><width>%d</width><height>%d</height><depth>%d</depth></size><segmented>0</segmented>
"""
objstr = """\<object><name>%s</name><pose>Unspecified</pose><truncated>0</truncated><difficult>0</difficult><bndbox><xmin>%d</xmin><ymin>%d</ymin><xmax>%d</xmax><ymax>%d</ymax></bndbox></object>
"""tailstr = '''\
</annotation>
'''def write_xml(anno_path, jpg_pth, head, input_shape, boxes, unique_labels, tail):f = open(anno_path, "w")f.write(head%(jpg_pth, input_shape[0], input_shape[1], 3))for i, box in enumerate(boxes):f.write(objstr%(str(unique_labels[int(box[4])]), box[0], box[1], box[2], box[3]))f.write(tail)

2. 将目标检测结果保存为json格式

def write_json (img_path, pred):"""Plot parking slots on the image."""cur_json_dict = {"version": "5.1.1","flags": {},"shapes": [],}if(len(pred)==0):print("img  pred none box",img_path)image=cv.imread(img_path)# marking_points = list(list(zip(*pred_points))[1])height = image.shape[0]  # 320 width =  image.shape[1]  # 320for poly in range(len(pred_points)):cur_json_dict['shapes'].append({"label": isOccupied, "points": poly, "group_id": None,"shape_type": "polygon", "flags": {}})new_json_path = (img_path.split('.')[0]+'.json').replace("image","annotated_label")start =os.path.dirname(new_json_path)create_folder(start)relative_path = "..//img//" + os.path.basename(img_path)cur_json_dict["imagePath"] = relative_path# cur_json_dict["imageData"] = str(base64.b64encode(open(img_path, "rb").read()))# # delete 'b and '# cur_json_dict["imageData"] = cur_json_dict["imageData"][2:-1]cur_json_dict["imageData"] = Nonecur_json_dict["imageHeight"] = image.shape[0]cur_json_dict["imageWidth"] = image.shape[1]

更多推荐

利用检测结果实现半自动标注

本文发布于:2023-11-15 04:25:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1593613.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!