Exemplo n.º 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) 
Exemplo n.º 2
0
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)           
Exemplo n.º 3
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)
Exemplo n.º 4
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)