python两级目录图像文件夹批量resize

"""
by Fivethousand
"""
import os
import cv2

NEW_SIZE=112        #新的图片的分辨率

Load_Path='F:\python_programs\\tasks_from_King\datasets\CASIA-WebFace-part'                    #读取原来的数据集的地址
Save_Path='F:\python_programs\\tasks_from_King\datasets'                    #要保存的新的数据集的地址


new_name="dataset(resized)"             #resize后的数据集名字
root=os.path.join(Save_Path,new_name).replace('\\','/')            #新数据集的根目录
if os.path.exists(root) is not True:
    os.mkdir(root)                          #创建根目录


for filename in os.listdir(Load_Path):
    print("Processing:"+filename)
    new_file=os.path.join(root,filename)
    if os.path.exists(new_file) is not True:
        os.mkdir(new_file)       #在新数据集根目录下新建同名文件夹
    for img in os.listdir(os.path.join(Load_Path,filename)):
        new_img=os.path.join(new_file,img)
        image=cv2.imread(os.path.join(Load_Path,filename,img))
        if image is not None:
            res=cv2.resize(image,(NEW_SIZE,NEW_SIZE),interpolation=cv2.INTER_CUBIC)
        cv2.imwrite(new_img, res)

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值