zoukankan      html  css  js  c++  java
  • python将图片旋转,颠倒,修改尺寸

    直接上代码,根据需求注释选择相应修改 

    from PIL import Image
    import os
    import os.path
    
    rootdir = r'G:jianfengproject
    ubblish_detfaster_rcnn
    ubbish_voc_xml
    ubbish_pic_forTest4396'  # 指明被遍历的文件夹
    for parent, dirnames, filenames in os.walk(rootdir):
        for filename in filenames:
            print('parent is :' + parent)
            print('filename is :' + filename)
            currentPath = os.path.join(parent, filename)
            print('the fulll name of the file is :' + currentPath)
    
            im = Image.open(currentPath)
            #进行上下颠倒
            out = im.transpose(Image.FLIP_TOP_BOTTOM)
            #进行左右颠倒
            out =out.transpose(Image.FLIP_LEFT_RIGHT)
            # 进行旋转90
            out = im.transpose(Image.ROTATE_90)
            # 进行旋转180
            out = im.transpose(Image.ROTATE_180)
            # 进行旋转270
            out = im.transpose(Image.ROTATE_270)
            #将图片重新设置尺寸
            out= out.resize((1280,720))
            newname = r"G:jianfengproject
    ubblish_detfaster_rcnn
    ubbish_voc_xml
    ubbish_pic_forTest4396_720" + '\' +"10t"+ filename
            out.save(newname)
  • 相关阅读:
    抓老鼠
    我的寒假作业
    寒假作业
    大一上学期C语言学习总结
    我的三位老师
    自我介绍
    2019春季第七周作业
    第六周总结
    第五周作业及其总结
    2019春季第四周作业
  • 原文地址:https://www.cnblogs.com/bob-jianfeng/p/11237806.html
Copyright © 2011-2022 走看看