alignfaces 1.0.1__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,42 @@
1
+ from pathlib import Path
2
+ import os
3
+
4
+
5
+ # Run at outset of get_landmarks()
6
+ def get_source_files(MotherDir, FilePrefix="", FilePostfix="jpg"):
7
+ if type(MotherDir) == str:
8
+ MotherDir = Path(MotherDir)
9
+ input_files = []
10
+ for p in MotherDir.rglob(FilePrefix + "*" + FilePostfix):
11
+ input_files.append(str(p))
12
+ print(str(p))
13
+ return sorted(input_files)
14
+
15
+
16
+ # Run at outset of align_procrustes() and place_aperture()
17
+ def clone_directory_tree(MotherDir, new_dir="aligned", FilePrefix="", FilePostfix="jpg"):
18
+ if type(MotherDir) == str:
19
+ MotherDir = Path(MotherDir)
20
+ input_files = get_source_files(MotherDir, FilePrefix=FilePrefix, FilePostfix=FilePostfix)
21
+ P = []
22
+ for f in input_files:
23
+ P.append(Path(f).parent)
24
+ P = list(set(P))
25
+ mothers_name = MotherDir.parts[-1]
26
+ new_directory = MotherDir.parent / (str(mothers_name) + "-" + new_dir)
27
+ print(new_directory)
28
+ for p in P:
29
+ new_dir = new_directory / p.relative_to(MotherDir)
30
+ if not new_dir.exists():
31
+ new_dir.mkdir(parents=True, exist_ok=True) # NEED TEST
32
+ print(new_dir)
33
+ return str(new_directory) + os.sep
34
+
35
+
36
+ # Within make_aligned_faces (align_procrustes and place_aperture),
37
+ # get_landmark_features() is used to get only analyze those files with
38
+ # landmarks and so returns a list of input and output filenames.
39
+ # Where output_files determined by output_dir
40
+ # End
41
+ # -----------------------------------------------------------------------------
42
+ # -----------------------------------------------------------------------------
@@ -0,0 +1,42 @@
1
+ from pathlib import Path
2
+ import os
3
+
4
+
5
+ # Run at outset of get_landmarks()
6
+ def get_source_files(MotherDir, FilePrefix="", FilePostfix="jpg"):
7
+ if type(MotherDir) == str:
8
+ MotherDir = Path(MotherDir)
9
+ input_files = []
10
+ for p in MotherDir.rglob(FilePrefix + "*" + FilePostfix):
11
+ input_files.append(str(p))
12
+ print(str(p))
13
+ return input_files
14
+
15
+
16
+ # Run at outset of align_procrustes() and place_aperture()
17
+ def clone_directory_tree(MotherDir, new_dir="aligned", FilePrefix="", FilePostfix="jpg"):
18
+ if type(MotherDir) == str:
19
+ MotherDir = Path(MotherDir)
20
+ input_files = get_source_files(MotherDir, FilePrefix=FilePrefix, FilePostfix=FilePostfix)
21
+ P = []
22
+ for f in input_files:
23
+ P.append(Path(f).parent)
24
+ P = list(set(P))
25
+ mothers_name = MotherDir.parts[-1]
26
+ new_directory = MotherDir.parent / (str(mothers_name) + "-" + new_dir)
27
+ print(new_directory)
28
+ for p in P:
29
+ new_dir = new_directory / p.relative_to(MotherDir)
30
+ if not new_dir.exists():
31
+ new_dir.mkdir(parents=False, exist_ok=False) # NEED TEST
32
+ print(new_dir)
33
+ return str(new_directory) + os.sep
34
+
35
+
36
+ # Within make_aligned_faces (align_procrustes and place_aperture),
37
+ # get_landmark_features() is used to get only analyze those files with
38
+ # landmarks and so returns a list of input and output filenames.
39
+ # Where output_files determined by output_dir
40
+ # End
41
+ # -----------------------------------------------------------------------------
42
+ # -----------------------------------------------------------------------------
@@ -0,0 +1,86 @@
1
+ import glob
2
+ import os
3
+
4
+ # Deprecated function (does too much!)
5
+ def make_files(MotherDir, FilePrefix="", FilePostfix="jpg", new_dir="aligned"):
6
+ # Copy directory structure for output
7
+ MotherBits = MotherDir.split(os.path.sep)
8
+ go_back = -len(MotherBits[-2]) - 1
9
+ GrannyDir = MotherDir[0:go_back]
10
+ AuntieDir = GrannyDir + MotherBits[-2] + "-" + new_dir + os.path.sep
11
+
12
+ if not os.path.isdir(AuntieDir):
13
+ os.mkdir(AuntieDir)
14
+
15
+ input_files = []
16
+ output_files = []
17
+ for infile in glob.iglob(MotherDir + "**" + os.path.sep +
18
+ FilePrefix + "*." + FilePostfix, recursive=True):
19
+ input_files.append(infile)
20
+ GiveToAuntie = infile[len(MotherDir):]
21
+ output_files.append(AuntieDir + GiveToAuntie)
22
+ AdoptedBits = GiveToAuntie.split(os.path.sep)
23
+ AdoptedBits = AdoptedBits[:-1]
24
+ CheckForThis = AuntieDir
25
+ for next_dir in AdoptedBits:
26
+ CheckForThis = CheckForThis + next_dir + os.path.sep
27
+ if not os.path.isdir(CheckForThis):
28
+ os.mkdir(CheckForThis)
29
+
30
+ assert len(input_files) == len(output_files)
31
+ # # Write lists to files.
32
+ # with open(GrannyDir + 'input_files.data', 'wb') as filehandle:
33
+ # pickle.dump(input_files, filehandle)
34
+ # with open(GrannyDir + 'output_files.data', 'wb') as filehandle:
35
+ # pickle.dump(output_files, filehandle)
36
+ files = []
37
+ files.append(input_files)
38
+ files.append(output_files)
39
+ output_dir = AuntieDir
40
+ return files, output_dir
41
+
42
+
43
+ # Run at outset of get_landmarks()
44
+ def get_source_files(MotherDir, FilePrefix="", FilePostfix="jpg"):
45
+ MotherBits = MotherDir.split(os.path.sep)
46
+ input_files = []
47
+ for infile in glob.iglob(MotherDir + "**" + os.path.sep +
48
+ FilePrefix + "*." + FilePostfix, recursive=True):
49
+ input_files.append(infile)
50
+ return input_files
51
+
52
+
53
+ # Run at outset of align_procrustes() and place_aperture()
54
+ def clone_directory_tree(MotherDir, new_dir="aligned", FilePrefix="", FilePostfix="jpg"):
55
+ MotherBits = MotherDir.split(os.path.sep)
56
+ go_back = -len(MotherBits[-2]) - 1
57
+ GrannyDir = MotherDir[0:go_back]
58
+ AuntieDir = GrannyDir + MotherBits[-2] + "-" + new_dir + os.path.sep
59
+
60
+ if not os.path.isdir(AuntieDir):
61
+ os.mkdir(AuntieDir)
62
+
63
+ for infile in glob.iglob(MotherDir + "**" + os.path.sep +
64
+ FilePrefix + "*." + FilePostfix, recursive=True):
65
+
66
+ GiveToAuntie = infile[len(MotherDir):]
67
+
68
+ AdoptedBits = GiveToAuntie.split(os.path.sep)
69
+ AdoptedBits = AdoptedBits[:-1]
70
+ CheckForThis = AuntieDir
71
+ for next_dir in AdoptedBits:
72
+ CheckForThis = CheckForThis + next_dir + os.path.sep
73
+ if not os.path.isdir(CheckForThis):
74
+ os.mkdir(CheckForThis)
75
+
76
+ output_dir = AuntieDir
77
+ return output_dir
78
+
79
+
80
+ # Within make_aligned_faces (align_procrustes and place_aperture),
81
+ # get_landmark_features() is used to get only analyze those files with
82
+ # landmarks and so returns a list of input and output filenames.
83
+ # Where output_files determined by output_dir
84
+ # End
85
+ # -----------------------------------------------------------------------------
86
+ # -----------------------------------------------------------------------------