python批处理将图片进行放大

有时候对于网络识别,将原始图片放进网络中并不能达到自己想要的效果,但是有时候如果将图片放大之后,识别率却能够达到意想不到的结果现在提供一种将文件中的图片进行批处理放大的代码:

import os
​
from PIL import Image
import sys
 
 
#获取path目录下的所有文件
def get_imlist(path):
    return[os.path.join(path,f)
           for f in os.listdir(path)]
 
 
def change_size(path):
    directorys=get_imlist(path)
    for directory in directorys:
    #不是图片文件就跳过
        print(directory)
        if not(directory.endswith('.jpg') or directory.endswith('.png') or directory.endswith('.bmp')):  ##b
            pass
        else:
            img=Image.open(directory)
            s="/"
            #获取文件名(含后缀)
            oimage_name=directory[directory.rfind(s)+1:]
            (oimage_width,oimage_height)=img.size
            new_width=oimage_width * 3
            new_height=oimage_height * 3
            out=img.resize((new_width,new_height),Image.ANTIALIAS)
            out.save("%s" %oimage_name)  #直接替换
 
 
if __name__ == '__main__':
    change_size("F:\桌面\\test")

  • 6
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

心之所向521

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值