目标检测小工具

敏捷开发 - 目标检测

  工作中经常会有一些重复的工作,写过的脚本找起来很费劲,有时候还需要重新写,比如生成训练模型所需要的voc格式的label、json转voc、解析voc画在原图上方便查看…

Agile Pioneer  

解析voc格式的label并check

<annotation>
	<folder>detect</folder>
	<filename>img0423.png</filename>
	<path>E:\egg_gait\data_2019_11_04\detect\img0423.png</path>
	<source>
		<database>Unknown</database>
	</source>
	<size>
		<width>1280</width>
		<height>720</height>
		<depth>3</depth>
	</size>
	<segmented>0</segmented>
	<object>
		<name>egg</name>
		<pose>Unspecified</pose>
		<truncated>0</truncated>
		<difficult>0</difficult>
		<bndbox>
			<xmin>7</xmin>
			<ymin>43</ymin>
			<xmax>764</xmax>
			<ymax>712</ymax>
		</bndbox>
	</object>
</annotation>

demo程序

import os
import cv2
import numpy as np
from lxml import etree
import os.path as osp

def parse_voc_xml(xml_path):
    """
    return [[class, xmin, ymin, xmax, ymax], ..., [.....]]
    """
    tree = etree.parse(xml_path)  
    root = tree.getroot()

    height, width = 0, 0
    boxes = list()

    for article in root:
        box = list()
        # print("element name:", article.tag)
        # print("element content:", article.text)

        if article.tag == "filename":
            print(article.text)
        
        # size    
        if article.tag == "size":
            for field in article:
                if field.tag == "width":
                    width = int(field.text)
                if field.tag == "height":
                    height = int(field.text)        
        
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值