批量修改图片名字为voc2007数据集要求的格式

it2024-07-14  44

运行代码前,请先备份一份原始数据!因为直接在原始文件夹中修改图片名字。

import os img_path = "img_res" def rename(): i=1 for item in os.listdir(img_path): print("the raw picture name:",item) old_file = os.path.join(img_path,item) new_file = os.path.join(img_path,(str(i).zfill(6)+'.jpg')) os.rename(old_file, new_file) i+=1 if __name__ == '__main__': rename() print("Naming completed!")

修改前: 修改后: 注:str(i).zfill(6)的作用是在i不足6位时,在其前面补0 以上代码的缺点就是在原有的文件夹中直接修改图片名字,而不是另存到新的文件夹中,后期有时间将进行更新。 -------------------------------2020-10-21-14:19-------------------------------

参考: https://blog.csdn.net/qq_32863339/article/details/85260188

最新回复(0)