import os
import shutil
def dataset_split(source_dir, outputdir):
origin_dir = os.listdir (source_dir)
count = 0
new_dir = os.listdir(source_dir)
for sub_dir in new_dir:
image_path = os.path.join(source_dir,sub_dir)
image_name = os.listdir(image_path)
print (image_name)
for i in range(len(image_name)):
origin_image_name = os.path.join(image_path,image_name[i])
print(origin_image_name)
new_image_name = os.path.join(image_path,str(count)+'_'+str(i)+'.jpg')
print(new_image_name)
os.rename (origin_image_name, new_image_name)
dest_path = str(output_dir+"\\")+str(count)+'_'+str(i)+'.jpg'
print(dest_path)
shutil.copy(new_image_name,dest_path)
count = count + 1
print('Done')
if __name__ == "__main__":
source_dir = "E:\RealLifeMaskedFaceDataset\self-built-masked-face-recognition-dataset\AFDB_masked_face_dataset"
output_dir = "E:\RealLifeMaskedFaceDataset\self-built-masked-face-recognition-dataset\output\withmask"
dataset_split(source_dir,output_dir)