import os
import math
import shutil
'''
寻找jpg文件名列表
'''
jpg_path = ' '
jpg_list= []
jpg_list = os.listdir(jpg_path)
name_list_jpg = []
name = map = {}
for jpg_name in jpg_list:
name_j,suffix = os.path.splitext(jpg_name)
name_list_jpg.append(name_j)
'''
寻找pcd文件名列表
'''
pcd_path = ' '
pcd_list = []
pcd_list = os.listdir(pcd_path)
name_list_pcd = []
for pcd_name in pcd_list:
name_p,suffix = os.splitext(pcd_name)
name_list.append(name_p)
'''
将原文件夹的jpg,pcd文件复制到现在文件夹里面的函数
'''
def cop_file(select_file_name_list,old_path1,old_path2,new_path):
for file_name in select_file_nam_list:
item1,item2 = file_name[0],file_name[1]
shutil.copyfile(old_path1+'/'+item1,new_path+'/'+item1)
shutil.copyfile(old_path2+'/'+item2,new_path+'/'+item2)
'''
寻找最近的jpg与pcd文件
'''
list_match = []
list_match_jpg = []
list_match_pcd = []
j_p_match = []
for namej in sorted(name_list_jpg):
namej = float(int(namej)/pow(10,6))
list_match_jpg.append(namej)
for namep in sorted(name_list_pcd):
key = float(namep)
list_match_pcd.append(key)
name_map[key] = namep
save_path = ' '
if not os.path.exists(save_path):
os.mkdir(save_path)
for list_jpg in list_match_jpg:
for list_pcd in list_match_pcd:
j_p_match = []
if(abs(list_jpg-list_pcd)<0.02):
list_jpg1 = str(int(list_jpg*pow(10,6))) + '.jpg'
list_pcd1 = name_map[list_pcd] + '.pcd'
list_match = [list_jpg1,list_pcd1]
j_p_match,append(list_match)
save_dir = save_path + '/' + str(int((list_jpg)*pow(10,6)))
` if not os.path.exists(save_dir):
os.mkdir(save_dir)
cop_file(j_p_match,jpg_path,pcd_path,save_dir)