-
Notifications
You must be signed in to change notification settings - Fork 0
/
image_name_change.py
executable file
·34 lines (26 loc) · 1.03 KB
/
image_name_change.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
31
32
33
34
#after saving renamed images i think size of image maximize
# Python program to explain cv2.imwrite() method
# importing cv2
import cv2
# importing os module
import os
datab_path="C:\\Users\\Aakash\\Desktop\\tcs_face_recognition\\media\\upload_image_from_this_folder\\"
for img_class_name in os.listdir(datab_path):
all_imgs_of_img_class_name =[datab_path + img_class_name+'\\' + f for f in os.listdir(datab_path + img_class_name)]
output_directory = "C:\\Users\\Aakash\\Desktop\\tcs_face_recognition\\media\\tp\\" + img_class_name
temp=1
os.mkdir(output_directory)
for image_path in all_imgs_of_img_class_name:
# Using cv2.imread() method
# to read the image
img = cv2.imread(image_path)
# Change the current directory
# to specified directory
os.chdir(output_directory)
# Filename
filename = img_class_name+ str(temp)+'.jpg'
temp=temp+1
# Using cv2.imwrite() method
# Saving the image
cv2.imwrite(filename, img)
print(f'Successfully saved {img_class_name}')