生成数据集列表txt<代码>
以KITTI的双目视觉数据为例,python代码:
import os, glob # info = os.getcwd() # Get current path info = '/media/wwt/9e35de07-e248-49c2-afcf-b9ce00605fbe/HXH/backup/dataset' # KITTI2012 info2012 = info + '/KITTI stereo2012/training/' imgLlist = info2012 + 'colored_0/' imgRlist = info2012 + 'colored_1/' displist = info2012 + 'disp_noc/' imgLlist = sorted(glob.glob(imgLlist+'*_10.png')) imgRlist = sorted(glob.glob(imgRlist+'*_10.png')) displist = sorted(glob.glob(displist+'*_10.png')) ft = open('1.txt','w') for i in range(len(imgLlist)): imgL = imgLlist[i] imgR = imgRlist[i] disp = displist[i] if imgL[imgL.rfind('/')+1:] == imgR[imgR.rfind('/')+1:] == disp[disp.rfind('/')+1:] : ft.writelines(imgL+' '+imgR+' '+disp+'\n') ft.close()
glob.glob() 返回符合指定规则的绝对路径
sorted() 进行排序操作