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中使用sqlalchemy操作數(shù)據(jù)庫的問題總結(jié)
在探索使用?FastAPI,?SQLAlchemy,?Pydantic,Redis,?JWT?構(gòu)建的項目的時候,其中數(shù)據(jù)庫訪問采用SQLAlchemy,并采用異步方式,這篇文章主要介紹了在Python中使用sqlalchemy來操作數(shù)據(jù)庫的幾個小總結(jié),需要的朋友可以參考下2024-08-08
pandas數(shù)據(jù)清洗,排序,索引設(shè)置,數(shù)據(jù)選取方法
下面小編就為大家分享一篇pandas數(shù)據(jù)清洗,排序,索引設(shè)置,數(shù)據(jù)選取方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-05-05

