-
Notifications
You must be signed in to change notification settings - Fork 0
/
dms.py
71 lines (49 loc) · 1.79 KB
/
dms.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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Created on Thu Aug 1 22:01:10 2024
@author: anonymous
"""
import os
import shutil
from pathlib import Path
FACES_DIR = Path("faces")
def move_images(image_names, new_directory):
print(image_names)
#print(new_directory)
target_directory = os.path.join("faces", new_directory)
print(target_directory)
# Create new directory if doesn't exists
os.makedirs(target_directory, exist_ok=True)
counter = 1
# Move images
for image_name in image_names:
source_path = os.path.join('faces/Unknown', image_name)
file_extension = os.path.splitext(image_name)[1]
# Generate new unique filename
while True:
new_image_name = f"{new_directory}_{counter}{file_extension}"
destination_path = os.path.join(target_directory, new_image_name)
print(destination_path)
if not os.path.exists(destination_path):
break
counter += 1
if os.path.exists(source_path):
print("moving....")
shutil.move(source_path, destination_path)
counter += 1
else:
print(f'Image {image_name} not found in Unknown directory')
return True
def list_directories():
directories = {}
for directory in FACES_DIR.iterdir():
if directory.is_dir():
images = [image.name for image in directory.glob("*.jpg") if image.is_file()]
directories[directory.name] = images
return directories
def load_image(directory: str, filename: str):
dir_path = FACES_DIR / directory
if dir_path.exists() and (dir_path / filename).exists():
return str(dir_path)
return ""