批量找到时间戳相近的jpg和pcd文件,并且保存在新的文件夹

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)

        

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值