XML.write_xml(tree,xmlPath)     
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)           
if __name__=="__main__":
    # imgDir=r"F:\gasStation\tank\regular_dataset\SanJiang_tankbox\checked\no_pipe"
    xmlDir=r'/disk2/hao.yang/project/Qin/data/xmls/guide/complete/guide_FMXX_8000_complete/'
    referRoot='/disk2/hao.yang/project/Qin/data/xmls/guide/complete/oilstation/'
    referDirs=FILES.get_sub_dirs(referRoot)
    for dirName in referDirs:
        referDir=os.path.join(referRoot,dirName)
    # referPath=r'F:\gasStation\tank\regular_dataset\SanJiang_tankbox\tank\SanJiang_refer_9.xml'
    # addCates=['car','motorcycle','truck','bus']
    # addCates=['blue','yellow','other','security','red']
    # addCates=['tank_close','tank_open']
    # addCates=['cashbox_close','cashbox_open']
        addCates=['gun_in','gun_out']
        allXmls=[x for x in FILES.get_sorted_files(xmlDir) if ".xml" in x]
        for xml in allXmls:
            xmlPath=os.path.join(xmlDir,xml)
            referPath=os.path.join(referDir,xml)
            if os.path.exists(referPath):
                add_cates(xmlPath,referPath,addCates)
Exemple #2
0
    REMRATE = filesCount / remainNum
    remRate = REMRATE
    count = int(REMRATE) + 1
    fileNum = 0
    for file in allFiles:
        if count - remRate > 0:
            filePath = os.path.join(sampleDir, file)
            tarPath = os.path.join(tarDir, file)
            shutil.copy(filePath, tarPath)
            fileNum += 1
            remRate += REMRATE
        count += 1


memberRoot = '/disk2/hao.yang/project/Qin/data/xmls/guide'
members = FILES.get_sub_dirs(memberRoot)
for member in members:
    sampleRoot = os.path.join(memberRoot, member)
    tarRoot = os.path.join(memberRoot, member + '_sample')
    FILES.mkdir(tarRoot)
    dirNames = FILES.get_sub_dirs(sampleRoot)
    for dirName in dirNames:
        sampleDir = os.path.join(sampleRoot, dirName)
        tarDir = os.path.join(tarRoot, dirName)
        FILES.mkdir(tarDir)
        sample_files(sampleDir, tarDir, 2000)
# xmlDir=r"E:\factory\voc\add_data\summary\rawImg\Tank_jl"
# jpgDir=r"E:\research\lackLabel\voc\img4206"
# xmlTar=r"E:\factory\voc\add_data\summary\rawImg\Tank_jl_lite"
# jpgTar=r"E:\research\lackLabel\voc\img2103_1"
# remainNum=70
Exemple #3
0
#encoding=utf-8
import os
import shutil
import time
from basicFun import FILES
jpgRoot=r"/DATACENTER2/yh/dataRoom/gasStation/tank/train/sj18JunFrames"
if __name__=="__main__":
    remainNum=500
    start = time.time()
    jpgDirs=FILES.get_sub_dirs(jpgRoot)
    for dirName in jpgDirs:
        jpgDir=jpgRoot+'/'+dirName
        allJpgs=FILES.get_sorted_files(jpgDir)
        jpgCount=len(allJpgs)
        if jpgCount>3000:
            for jpg in allJpgs[remainNum:]:
                jpgPath=os.path.join(jpgDir,jpg)
                os.remove(jpgPath)

# def removeRemain(rmdir,remainNum):
#   allFiles=FILES.get_sorted_files(rmdir)
#   filesCount=len(rmdir)
#   for 
#   remRate=REMRATE
#   # print(rmRate)
#   count=int(REMRATE)+1
#   fileNum=0
#   for file in allFiles:
#       if count-remRate>0:
#           filePath=dirDir+'/'+file
#           tarPath=tarDir+'/'+file
Exemple #4
0
import os
import shutil
import time
from basicFun import FILES
if __name__=="__main__":
    timeStart=time.clock()
    roots="/DATACENTER4/hao.yang/project/Qin/data/preProcess/extractFrame/"
    rootsName=['0706_checkout']
    for rootName in rootsName:
        rootdir=os.path.join(roots,rootName)
        tardir=os.path.join(roots,rootName+"All") #不用创建
        print(rootdir,tardir)
        i=1
        if os.path.exists(rootdir):
            FILES.mkdir(tardir)
            alldirs=FILES.get_sub_dirs(rootdir)
            for dirName in alldirs:
                if 'test' in dirName:
                    continue
                dirpath=os.path.join(rootdir,dirName)
                # print(dirpath)
                alljpg=sorted([x for x in FILES.get_files(dirpath) if ".jpg" in x])#审核为.jpg形成列表
                for jpg in alljpg:
                    # rename
                    # newJpg=dirpath.split("/")[-1]+str("%06d"%i)+".jpg"
                    newJpg='{}_{}'.format(dirName,jpg)
                    # newJpg=jpg
                    i+=1
                    oldpath=os.path.join(dirpath,jpg)
                    newpath=os.path.join(tardir,newJpg)
                    shutil.copy(oldpath,newpath)
# trade_zhangbabeilu_total
# featureArea=(639,421,681,490)
# safe_XiWan
# featureArea=(843,253,1049,481)
# 适用于卸油口全局去重的阈值
SIMIBOUND = 0.99
# 适用于保险柜小区域去重的阈值
# SIMIBOUND=0.8
jpgRoot = r"/disk2/hao.yang/project/Qin/data/preProcess/extractFrame/0522_XiWan_b/"
# if jpgRoot[-1]=='/':
#     dstRoot=jpgRoot[:-1]+"Unique"+str(int(SIMIBOUND*1000))
# else:
#     dstRoot=jpgRoot+"Unique"+str(int(SIMIBOUND*1000))
# dstRoot=jpgRoot.replace('0505','0505removedSimilarityFrame')
dstRoot = jpgRoot.replace('extractFrame', 'removedSimilarityFrame')
rootsName = FILES.get_sub_dirs(jpgRoot)
# rootsName=[1]
startdir = 1  #从第startdir开始,处理完第enddir结束(包含enddir)
enddir = 43  #注意作为开始的startdir第一帧无事件
# 需定义的参数:
if __name__ == "__main__":
    # IMG.info()
    start = time.time()
    count = 1
    resume = 1
    dirCount = 1
    FILES.mkdir(dstRoot)
    for rootName in rootsName:
        dirpath = os.path.join(jpgRoot, rootName)
        # dirpath="/DATACENTER5/hao.yang/dataRoom/Qin/park/caotan/longVideoFrames/8/"
        if os.path.exists(dirpath):