脚本应用背景:
从OfficeTrace_1.txt文件中 获取每一行的前两个元素(pos_x,pos_z), 按照 这种格式组织文件
(pos_x,pos_z)tilexxcrfxx.264, 如(0,0)tile0crf31.264。
根据轨迹计算出的264文件,从3D场景all_tiles中天选出本轨迹的 3D场景图片。
import os
import shutil
import sys
files = []
# source = "./trace/OfficeTrace_1.txt"
# ori = './tiles'
# tar = './TargetTiles'
# 读入trace.txt ,拼接目录名
def read_trace_table_pos(filename):
granularity = 5.0
quality = [15, 19, 23, 27, 31, 35]
with open(filename) as f:
lines = f.readlines()
trace_cnt = 0
crf_cnt = 0
for line in lines:
strs = line.split(" ")
pos_x = (int)(float(strs[0])/granularity) * granularity #float
pos_x = str(int(pos_x)) #int -- > string
pos_z = (int)(float(strs[1])/granularity)*granularity
pos_z = str(int(pos_z))
for i in range(0, 4):
for j in quality:
file_crf = str('(' + pos_x + ',' + pos_z + ')' +
'tile' + str(i) + 'crf' + str(j) + '.264')
files.append(file_crf)
crf_cnt += 1
trace_cnt += 1
print(str(trace_cnt) + " trace has been read.")
print(str(crf_cnt) + " make crf tiles.")
# 从tiles中找出符合的crf文件
def pick_crf_files(ori,tar):
for i in files:
ori_path = os.path.join(ori, i) # 拼接原目标路径
if (os.path.exists(ori_path)):
tar_path = os.path.join(tar, i) # 拼接目标路径
if (os.path.exists(tar_path)):
# 已经存在,不再复制
print("already exist:" + tar_path)
continue
else:
# 原文件存在,目标不存在,复制
shutil.copyfile(ori_path, tar_path)
print("copy %s ---> %s"%(ori_path,tar_path))
else:
# print the file not exist
print("missing file:" + ori_path)
# missnum = missnum +1
# print(missnum)
continue
# read_trace_table_pos(source)
# pick_crf_files()
if __name__ == '__main__':
if len(sys.argv) == 4:
OfficeTrace_dir = sys.argv[1].strip()
all_tiles_dir = sys.argv[2].strip()
target_crf_dir = sys.argv[3].strip()
print('Calculate the pose according to \'%s\', and select the target crf \'%s\' from all tiles \'%s\' ' %(OfficeTrace_dir, target_crf_dir,all_tiles_dir))
else:
print("format:OfficeTrace_dir all_tiles_dir, target_crf_dir")
sys.exit()
read_trace_table_pos(OfficeTrace_dir)
pick_crf_files(all_tiles_dir,target_crf_dir)
print("pick_crf_files successfull!")