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

视觉目标检测标注xml格式文件解析可视化 - python 实现

视觉目标检测任务,通常用 labelimage标注,对应的标注文件为xml。

该示例来源于开源项目:https://gitcode.com/DataBall/DataBall-detections-100s/overview

读取 xml 标注文件,并进行可视化示例如下:

#-*-coding:utf-8-*-
# date:2024-09
# Author: DataBall - Xian
# function: show yolo data of voc format annoimport cv2
import os
import numpy as np
import xml.etree.cElementTree as et
import supervision as svif __name__ == "__main__":path_data='D:/dataset/img_list/bike/'idx = 0box_annotator = sv.BoxAnnotator()for file in os.listdir(path_data):if ".jpg" in file or ".png" in file:print(" ->[{}] {}".format(idx,file))path_img = path_data + filepath_label = path_img.replace(".jpg",".xml").replace(".png",".xml")if not os.access(path_label,os.F_OK): # 判断标注文件是否存在continueimg = cv2.imread(path_img) # 读取图片tree=et.parse(path_label)root=tree.getroot()for Object in root.findall('object'):name=Object.find('name').text # 获取类别名字# 获取坐标 xyxybndbox=Object.find('bndbox')x1= np.float32((bndbox.find('xmin').text))y1= np.float32((bndbox.find('ymin').text))x2= np.float32((bndbox.find('xmax').text))y2= np.float32((bndbox.find('ymax').text))# opencv 方式可视化# cv2.rectangle(img, (int(x1),int(y1)), (int(x2),int(y2)), (255,100,100), 2)# cv2.putText(img, "{}".format(name), (int(x1),int(y1)),\# cv2.FONT_HERSHEY_PLAIN, 2.5, (0, 55, 255), 6)# cv2.putText(img, "{}".format(name), (int(x1),int(y1)),\# cv2.FONT_HERSHEY_PLAIN, 2.5, (0, 255, 0), 2)# sv.BoxAnnotator() 方式可视化box_ = np.array([int(x1),int(y1), int(x2),int(y2)]).reshape(-1,4)det_ = sv.Detections(xyxy=box_)img = box_annotator.annotate(scene=img, detections=det_, labels=[name])cv2.namedWindow('image',0)cv2.imshow('image',img)if cv2.waitKey(30) == 27:breakcv2.destroyAllWindows()

助力快速掌握数据集的信息和使用方式。

http://www.lryc.cn/news/475685.html

相关文章:

  • clion远程配置docker ros2
  • 微信小程序 uniapp 腾讯地图的调用
  • OLAP平台架构演化历程
  • OmniGen: Unified Image Generation(代码的复现)
  • keepalive+mysql8双主
  • C#-基础构造函数、析构函数
  • Ubuntu删除docker
  • 系统地介绍Qt的QtConcurrent模块
  • 【进阶sql】复杂sql收集及解析【mysql】
  • 达梦检查工具dmdbchk的性能
  • Docker是什么
  • Vue进阶指南:Watch 和 Computed 的深度理解
  • 51c大模型~合集12
  • 大模型 RAG 面试真题大全
  • 【django】Django REST Framework 构建 API:APIView 与 ViewSet
  • TOEIC 词汇专题:旅游计划篇
  • 第三次RHCSA作业
  • WebGL(Web Graphics Library)
  • Unity核心笔记
  • 数据挖掘(六)
  • Netty 组件介绍 - Channel
  • 时间序列预测(十)——长短期记忆网络(LSTM)
  • Flink CDC 同步 Mysql 数据
  • 【python实战】-- 根据文件名分类
  • 蓝桥双周赛 第21场 小白入门赛
  • Linux 进程间通信 共享内存_消息队列_信号量
  • Mybatis自定义日志打印
  • 【在Linux世界中追寻伟大的One Piece】Socket编程TCP(续)
  • 面试高频问题:C/C++编译时内存五个分区
  • 阅读博士论文《功率IGBT模块健康状态监测方法研究》