当前位置: 首页 > news >正文

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

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]
http://www.lryc.cn/news/227599.html

相关文章:

  • Android修行手册 - 万字梳理JNI开发正确技巧和错误缺陷
  • C++学习 --类和对象之继承
  • Redis之缓存
  • Redis6的IO多线程分析
  • kali linux安装教程
  • React进阶之路(四)-- React-router-v6、Mobx
  • 55基于matlab的1.高斯噪声2.瑞利噪声3.伽马噪声4.均匀分布噪声5.脉冲(椒盐)噪声
  • Codeforces Round 908 (Div. 2)视频详解
  • 电路综合-基于简化实频的SRFT集总参数切比雪夫低通滤波器设计
  • Linux系统编程——实现cp指令(应用)
  • 20231112_DNS详解
  • 使用ssh上传数据到阿里云ESC云服务上
  • 【408】计算机学科专业基础 - 数据结构
  • SpringSpringBoot自动装配
  • k8s 部署mqtt —— 筑梦之路
  • 模型部署:量化中的Post-Training-Quantization(PTQ)和Quantization-Aware-Training(QAT)
  • C++模板元模板(异类词典与policy模板)- - - 题目答案
  • 二十三种设计模式全面解析-组合模式与迭代器模式的结合应用:构建灵活可扩展的对象结构
  • postgresql|数据库|提升查询性能的物化视图解析
  • Unity中Shader雾效的原理
  • chatgpt辅助论文优化表达
  • Vue3 源码解读系列(二)——初始化应用实例
  • 网络原理-UDP/TCP详解
  • C#多线程入门概念及技巧
  • c primer plus_chapter_four——字符串和格式化输入/输出
  • Python Fastapi+Vue+JWT实现注册、登录、状态续签【登录保持】
  • oracle-sql语句解析类型
  • 2023 年最新企业微信官方会话机器人开发详细教程(更新中)
  • 3、FFmpeg基础
  • c语言:用指针解决有关字符串等问题