AppSettings and Configuration changes,

major changes to E_Distance and minor for D_Face
This commit is contained in:
2022-08-19 21:37:36 -07:00
parent 004017b9dd
commit be7a6abbf4
60 changed files with 1269 additions and 1344 deletions

View File

@ -254,14 +254,8 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
private List<D_Face> GetFaces(FileHolder resizedFileHolder, Item item, A_Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string facesDirectory)
{
List<D_Face> results = new();
if (_Configuration.PaddingLoops is null)
throw new NullReferenceException(nameof(_Configuration.PaddingLoops));
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (_Configuration.NumberOfJitters is null)
throw new NullReferenceException(nameof(_Configuration.NumberOfJitters));
if (_Configuration.NumberOfTimesToUpsample is null)
throw new NullReferenceException(nameof(_Configuration.NumberOfTimesToUpsample));
List<Location> locations;
FaceRecognitionDotNet.Image? unknownImage = null;
if (resizedFileHolder.Exists)
@ -275,7 +269,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
else
{
FaceRecognition faceRecognition = FaceRecognition.Create(_ModelParameter);
locations = faceRecognition.FaceLocations(_Model, unknownImage, _Configuration.NumberOfTimesToUpsample.Value, sortByPixelPercentage: true);
locations = faceRecognition.FaceLocations(_Model, unknownImage, _Configuration.NumberOfTimesToUpsample, sortByNormalizedPixelPercentage: true);
if (!locations.Any())
results.Add(new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, item.RelativePath, i: null, location: null));
else
@ -305,7 +299,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
padding = (int)((source.Width + source.Height) / 2 * .01);
for (int i = 0; i < locations.Count; i++)
{
for (int p = 0; p <= _Configuration.PaddingLoops.Value; p++)
for (int p = 0; p <= _Configuration.PaddingLoops; p++)
{
location = new(locations[i].Confidence,
locations[i].Bottom + (padding * p),
@ -332,9 +326,9 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
{
if (knownImage is null || knownImage.IsDisposed)
throw new NullReferenceException(nameof(knownImage));
facesLandmarks = faceRecognition.GetFaceLandmarkCollection(knownImage, _Configuration.NumberOfTimesToUpsample.Value, faceLocations: null, _PredictorModel, _Model);
facesLandmarks = faceRecognition.GetFaceLandmarkCollection(knownImage, _Configuration.NumberOfTimesToUpsample, faceLocations: null, _PredictorModel, _Model);
}
if (facesLandmarks.Count == 0 && p < _Configuration.PaddingLoops.Value)
if (facesLandmarks.Count == 0 && p < _Configuration.PaddingLoops)
continue;
else if (facesLandmarks.Count != 1)
continue;
@ -364,9 +358,9 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
{
if (rotatedImage is null || rotatedImage.IsDisposed)
throw new NullReferenceException(nameof(rotatedImage));
faceEncodings = faceRecognition.FaceEncodings(rotatedImage, _Configuration.NumberOfTimesToUpsample.Value, knownFaceLocation: null, _Configuration.NumberOfJitters.Value, _PredictorModel, _Model);
faceEncodings = faceRecognition.FaceEncodings(rotatedImage, _Configuration.NumberOfTimesToUpsample, knownFaceLocation: null, _Configuration.NumberOfJitters, _PredictorModel, _Model);
}
if (faceEncodings.Count == 0 && p < _Configuration.PaddingLoops.Value)
if (faceEncodings.Count == 0 && p < _Configuration.PaddingLoops)
continue;
else if (faceEncodings.Count != 1)
continue;
@ -417,15 +411,11 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
List<D_Face>? results;
if (item.Property?.Id is null)
throw new NullReferenceException(nameof(item.Property.Id));
if (_Configuration.PropertiesChangedForFaces is null)
throw new NullReferenceException(nameof(_Configuration.PropertiesChangedForFaces));
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (string.IsNullOrEmpty(dResultsFullGroupDirectory))
throw new NullReferenceException(nameof(dResultsFullGroupDirectory));
string json;
D_Face face;
bool checkForOutputResolutionChange = false;
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), item.ImageFileHolder.NameWithoutExtension);
@ -453,7 +443,17 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
}
if (!Directory.Exists(facesDirectory))
_ = Directory.CreateDirectory(facesDirectory);
if (_Configuration.PropertiesChangedForFaces.Value)
if (_Configuration.ForceFaceLastWriteTimeToCreationTime && !fileInfo.Exists && File.Exists(Path.ChangeExtension(fileInfo.FullName, ".delete")))
{
File.Move(Path.ChangeExtension(fileInfo.FullName, ".delete"), fileInfo.FullName);
fileInfo.Refresh();
}
if (_Configuration.ForceFaceLastWriteTimeToCreationTime && fileInfo.Exists && fileInfo.LastWriteTime != fileInfo.CreationTime)
{
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
fileInfo.Refresh();
}
if (_Configuration.PropertiesChangedForFaces)
results = null;
else if (!fileInfo.Exists)
results = null;
@ -467,15 +467,6 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
results = JsonSerializer.Deserialize<List<D_Face>>(json);
if (results is null)
throw new NullReferenceException(nameof(results));
for (int i = 0; i < results.Count; i++)
{
face = results[i];
if (face.OutputResolution is not null)
continue;
if (!checkForOutputResolutionChange)
checkForOutputResolutionChange = true;
results[i] = new(outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, face);
}
subFileTuples.Add(new Tuple<string, DateTime>(nameof(D_Face), fileInfo.LastWriteTime));
}
catch (Exception)
@ -484,15 +475,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
parseExceptions.Add(nameof(D_Face));
}
}
if (results is not null && checkForOutputResolutionChange)
{
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
}
else if (results is null)
if (results is null)
{
results = GetFaces(resizedFileHolder, item, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
@ -501,13 +484,23 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
subFileTuples.Add(new Tuple<string, DateTime>(nameof(D_Face), DateTime.Now));
}
if (_Configuration.ForceFaceLastWriteTimeToCreationTime)
{
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
if (Property.Models.Stateless.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
{
File.SetLastWriteTime(fileInfo.FullName, fileInfo.CreationTime);
fileInfo.Refresh();
subFileTuples.Add(new Tuple<string, DateTime>(nameof(D_Face), fileInfo.CreationTime));
}
}
return results;
}
internal void SaveFaces(string dResultsFullGroupDirectory, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Item item, List<D_Face> faceCollection)
{
if (_Configuration.OverrideForFaceImages is null)
throw new NullReferenceException(nameof(_Configuration.OverrideForFaceImages));
if (item.ImageFileHolder is null)
throw new NullReferenceException(nameof(item.ImageFileHolder));
if (item.ResizedFileHolder is null)
@ -539,7 +532,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
File.Delete(parentCheck);
}
imageFiles.Add(fileInfo.FullName);
if (_Configuration.OverrideForFaceImages.Value)
if (_Configuration.OverrideForFaceImages)
check = true;
else if (!fileInfo.Exists)
check = true;
@ -550,7 +543,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
SaveFaces(faceCollection, item.ResizedFileHolder, imageFiles);
}
internal static void SaveShortcuts(string[] juliePhares, string dResultsFullGroupDirectory, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, Item[] filteredItems)
internal static void SaveShortcuts(string[] juliePhares, string dResultsFullGroupDirectory, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, List<Item> items)
{
Person person;
string fileName;
@ -559,7 +552,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
WindowsShortcut windowsShortcut;
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
string dFacesContentDirectory = Path.Combine(dResultsFullGroupDirectory, $"({ticks})");
List<(Item, (string, Shared.Models.Properties.IFace?, (string, string, string, string))[])> collections = Item.GetCollection(propertyLogic, filteredItems, dFacesContentDirectory);
List<(Item, (string, Shared.Models.Properties.IFace?, (string, string, string, string))[])> collections = Item.GetCollection(propertyLogic, items, dFacesContentDirectory);
foreach ((Item item, (string personKey, Shared.Models.Properties.IFace? _, (string, string, string, string))[] collection) in collections)
{
if (collection.Length != 1)