這篇文章主要介紹了利用python怎么實(shí)現(xiàn)一個旋轉(zhuǎn)和水平翻轉(zhuǎn)功能,此處通過實(shí)例代碼給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考價值,需要的朋友可以參考下:

Python是一種編程語言,內(nèi)置了許多有效的工具,Python幾乎無所不能,該語言通俗易懂、容易入門、功能強(qiáng)大,在許多領(lǐng)域中都有廣泛的應(yīng)用,例如最熱門的大數(shù)據(jù)分析,人工智能,Web開發(fā)等。
如下所示:
# 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()到此這篇關(guān)于利用python怎么實(shí)現(xiàn)一個旋轉(zhuǎn)和水平翻轉(zhuǎn)功能的文章就介紹到這了,更多相關(guān)利用python怎么實(shí)現(xiàn)一個旋轉(zhuǎn)和水平翻轉(zhuǎn)功能的內(nèi)容請搜索創(chuàng)新互聯(lián)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持創(chuàng)新互聯(lián)!
網(wǎng)站欄目:利用python怎么實(shí)現(xiàn)一個旋轉(zhuǎn)和水平翻轉(zhuǎn)功能-創(chuàng)新互聯(lián)
文章起源:http://chinadenli.net/article6/cdcoig.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供營銷型網(wǎng)站建設(shè)、建站公司、網(wǎng)站排名、Google、網(wǎng)站營銷、網(wǎng)站設(shè)計(jì)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)
猜你還喜歡下面的內(nèi)容