Beispiel #1
0
def filesConfigs(srcRootPath, xmlSubFileName):

    #1.先将两个输入路径规整(分隔符)
    templist = srcRootPath.split("/")
    srcRootPath = templist[0]
    for index, folder in enumerate(templist):
        if index == 0:
            continue
        srcRootPath = srcRootPath + "\\" + folder

    templist = xmlSubFileName.split("/")
    xmlSubFileName = templist[0]
    for index, folder in enumerate(templist):
        if index == 0:
            continue
        xmlSubFileName = os.path.join(xmlSubFileName, folder)

    #2.计算labelImg输入参数
    [imagePath, imagefullname, xmlPath] = ParseArgvs(srcRootPath,
                                                     xmlSubFileName)

    predefClassFilePath = os.path.join(workPath, "predefClass.txt")

    #生成img_xml_namedict.txt文件
    img_xml_txtpath = os.path.join(os.path.dirname(imagePath),
                                   "img_xml_namedict.txt")
    if os.path.exists(img_xml_txtpath) != True:
        Generate_img_xml_namedict(os.path.dirname(img_xml_txtpath))

    img_xml_namedict = {}
    if os.path.exists(imagefullname) == True:
        img_xml_txtpath = os.path.join(os.path.dirname(imagePath),
                                       "img_xml_namedict.txt")
        if os.path.exists(img_xml_txtpath) == True:
            img_xml_txt = open(img_xml_txtpath, "r")
            for line in img_xml_txt:
                line = line.strip("\n")
                names = line.split(" ")
                imgName = names[0]
                xmlName = names[1]
                img_xml_namedict[imgName] = xmlName
    else:
        print("There is no file!")

    labelImg_argv = [
        imagefullname, predefClassFilePath, xmlPath, img_xml_namedict
    ]
    argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]
    #print(labelImg_argv)
    #print(argv_org)

    #通过参数调用labelImg
    try:
        if len(labelImg_argv) == 4 and len(argv_org) == 3:
            sys.exit(labelImg.main(labelImg_argv, argv_org))
        else:
            sys.exit(labelImg.main())

    finally:
        print("success!")
Beispiel #2
0
def filesConfigs():
    argv = []
    argv_org = []
    changed_JPG_name = []
    argv2 = []
    argv2_org = []
    changed_JPG_name2 = []
    savePath = []
    savePath2 = []
    if len(sys.argv) == 4:
        (changed_JPG_name, predefClassFilePath,
         savePath) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [sys.argv[0], changed_JPG_name, predefClassFilePath, savePath]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

    if len(sys.argv) == 7:
        (changed_JPG_name, predefClassFilePath,
         savePath) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [sys.argv[0], changed_JPG_name, predefClassFilePath, savePath]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

        (changed_JPG_name2, predefClassFilePath2,
         savePath2) = ParseArgvs(srcRootPath2, xmlSubFileName2)
        argv2 = [
            sys.argv[0], changed_JPG_name2, predefClassFilePath2, savePath2
        ]
        argv2_org = [sys.argv[4], sys.argv[5], sys.argv[6]]

    #argv_org = ["D:/myWork/clear/","20181115412/20181115/1019/1/xml/1019_1_0_1_2018_20181127163317.XML","5Zac5rSL5rSL"]

    #argv2_org = ["D:/myWork/clear/","20181115412/20181115/1019/1/xml/1019_1_0_2_2019_20181127205735.XML","5Zac5rSL5rSL"]

    try:
        if len(argv_org) == 3:
            if len(argv2_org) == 3:
                sys.exit(labelImg.main(argv, argv_org, argv2, argv2_org))
            else:
                sys.exit(labelImg.main(argv, argv_org))
        else:
            sys.exit(labelImg.main())

    #except:
    #    print('die')
    finally:
        #os.rename(changed_JPG_name,origin_JPG_name)
        if os.path.exists(changed_JPG_name) == True:
            thumbGeneration.GenerationThumbAndErrThumb2(
                changed_JPG_name,
                srcRootPath.replace("clear", "repair") + xmlSubFileName,
                savePath)
            os.remove(changed_JPG_name)
            if os.path.exists(savePath + "/th") == True:
                shutil.rmtree(savePath + "/th")
        if os.path.exists(changed_JPG_name2) == True:
            os.remove(changed_JPG_name2)
        if os.path.exists(
                srcRootPath.replace("clear", "repair") +
                xmlSubFileName2) == True:
            os.remove(srcRootPath.replace("clear", "repair") + xmlSubFileName2)
