您好,登錄后才能下訂單哦!
這篇文章主要介紹了利用python怎么實(shí)現(xiàn)一個(gè)旋轉(zhuǎn)和水平翻轉(zhuǎn)功能,此處通過(guò)實(shí)例代碼給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考價(jià)值,需要的朋友可以參考下:
Python是一種編程語(yǔ)言,內(nèi)置了許多有效的工具,Python幾乎無(wú)所不能,該語(yǔ)言通俗易懂、容易入門(mén)、功能強(qiáng)大,在許多領(lǐng)域中都有廣泛的應(yīng)用,例如最熱門(mén)的大數(shù)據(jù)分析,人工智能,Web開(kāi)發(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() # 指定逆時(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()
到此這篇關(guān)于利用python怎么實(shí)現(xiàn)一個(gè)旋轉(zhuǎn)和水平翻轉(zhuǎn)功能的文章就介紹到這了,更多相關(guān)利用python怎么實(shí)現(xiàn)一個(gè)旋轉(zhuǎn)和水平翻轉(zhuǎn)功能的內(nèi)容請(qǐng)搜索億速云以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持億速云!
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。