python将图片旋转,颠倒,修改尺寸
程序员文章站
2022-07-02 13:21:20
直接上代码,根据需求注释选择相应修改 ......
直接上代码,根据需求注释选择相应修改
from pil import image import os import os.path rootdir = r'g:\jianfeng\project\rubblish_det\faster_rcnn\rubbish_voc_xml\rubbish_pic_fortest\4396' # 指明被遍历的文件夹 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:\jianfeng\project\rubblish_det\faster_rcnn\rubbish_voc_xml\rubbish_pic_fortest\4396_720" + '\\' +"10t"+ filename out.save(newname)