-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_data.py
More file actions
36 lines (30 loc) · 1.04 KB
/
process_data.py
File metadata and controls
36 lines (30 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
31
32
33
34
from imutils import paths
import os
# Methods
def rename_files(imagePaths, variable):
for imagePath in imagePaths:
# Extract the filename
path_split = imagePath.split(os.path.sep)
filename = path_split[2]
# Extract the different elements
elements = filename.split('.')
root = elements[0]
extension = elements[1]
variable = variable+1
# Create the new filename
new_filename = str(variable) + "." + extension
new_path = path_split[0] + os.path.sep + path_split[1] + os.path.sep + new_filename
# Rename the file
os.rename(imagePath, new_path)
# Rename the images
# YOU CAN PUT THE FOLDERS WITH THE IMAGES THEY ARE RENAMED AUTOMATICALLY
if not os.listdir("Gestures"):
print("Directory is empty")
else:
print("Loading the images")
imagePaths = list(paths.list_images("Gestures"))
# Sort files
imagePaths_sorted = sorted(imagePaths)
# Iterate the image paths
rename_files(imagePaths_sorted, 0)
print("Sucessfully finished")