Beispiel #3
0
def filesConfigs():
    (xmlSubPath, xmlfilename) = os.path.split(xmlSubFileName)
    sub_xmlf = xmlfilename.split("_")
    image_pre = ""
    for sub_index, sub in enumerate(sub_xmlf):
        if (sub_index == 0):
            image_pre = sub
        elif (sub_index == len(sub_xmlf) - 1):
            continue
        else:
            image_pre = image_pre + "_" + sub
    imagefilename = image_pre + ".JPG"

    imagePath = srcRootPath + xmlSubPath.replace("xml", "org", 1)
    imagefullname = imagePath + "/" + imagefilename
    predefClassFilePath = workPath + "/predefClass.txt"
    savePath = srcRootPath.replace("clear", "repair") + xmlSubPath

    print(imagefullname)
    print(predefClassFilePath)
    print(savePath)

    #创建保存路径
    if os.path.exists(savePath) != True:
        os.makedirs(savePath)
    shutil.copy(srcRootPath + xmlSubFileName, savePath)

    origin_xml_name = savePath + "/" + xmlfilename
    changed_xml_name = savePath + "/" + image_pre + ".XML"
    if os.path.exists(changed_xml_name) == True:
        os.remove(changed_xml_name)
    os.rename(origin_xml_name, changed_xml_name)

    argv = [sys.argv[0], imagefullname, predefClassFilePath, savePath]
    argv2 = []
    if len(sys.argv) == 4:
        argv2 = [sys.argv[1], sys.argv[2], sys.argv[3]]
    #argv2 = ["E:/myWork/clear","20181115412/20181115/1019/1/xml/1019_1_0_2_20181127163317_15890459863.xml","5p2O54Wc"]
    try:
        if len(argv2) == 3:
            sys.exit(labelImg.main(argv, argv2))
        else:
            sys.exit(labelImg.main(argv))
    #except:
    #    print('die')
    finally:
        os.rename(changed_xml_name, origin_xml_name)
