簡體   English   中英

使用python翻轉圖像

[英]Flip image using python

我嘗試使用 python 水平翻轉((關於 Y 軸))特定文件夾中的所有圖像我想保留初始圖像,對於翻轉的圖像,我想將它們重命名為 *_flip.jpg。 我被卡住了。 怎么做?

您可以遍歷目錄,並使用每個圖像flip的OpenCV根據你想要的東西軸水平上翻轉。 然后,您可以相應地保存翻轉的文件。

查看以下代碼片段以獲得一個想法。

import os
import cv2

directory = ''

for file in os.listdir(directory):
    img = cv2.imread(directory + file)
    horizontal_img = cv2.flip( img, 0 )

    #saving now
    cv2.imwrite(file + '_flip' + '.jpg', horizontal_img)

希望這可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM