文件夹中图像生成txt文本 img2txt

来源:互联网 发布:极客邦科技软件 编辑:程序博客网 时间:2024/06/06 02:59
import os#函数def ListFilesToTxt(dir,file,wildcard,recursion):    exts = wildcard.split(" ")    for root, subdirs, files in os.walk(dir):        for name in files:            txt=os.path.splitext(name)            for ext in exts:                if(name.endswith(ext)):                    file.write("/JPEGImages/"+txt[0]+".jpg"+" "+"/SegmentationClassAug/"+txt[0] +".png"+ "\n")                    break        if(not recursion):            breakdef Test():  dir="/~/deeplab1/exper/datavoc/VOC2012/SegmentationClassAug"  outfile="/~/lly/deeplab1/exper/voc12/list/train_aug.txt"  wildcard = ".png"  file = open(outfile,"w")  if not file:    print ("cannot open the file %s for writing" % outfile)  ListFilesToTxt(dir,file,wildcard, 0)  file.close()Test()
原创粉丝点击