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()
# 指定逆時(shí)針旋轉(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)的方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
Python程序員面試題 你必須提前準(zhǔn)備!(答案及解析)
這篇文章主要為大家解析了你必須提前準(zhǔn)備的Python程序員面試題答案,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2018-01-01
關(guān)于Python中字典dict的存儲(chǔ)原理詳解
Python字典是另一種可變?nèi)萜髂P?可存儲(chǔ)任意類型對(duì)象。如字符串、數(shù)字、元組等其他容器模型,因?yàn)樽值涫菬o(wú)序的所以不支持索引和切片,需要的朋友可以參考下2023-05-05
pytorch的梯度計(jì)算以及backward方法詳解
今天小編就為大家分享一篇pytorch的梯度計(jì)算以及backward方法詳解,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-01-01
WIndows10系統(tǒng)下面安裝Anaconda、Pycharm及Pytorch環(huán)境全過(guò)程(NVIDIA?GPU版本)
這篇文章主要給大家介紹了關(guān)于WIndows10系統(tǒng)下面安裝Anaconda、Pycharm及Pytorch環(huán)境(NVIDIA?GPU版本)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下2023-02-02
python PyQt5 爬蟲實(shí)現(xiàn)代碼
這篇文章主要介紹了python PyQt5 爬蟲實(shí)現(xiàn)代碼,代碼簡(jiǎn)單易懂,對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-04-04
Python簡(jiǎn)單實(shí)現(xiàn)Base64編碼和解碼的方法
這篇文章主要介紹了Python簡(jiǎn)單實(shí)現(xiàn)Base64編碼和解碼的方法,結(jié)合具體實(shí)例形式分析了Python實(shí)現(xiàn)base64編碼解碼相關(guān)函數(shù)與使用技巧,需要的朋友可以參考下2017-04-04
python數(shù)據(jù)庫(kù)操作常用功能使用詳解(創(chuàng)建表/插入數(shù)據(jù)/獲取數(shù)據(jù))
這篇文章主要介紹了python數(shù)據(jù)庫(kù)操作常用功能使用方法:獲取mysql版本、創(chuàng)建表、插入數(shù)據(jù)、slect獲取數(shù)據(jù)等,下面看示例吧2013-12-12