Beispiel #4
0
def filesConfigs():
    argv = []
    argv_org = []
    changed_JPG_name = ""
    argv2 = []
    argv2_org = []
    changed_JPG_name2 = ""
    savePath = ""
    savePath2 = ""
    savePathfinally = ""
    savePathfinally2 = ""
    if len(sys.argv) == 4:
        (changed_JPG_name, predefClassFilePath, savePath,
         savePathfinally) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [sys.argv[0], changed_JPG_name, predefClassFilePath, savePath]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

    if len(sys.argv) == 5:
        (changed_JPG_name, predefClassFilePath, savePath,
         savePathfinally) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [sys.argv[0], changed_JPG_name, predefClassFilePath, savePath]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

        argv2 = [sys.argv[0], compareImgPath, predefClassFilePath, savePath]

    if len(sys.argv) == 7:
        (changed_JPG_name, predefClassFilePath, savePath,
         savePathfinally) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [sys.argv[0], changed_JPG_name, predefClassFilePath, savePath]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

        (changed_JPG_name2, predefClassFilePath2, savePath2,
         savePathfinally2) = ParseArgvs(srcRootPath2, xmlSubFileName2)
        argv2 = [
            sys.argv[0], changed_JPG_name2, predefClassFilePath2, savePath2
        ]
        argv2_org = [sys.argv[4], sys.argv[5], sys.argv[6]]

    #argv_org = ["D:/myWork/clear/","20181115412/20181115/1019/1/xml/1019_1_0_1_2018_20181127163317.XML","5Zac5rSL5rSL"]

    #argv2_org = ["D:/myWork/clear/","20181115412/20181115/1019/1/xml/1019_1_0_2_2019_20181127205735.XML","5Zac5rSL5rSL"]

    try:
        if len(argv_org) == 3:
            if len(argv2_org) == 3:
                sys.exit(labelImg.main(argv, argv_org, argv2, argv2_org))
            elif len(argv2) == 4:
                sys.exit(labelImg.main(argv, argv_org, argv2, argv2_org))
            else:
                sys.exit(labelImg.main(argv, argv_org))
        else:
            sys.exit(labelImg.main())

    #except:
    #    print('die')

    finally:
        #CJY at 2019.3.5
        if os.path.exists(os.path.join(workPath, "saveFlag.txt")) == True:
            sF = open(os.path.join(workPath, "saveFlag.txt"), "r")
            deleteNum = sF.readline()
            #print(deleteNum)
            sF.close()
            os.remove(os.path.join(workPath, "saveFlag.txt"))
            #创建最终保存路径
            if os.path.exists(savePathfinally) != True:
                os.makedirs(savePathfinally)
            #生成缩略图
            outputErrThumb = th.GenerationThumbAndErrThumb(
                changed_JPG_name,
                srcRootPath.replace("clear", "repairTemp") + xmlSubFileName,
                savePath)
            ETpre, ext = os.path.splitext(outputErrThumb)
            ETpre = ETpre + "_D" + deleteNum  #加入删除个数的记录
            outputErrThumb2 = ETpre + ext
            os.rename(outputErrThumb, outputErrThumb2)
            outputErrThumb = outputErrThumb2

            #搬移(缩略图+xml)
            if os.path.exists(outputErrThumb) == True:
                shutil.copy(outputErrThumb, savePathfinally)
            if os.path.exists(
                    srcRootPath.replace("clear", "repairTemp") +
                    xmlSubFileName) == True:
                shutil.copy(
                    srcRootPath.replace("clear", "repairTemp") +
                    xmlSubFileName, savePathfinally)

        #删除Temp文件夹
        TempPath = srcRootPath.replace("clear", "repairTemp")
        #print("Temp:",TempPath)
        if os.path.exists(TempPath) == True:
            #shutil.rmtree(srcRootPath.replace("clear","repairTemp"))
            for root, dirs, files in os.walk(TempPath, topdown=False):
                #print("root: ", root, "  dirs: ", dirs, "  files: ",files)
                '''
                root:  foo/bar/baz/empty/test   dirs:  []   files:  []
                root:  foo/bar/baz/empty   dirs:  ['test']   files:  []
                root:  foo/bar/baz   dirs:  ['empty']   files:  ['test_bak.txt', 'test.txt']
                '''
                #continue
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
            os.rmdir(TempPath)
        """
Beispiel #5
0
            #outputErrThumb = thumbGeneration.GenerationThumbAndErrThumb2(changed_JPG_name,srcRootPath.replace("clear","repairTemp")+xmlSubFileName,savePath)
            outputErrThumb = GenerationThumbAndErrThumb2(changed_JPG_name,srcRootPath.replace("clear","repairTemp")+xmlSubFileName,savePath)
            
            if os.path.exists(savePathfinally)!=True:
                  os.makedirs(savePathfinally)
            if os.path.exists(outputErrThumb) ==True:
                shutil.copy(outputErrThumb,savePathfinally)
                os.remove(outputErrThumb)
            if os.path.exists(srcRootPath.replace("clear","repairTemp")+xmlSubFileName) ==True:
                shutil.copy(srcRootPath.replace("clear","repairTemp")+xmlSubFileName,savePathfinally)
                os.remove(srcRootPath.replace("clear","repairTemp")+xmlSubFileName)
            os.remove(changed_JPG_name)
            if os.path.exists(savePath+"/th") ==True:
                shutil.rmtree(savePath+"/th")
                
        if os.path.exists(changed_JPG_name2) ==True and changed_JPG_name2!="":
            os.remove(changed_JPG_name2)
        if os.path.exists(srcRootPath.replace("clear","repairTemp")+xmlSubFileName2) ==True and xmlSubFileName2!="":
            os.remove(srcRootPath.replace("clear","repairTemp")+xmlSubFileName2)         
        
        if os.path.exists(srcRootPath.replace("clear","repairTemp")) ==True:
            shutil.rmtree(srcRootPath.replace("clear","repairTemp"))
        """


if __name__ == '__main__':
    if len(sys.argv) == 4 or len(sys.argv) == 5 or len(sys.argv) == 7:
        filesConfigs()
    else:
        sys.exit(labelImg.main([sys.argv[0]]))
