forked from kpiatan/ros_display_emotions
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflip_images.py
More file actions
30 lines (24 loc) · 1.04 KB
/
flip_images.py
File metadata and controls
30 lines (24 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import os
from PIL import Image
# Set the input and output folder paths
input_folder = "./src/cropped/1024_600"
output_folder = "./src/cropped/1024_600_flipped" # Set to input_folder to overwrite
# Create the output folder if it doesn't exist
if not os.path.exists(output_folder):
os.makedirs(output_folder)
# Supported image file extensions
image_extensions = ('.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp')
# Process each file in the folder
for filename in os.listdir(input_folder):
if filename.lower().endswith(image_extensions):
input_path = os.path.join(input_folder, filename)
output_path = os.path.join(output_folder, filename)
try:
with Image.open(input_path) as img:
# Rotate the image by 180 degrees
rotated_img = img.rotate(180)
# Save the rotated image
rotated_img.save(output_path)
print(f"Rotated and saved: {output_path}")
except Exception as e:
print(f"Failed to process {filename}: {e}")