前言
在标注的时候,很可能标签标成其他错误的标签,如果新手标注,更容易出现这种情况。
那么这个时候,可以根据标注的xml文件把物体分割出来,并另存到以标签为名字的目录下。
那么怎么方便的修改呢?
只需要查看每个目录,把不是该标签的图片,移动到对应的目录里,执行代码就可以了。
解决
代码一:分割出各个标签的物体
'''
该项目为labelimg 标注转 coco数据集格式的代码
'''
import glob
import os
import cv2
xmls_path = "C:\\Users\\Shanmh\\Desktop\\test_class\\xmls"
images_path ="C:\\Users\\Shanmh\\Desktop\\test_class\\images"
save_path="C:\\Users\\Shanmh\\Desktop\\test_class\\save_crop"
# 定义从xml获取信息的函数
def _read_anno(img_name):
xml_name=img_name.split(".j")[0]+".xml"
xml_path=os.path.join(xmls_path,xml_name)
img_path=os.path.join(images_path,img_name)
import xml.etree.ElementTree as ET
tree = ET.parse(xml_pat