欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python實(shí)現(xiàn)旋轉(zhuǎn)和水平翻轉(zhuǎn)的方法

 更新時間:2018年10月25日 15:12:19   作者:sunfellow2009  
今天小編就為大家分享一篇python實(shí)現(xiàn)旋轉(zhuǎn)和水平翻轉(zhuǎn)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧

如下所示:

# coding=utf-8
import glob
import os

from PIL import Image


def rotate_270(imgae):
"""
將圖片旋轉(zhuǎn)270度
"""
# 讀取圖像
im = Image.open(imgae)
# im.show()
# 指定逆時針旋轉(zhuǎn)的角度
im_rotate = im.rotate(270)
# im_rotate.show()
return im_rotate


def flip_horizontal(image):
"""
將圖片水平翻轉(zhuǎn)
"""
im = Image.open(image)
# im.show()
im_fh = im.transpose(Image.FLIP_LEFT_RIGHT)
# im_fh.show()
return im_fh


def createFile(path):
isExists = os.path.exists(path)
# 判斷結(jié)果
if not isExists:
# 如果不存在則創(chuàng)建目錄
# 創(chuàng)建目錄操作函數(shù)
os.makedirs(path)
return True
else:
# 如果目錄存在則不創(chuàng)建,并提示目錄已存在
print('%s 目錄已存在' % path)
return False


def main():
path = 'D:/VideoPhotos/hongshi/'
createFile('D:/VideoPhotos/hongshi_rotate')
createFile('D:/VideoPhotos/hongshi_flip_horizontal')

dirs = os.listdir(path)
for dir in dirs:
# print(dir)
createFile('D:/VideoPhotos/hongshi_rotate/' + dir)
createFile('D:/VideoPhotos/hongshi_flip_horizontal/' + dir)

images = glob.glob(path + dir + r"\*.jpg")
for image in images:
image_name = image[image.find("\\"):]
print(image_name)
rotate_270(image).save('D:/VideoPhotos/hongshi_rotate/' + dir +
image_name)
flip_horizontal(image).save(
'D:/VideoPhotos/hongshi_flip_horizontal/' + dir + image_name)


if __name__ == '__main__':
main()

以上這篇python實(shí)現(xiàn)旋轉(zhuǎn)和水平翻轉(zhuǎn)的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論