【Tool】labelImg label modification

Preface

When labeling, it is very likely that the label will be labeled with other wrong labels. This situation is more likely to occur if a novice labels.

Then at this time, the object can be segmented according to the annotated xml file and saved to a directory named with the label .

So how to modify it easily?

You only need to check each directory, move the images that are not of that tag to the corresponding directory, and execute the code.

solve

Code 1: Segment objects with each label


'''
该项目为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

Guess you like

Origin blog.csdn.net/qq_55542491/article/details/131111777