Reputation: 21
I tried to flip horizontally((about Y axis)) all the images in a specific folder using python I want to keep the initial images and for the flipped ones I want to rename them as *_flip.jpg. I am stuck . How to do it?
Upvotes: 0
Views: 3773
Reputation: 11907
You can loop through each image in the directory and use flip
of OpenCV to flip it horizontally on based on what axis you want. You can then save the flipped file accordingly.
Look at the following snippet to get an idea.
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)
Hope this helps.
Upvotes: 3