-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconverter.py
30 lines (24 loc) · 1.18 KB
/
converter.py
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
import cv2
import imageio
def convert_gif_to_jpg(gif_path, output_directory):
os.makedirs(output_directory, exist_ok=True)
gif_reader = imageio.get_reader(gif_path)
for frame_index in range(len(gif_reader)):
frame = gif_reader.get_data(frame_index)
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
output_path = os.path.join(output_directory, f"frame_{frame_index + 1}.jpg")
cv2.imwrite(output_path, rgb_frame)
directory = 'C:/Users/HP/Desktop/Python_AI/lbp-descriptor-textureRecog/assets/OASIS_MRI_DB'
output_directory = 'C:/Users/HP/Desktop/Python_AI/lbp-descriptor-textureRecog/assets/OASIS_MRI_DB/OASIS_Cross_gallery_converted'
index=0
category_path = os.path.join(directory, f'OASIS_Cross_gallery')
for filename in os.listdir(category_path):
gif_path = os.path.join(category_path, filename)
gif_reader = imageio.get_reader(gif_path)
for frame_index in range(len(gif_reader)):
frame = gif_reader.get_data(frame_index)
rgb_frame = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
output_path = os.path.join(output_directory, f"frame_{index + 1}.jpg")
cv2.imwrite(output_path, rgb_frame)
index=index+1