Example #1
0
def add_box(path,boxes):
    # print(path)
    tree = ET.ElementTree(file=path)
    root = tree.getroot()
    for bndbox in boxes:
        root=XML.add_tag(root,bndbox)
    XML.write_xml(tree,path) 
Example #2
0
def regular_xml(path, filename):
    global count
    tree = ET.ElementTree(file=path)
    root = tree.getroot()
    # XML.chag_label(root,labelDict) # 修改label名称
    # root=XML.del_tag(root,names) # 删除指定label
    root = XML.save_tag(root, names)  # 只保留指定label
    # root=XML.thresh_size(path,root,sizeThresh,sizeThreshNames)
    XML.write_xml(tree, path)
Example #3
0
def regular_xml(path, filename):
    global count
    tree = ET.ElementTree(file=path)
    root = tree.getroot()
    XML.chk_label(root, sizeThreshDict)
    XML.chag_size(root, filename, width, height)
    XML.chag_filename(root, filename)
    XML.thresh_size(root, width, sizeThreshDict)
    XML.write_xml(tree, path)
def add_new_cates(xmlPath,referPath,addCates):
    addBoxes=XML.read_objects(referPath)
    tree = ET.ElementTree(file=xmlPath)
    root = tree.getroot()
    root=XML.del_tag(root,addCates)
    # print(addBoxes)
    for box in addBoxes:
        if box['name'] in addCates:
            root=XML.add_tag(root,box)
    XML.write_xml(tree,xmlPath)           
Example #5
0
def regular_xml(newxmlPath, img, newimg):
    print(newxmlPath, xml, newxml)

    tree = ET.ElementTree(file=newxmlPath)
    root = tree.getroot()

    for obj in root.findall('filename'):
        print(obj.text)
        obj.text = newimg

    for obj in root.findall('path'):
        print(obj.text)
        obj.text = obj.text.replace(img, newimg)

    XML.write_xml(tree, newxmlPath)
Example #6
0
        if top_labels:
            #outImg
            image, labels, xmins, ymins, xmaxs, ymaxs = drawImg(
                image, top_labels, top_xmin, top_ymin, top_xmax, top_ymax,
                top_scores)
            # desImg = os.path.join(outImg,file)
            # cv2.imwrite(desImg,image)
            # # outXml
            if len(labels) > 0:
                tarXml = os.path.join(tarXmlDir, file.split('.')[0] + '.xml')
                shutil.copy(referXml, tarXml)
                tree = ET.ElementTree(file=tarXml)
                root = tree.getroot()
                for i in range(len(labels)):
                    # if labels[i] not in ["close","open","cover"]:
                    if 1 > 0:
                        xmin = str(xmins[i])
                        ymin = str(ymins[i])
                        xmax = str(xmaxs[i])
                        ymax = str(ymaxs[i])
                        # print(labels[i],xmin,ymin,xmax,ymax)
                        obj = {
                            'name': labels[i],
                            'xmin': xmin,
                            'ymin': ymin,
                            'xmax': xmax,
                            'ymax': ymax
                        }
                        XML.add_tag(root, obj)
                        XML.write_xml(tree, tarXml)
Example #7
0
def changeXmlLabelName(path, labelDict):
    tree = ET.ElementTree(file=path)
    root = tree.getroot()
    root = XML.del_tag(root, ["13"])
    root = XML.chag_name(root, labelDict)
    XML.write_xml(tree, path)
Example #8
0
labelXmlDir = r'/disk2/hao.yang/project/Qin/data/imgs/isle/modelxml_isle_17117_havered/'
# checkedDir='/disk2/hao.yang/project/Qin/data/xmls/checkout/complete'
attentionNames = ['red']
confuseNames = ['yellow', 'other', 'blue']
count = 0
allChecked = []
# allChecked=[x for x in FILES.get_sorted_files(checkedDir) if ".xml" in x]
allXmls = [
    x for x in FILES.get_sorted_files(modelXmlDir)
    if ".xml" in x and x not in allChecked
]
for xml in allXmls:
    labelXmlPath = os.path.join(labelXmlDir, xml)
    modelXmlPath = os.path.join(modelXmlDir, xml)
    if os.path.exists(labelXmlPath):
        labelObjs = XML.read_objects(labelXmlPath)
        modelObjs = XML.read_objects(modelXmlPath)
        newObjs = []
        for labelObj in labelObjs:
            if labelObj['name'] in confuseNames:
                newObjs.append(fuse(labelObj, modelObjs))
            else:
                newObjs.append(labelObj)
        tree = ET.ElementTree(file=labelXmlPath)
        root = tree.getroot()
        XML.del_all_tag(root)
        for box in newObjs:
            root = XML.add_tag(root, box)
        XML.write_xml(tree, labelXmlPath)
# FILES.copy_files_refer_dir(imgDir,'.jpg',badDir,badDir)
Example #9
0
def regular_xml(path, changeLabelDict):
    global count
    tree = ET.ElementTree(file=path)
    root = tree.getroot()
    XML.chag_label(root, changeLabelDict, tag="object")
    XML.write_xml(tree, path)