python實現(xiàn)旋轉(zhuǎn)和水平翻轉(zhuǎn)的方法
更新時間:2018年10月25日 15:12:19 作者:sunfellow2009
今天小編就為大家分享一篇python實現(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實現(xiàn)旋轉(zhuǎn)和水平翻轉(zhuǎn)的方法就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python程序員面試題 你必須提前準(zhǔn)備!(答案及解析)
這篇文章主要為大家解析了你必須提前準(zhǔn)備的Python程序員面試題答案,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-01-01
WIndows10系統(tǒng)下面安裝Anaconda、Pycharm及Pytorch環(huán)境全過程(NVIDIA?GPU版本)
這篇文章主要給大家介紹了關(guān)于WIndows10系統(tǒng)下面安裝Anaconda、Pycharm及Pytorch環(huán)境(NVIDIA?GPU版本)的相關(guān)資料,文中通過實例代碼介紹的非常詳細,需要的朋友可以參考下2023-02-02
Python簡單實現(xiàn)Base64編碼和解碼的方法
這篇文章主要介紹了Python簡單實現(xiàn)Base64編碼和解碼的方法,結(jié)合具體實例形式分析了Python實現(xiàn)base64編碼解碼相關(guān)函數(shù)與使用技巧,需要的朋友可以參考下2017-04-04
python數(shù)據(jù)庫操作常用功能使用詳解(創(chuàng)建表/插入數(shù)據(jù)/獲取數(shù)據(jù))
這篇文章主要介紹了python數(shù)據(jù)庫操作常用功能使用方法:獲取mysql版本、創(chuàng)建表、插入數(shù)據(jù)、slect獲取數(shù)據(jù)等,下面看示例吧2013-12-12