Beispiel #6
0
def filesConfigs(srcRootPath, xmlSubFileName, srcRootPath2, xmlSubFileName2):
    #1.先将两个输入路径规整(分隔符)
    templist = srcRootPath.split("/")
    srcRootPath = templist[0]
    for index, folder in enumerate(templist):
        if index == 0:
            continue
        srcRootPath = srcRootPath + "\\" + folder

    templist = xmlSubFileName.split("/")
    xmlSubFileName = templist[0]
    for index, folder in enumerate(templist):
        if index == 0:
            continue
        xmlSubFileName = os.path.join(xmlSubFileName, folder)

    argv = []
    argv_org = []
    argv2 = []
    argv2_org = []

    if len(sys.argv) == 4:
        (imagefullname, predefClassFilePath, savePath,
         i_x_namedict) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [imagefullname, predefClassFilePath, savePath, i_x_namedict]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

    if len(sys.argv) == 5:
        (imagefullname, predefClassFilePath, savePath,
         i_x_namedict) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [imagefullname, predefClassFilePath, savePath, i_x_namedict]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

        argv2 = [compareImgPath, predefClassFilePath, savePath, {}]

    if len(sys.argv) == 7:
        (imagefullname, predefClassFilePath, savePath,
         i_x_namedict) = ParseArgvs(srcRootPath, xmlSubFileName)
        argv = [imagefullname, predefClassFilePath, savePath, i_x_namedict]
        argv_org = [sys.argv[1], sys.argv[2], sys.argv[3]]

        (imagefullname2, predefClassFilePath2, savePath2,
         i_x_namedict2) = ParseArgvs2(srcRootPath2, xmlSubFileName2)
        argv2 = [
            imagefullname2, predefClassFilePath2, savePath2, i_x_namedict2
        ]
        argv2_org = [sys.argv[4], sys.argv[5], sys.argv[6]]

    #argv_org = ["D:/myWork/clear/","20181115412/20181115/1019/1/xml/1019_1_0_1_2018_20181127163317.XML","5Zac5rSL5rSL"]

    #argv2_org = ["D:/myWork/clear/","20181115412/20181115/1019/1/xml/1019_1_0_2_2019_20181127205735.XML","5Zac5rSL5rSL"]

    try:
        if len(argv_org) == 3:
            if len(argv2_org) == 3:
                sys.exit(labelImg.main(argv, argv_org, argv2, argv2_org))
            elif len(argv2) == 4:
                sys.exit(labelImg.main(argv, argv_org, argv2, argv2_org))
            else:
                sys.exit(labelImg.main(argv, argv_org))
        else:
            sys.exit(labelImg.main())

    #except:
    #    print('die')

    finally:
        comPath = srcRootPath.replace("clear", "compair")
        if os.path.exists(comPath) == True:
            #shutil.rmtree(srcRootPath.replace("clear","repairTemp"))
            for root, dirs, files in os.walk(comPath, topdown=False):
                #print("root: ", root, "  dirs: ", dirs, "  files: ",files)
                '''
                root:  foo/bar/baz/empty/test   dirs:  []   files:  []
                root:  foo/bar/baz/empty   dirs:  ['test']   files:  []
                root:  foo/bar/baz   dirs:  ['empty']   files:  ['test_bak.txt', 'test.txt']
                '''
                #continue
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
            os.rmdir(comPath)

        print("done")
Beispiel #7
0
    #except:
    #    print('die')

    finally:
        comPath = srcRootPath.replace("clear", "compair")
        if os.path.exists(comPath) == True:
            #shutil.rmtree(srcRootPath.replace("clear","repairTemp"))
            for root, dirs, files in os.walk(comPath, topdown=False):
                #print("root: ", root, "  dirs: ", dirs, "  files: ",files)
                '''
                root:  foo/bar/baz/empty/test   dirs:  []   files:  []
                root:  foo/bar/baz/empty   dirs:  ['test']   files:  []
                root:  foo/bar/baz   dirs:  ['empty']   files:  ['test_bak.txt', 'test.txt']
                '''
                #continue
                for name in files:
                    os.remove(os.path.join(root, name))
                for name in dirs:
                    os.rmdir(os.path.join(root, name))
            os.rmdir(comPath)

        print("done")


if __name__ == '__main__':
    if len(sys.argv) == 4 or len(sys.argv) == 5 or len(sys.argv) == 7:
        filesConfigs(srcRootPath, xmlSubFileName, srcRootPath2,
                     xmlSubFileName2)
    else:
        sys.exit(labelImg.main())
Beispiel #8
0
from labelImg import main
main()