python脚本寻找labelImg工具可能标注错误的xml文件

# coding: utf-8

###该部分代码可以实现找出xml文件里的矩形框个数,通过对比矩形框个数可以找到打重复的标签以及打错的标签

from PIL import Image
import os
import os.path
import numpy as np
import cv2
import glob
import pandas as pd
import xml.etree.ElementTree as ET
import time

start = time.time()

# 指明被遍历的文件夹
rootdir = r'D:\\picture\指针仪表拍图\\datasets\\'
for parent, dirnames, filenames in os.walk(rootdir):  # 遍历每一张图片
    for filename in filenames:
        # print('parent is :' + parent)
        # print('filename is :' + filename)
        currentPath = os.path.join(parent, filename)
        # print('the fulll name of the file is :' + currentPath)

        img = Image.open(currentPath)
        #  print (img.format, img.size, img.mode)
        # img.show()

        path = r'D:\\picture\\指针仪表拍图\\annotations\\'
        for xml_file in glob.glob(path + '/*.xml'):
            # 返回解析树
            tree = ET.parse(xml_file)
            # 获取根节点
            root = tree.getroot()
            # print(root)
            # 根据标签名查找root下的所有标签,并获取其值
            # print(imgname)
            # 对所有目标进行解析
            name_num = []
            for member in root.findall('object'):
                xmlname = root.find('filename').text
                savefilename = member.find('name').text
                name_num.append(savefilename)
                if xmlname == filename:
                    if len(name_num)==2:
                        print(currentPath)
                        print(name_num)



©️2020 CSDN 皮肤主题: 大白 设计师: CSDN官方博客 返回首页
实付0元
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值