From fb1c68e1f5b0169cd36edad5bda1e7ef03af21b7 Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Thu, 22 Sep 2022 23:39:58 -0700 Subject: [PATCH] Change to the Normalized Pixel Percentage Formula --- Instance/DlibDotNet.cs | 5 +- Instance/Models/Binder/Configuration.cs | 12 -- Instance/Models/Configuration.cs | 9 - Instance/Models/_D_Face.cs | 43 ++++- Instance/Models/_E_Distance.cs | 4 +- Instance/appsettings.Development.json | 6 +- Instance/appsettings.Staging.json | 6 +- Instance/appsettings.json | 6 +- Map/Map.csproj | 1 + Map/Models/Configuration.cs | 9 - Map/Models/MapLogic.cs | 11 +- Map/Models/Stateless/MapLogic.cs | 158 ++++++---------- Property/Models/Stateless/Container.cs | 10 +- Shared/Models/Face.cs | 4 +- Shared/Models/Location.cs | 94 ++++++---- Shared/Models/Properties/ILocation.cs | 12 +- Shared/Models/Stateless/ILocation.cs | 4 +- Shared/Models/Stateless/Methods/Face.cs | 15 -- Shared/Models/Stateless/Methods/IFace.cs | 5 - Shared/Models/Stateless/Methods/ILocation.cs | 31 ++-- Shared/Models/Stateless/Methods/IMapping.cs | 12 +- Shared/Models/Stateless/Methods/Location.cs | 56 ++++-- Shared/Models/Stateless/Methods/Mapping.cs | 83 ++++----- Tests/UnitTestCalculations.cs | 175 +++++++++++++++--- Tests/UnitTestResize.cs | 85 --------- .../Models/Binder/Configuration.cs | 12 -- .../Models/Configuration.cs | 9 - 27 files changed, 426 insertions(+), 451 deletions(-) diff --git a/Instance/DlibDotNet.cs b/Instance/DlibDotNet.cs index 2578ebd..dfb53aa 100644 --- a/Instance/DlibDotNet.cs +++ b/Instance/DlibDotNet.cs @@ -273,7 +273,6 @@ public partial class DlibDotNet configuration.MapLogicSigma, configuration.MappingDefaultName, configuration.MappingMoveUnableToMatch, - configuration.MappingSaveFaceEncoding, configuration.MappingSaveNotMapped, configuration.MappingSaveMapped, configuration.MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping, @@ -282,8 +281,6 @@ public partial class DlibDotNet configuration.PersonBirthdayFormat, configuration.PersonKeyFormat, configuration.SortingDaysDeltaTolerance, - configuration.SortingFacesToSkipAfterSortBeforeLoad, - configuration.SortingFacesToTakeAfterSortBeforeLoad, configuration.SortingMaximumPerFaceShouldBeHigh, configuration.SortingMaximumPerKey, configuration.SortingSigma); @@ -740,7 +737,7 @@ public partial class DlibDotNet if (string.IsNullOrEmpty(eResultsFullGroupDirectory)) throw new NullReferenceException(nameof(eResultsFullGroupDirectory)); List distinctFilteredFaces = SetMappingThenGetDistinctFilteredFacesWithMapping(argZero, containers); - List selectedFilteredFaces = E_Distance.GetSelectedFilteredFaces(_MapConfiguration, distinctFilteredFaces); + List selectedFilteredFaces = E_Distance.GetSelectedFilteredFaces(distinctFilteredFaces); E_Distance.SetFaceDistances(_AppSettings.MaxDegreeOfParallelism, ticks, selectedFilteredFaces); MapLogic mapLogic = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _MapConfiguration, _Faces.FileNameExtension, _Faces.HiddenFileNameExtension, _FaceParts.FileNameExtension, ticks, personContainers, eResultsFullGroupDirectory, distinctFilteredFaces, distance); SortingContainer[] sortingContainers = E_Distance.SetFaceMappingSortingCollectionThenGetSortingContainers(_AppSettings.MaxDegreeOfParallelism, _MapConfiguration, ticks, mapLogic, selectedFilteredFaces); diff --git a/Instance/Models/Binder/Configuration.cs b/Instance/Models/Binder/Configuration.cs index a4366a4..035a5bc 100644 --- a/Instance/Models/Binder/Configuration.cs +++ b/Instance/Models/Binder/Configuration.cs @@ -34,7 +34,6 @@ public class Configuration [Display(Name = "Mapped Max Index"), Required] public int? MappedMaxIndex { get; set; } [Display(Name = "Mapping Default Name"), Required] public string MappingDefaultName { get; set; } [Display(Name = "Mapping Move Unable to Match by 1 Tick"), Required] public bool? MappingMoveUnableToMatch { get; set; } - [Display(Name = "Mapping Save Face Encoding"), Required] public bool? MappingSaveFaceEncoding { get; set; } [Display(Name = "Mapping Save Mapped"), Required] public bool? MappingSaveMapped { get; set; } [Display(Name = "Mapping Save Not Mapped"), Required] public bool? MappingSaveNotMapped { get; set; } [Display(Name = "Mapping Use Deterministic Hash Code Unknown Face Key Value Pairs for Add to Mapping"), Required] public bool? MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { get; set; } @@ -69,8 +68,6 @@ public class Configuration [Display(Name = "Save Shortcuts"), Required] public string[] SaveShortcutsForOutputResolutions { get; set; } [Display(Name = "Skip Search"), Required] public bool? SkipSearch { get; set; } [Display(Name = "Sorting Days Delta Tolerance"), Required] public int? SortingDaysDeltaTolerance { get; set; } - [Display(Name = "Sorting Faces To Skip After Sort Before Load"), Required] public int? SortingFacesToSkipAfterSortBeforeLoad { get; set; } - [Display(Name = "Sorting Faces To Take After Sort Before Load"), Required] public int? SortingFacesToTakeAfterSortBeforeLoad { get; set; } [Display(Name = "SortingMaximumPerFaceShould be High"), Required] public int? SortingMaximumPerFaceShouldBeHigh { get; set; } [Display(Name = "Sorting Maximum Per Key"), Required] public int? SortingMaximumPerKey { get; set; } [Display(Name = "Sorting Sigma"), Required] public int? SortingSigma { get; set; } @@ -132,8 +129,6 @@ public class Configuration throw new NullReferenceException(nameof(configuration.MappingDefaultName)); if (configuration.MappingMoveUnableToMatch is null) throw new NullReferenceException(nameof(configuration.MappingMoveUnableToMatch)); - if (configuration.MappingSaveFaceEncoding is null) - throw new NullReferenceException(nameof(configuration.MappingSaveFaceEncoding)); if (configuration.MappingSaveNotMapped is null) throw new NullReferenceException(nameof(configuration.MappingSaveNotMapped)); if (configuration.MappingSaveMapped is null) @@ -194,10 +189,6 @@ public class Configuration throw new NullReferenceException(nameof(configuration.SkipSearch)); if (configuration.SortingDaysDeltaTolerance is null) throw new NullReferenceException(nameof(configuration.SortingDaysDeltaTolerance)); - if (configuration.SortingFacesToSkipAfterSortBeforeLoad is null) - throw new NullReferenceException(nameof(configuration.SortingFacesToSkipAfterSortBeforeLoad)); - if (configuration.SortingFacesToTakeAfterSortBeforeLoad is null) - throw new NullReferenceException(nameof(configuration.SortingFacesToTakeAfterSortBeforeLoad)); if (configuration.SortingMaximumPerFaceShouldBeHigh is null) throw new NullReferenceException(nameof(configuration.SortingMaximumPerFaceShouldBeHigh)); if (configuration.SortingMaximumPerKey is null) @@ -241,7 +232,6 @@ public class Configuration configuration.MappedMaxIndex, configuration.MappingDefaultName, configuration.MappingMoveUnableToMatch.Value, - configuration.MappingSaveFaceEncoding.Value, configuration.MappingSaveNotMapped.Value, configuration.MappingSaveMapped.Value, configuration.MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping.Value, @@ -275,8 +265,6 @@ public class Configuration configuration.SaveShortcutsForOutputResolutions, configuration.SkipSearch.Value, configuration.SortingDaysDeltaTolerance.Value, - configuration.SortingFacesToSkipAfterSortBeforeLoad.Value, - configuration.SortingFacesToTakeAfterSortBeforeLoad.Value, configuration.SortingMaximumPerFaceShouldBeHigh.Value, configuration.SortingMaximumPerKey.Value, configuration.SortingSigma.Value, diff --git a/Instance/Models/Configuration.cs b/Instance/Models/Configuration.cs index 9be57ae..0976a7a 100644 --- a/Instance/Models/Configuration.cs +++ b/Instance/Models/Configuration.cs @@ -33,7 +33,6 @@ public class Configuration public int? MappedMaxIndex { init; get; } public string MappingDefaultName { init; get; } public bool MappingMoveUnableToMatch { init; get; } - public bool MappingSaveFaceEncoding { init; get; } public bool MappingSaveNotMapped { init; get; } public bool MappingSaveMapped { init; get; } public bool MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { init; get; } @@ -67,8 +66,6 @@ public class Configuration public string[] SaveShortcutsForOutputResolutions { init; get; } public bool SkipSearch { init; get; } public int SortingDaysDeltaTolerance { init; get; } - public int SortingFacesToSkipAfterSortBeforeLoad { init; get; } - public int SortingFacesToTakeAfterSortBeforeLoad { init; get; } public int SortingMaximumPerFaceShouldBeHigh { init; get; } public int SortingMaximumPerKey { init; get; } public int SortingSigma { init; get; } @@ -101,7 +98,6 @@ public class Configuration int? mappedMaxIndex, string mappingDefaultName, bool mappingMoveUnableToMatch, - bool mappingSaveFaceEncoding, bool mappingSaveNotMapped, bool mappingSaveMapped, bool mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping, @@ -135,8 +131,6 @@ public class Configuration string[] saveShortcutsForOutputResolutions, bool skipSearch, int sortingDaysDeltaTolerance, - int sortingFacesToSkipAfterSortBeforeLoad, - int sortingFacesToTakeAfterSortBeforeLoad, int sortingMaximumPerFaceShouldBeHigh, int sortingMaximumPerKey, int sortingSigma, @@ -168,7 +162,6 @@ public class Configuration MappedMaxIndex = mappedMaxIndex; MappingDefaultName = mappingDefaultName; MappingMoveUnableToMatch = mappingMoveUnableToMatch; - MappingSaveFaceEncoding = mappingSaveFaceEncoding; MappingSaveNotMapped = mappingSaveNotMapped; MappingSaveMapped = mappingSaveMapped; MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping = mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping; @@ -202,8 +195,6 @@ public class Configuration SaveShortcutsForOutputResolutions = saveShortcutsForOutputResolutions; SkipSearch = skipSearch; SortingDaysDeltaTolerance = sortingDaysDeltaTolerance; - SortingFacesToSkipAfterSortBeforeLoad = sortingFacesToSkipAfterSortBeforeLoad; - SortingFacesToTakeAfterSortBeforeLoad = sortingFacesToTakeAfterSortBeforeLoad; SortingMaximumPerFaceShouldBeHigh = sortingMaximumPerFaceShouldBeHigh; SortingMaximumPerKey = sortingMaximumPerKey; SortingSigma = sortingSigma; diff --git a/Instance/Models/_D_Face.cs b/Instance/Models/_D_Face.cs index 7a96202..30a77cc 100644 --- a/Instance/Models/_D_Face.cs +++ b/Instance/Models/_D_Face.cs @@ -1,6 +1,7 @@ using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Imaging; +using System.Reflection; using System.Text.Json; using System.Text.Json.Serialization; using View_by_Distance.FaceRecognitionDotNet; @@ -33,6 +34,7 @@ public class D_Face private readonly ImageCodecInfo _ImageCodecInfo; private readonly ModelParameter _ModelParameter; private readonly PredictorModel _PredictorModel; + private readonly ConstructorInfo _ConstructorInfo; private readonly EncoderParameters _EncoderParameters; private readonly ImageCodecInfo _HiddenImageCodecInfo; private readonly EncoderParameters _HiddenEncoderParameters; @@ -53,6 +55,10 @@ public class D_Face _HiddenImageCodecInfo = hiddenImageCodecInfo; _HiddenEncoderParameters = hiddenEncoderParameters; _HiddenFileNameExtension = hiddenFileNameExtension; + ConstructorInfo? constructorInfo = typeof(PropertyItem).GetConstructor(BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public, null, Array.Empty(), null); + if (constructorInfo is null) + throw new Exception(); + _ConstructorInfo = constructorInfo; _WriteIndentedAndWhenWritingNull = new JsonSerializerOptions { WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull }; } @@ -144,31 +150,65 @@ public class D_Face return result; } + private static byte[] GetBytes(string value) + { + byte[] results = new byte[value.Length + 1]; + for (int i = 0; i < value.Length; i++) + results[i] = (byte)value[i]; + results[value.Length] = 0x00; + return results; + } + + private PropertyItem GetPropertyItem(int id, string value) + { + PropertyItem result = (PropertyItem)_ConstructorInfo.Invoke(null); + byte[] bytes = GetBytes(value); + result.Id = id; + result.Len = value.Length + 1; + result.Type = 2; + result.Value = bytes; + return result; + } + private void SaveFaces(FileHolder resizedFileHolder, List<(Face, FileInfo?, string)> collection) { + int pixel; int width; int height; + string json; Bitmap bitmap; Graphics graphics; Location? location; Rectangle rectangle; + PropertyItem? propertyItem; + int software = (int)IExif.Tags.Software; + int userComment = (int)IExif.Tags.UserComment; using Bitmap source = new(resizedFileHolder.FullName); + int imageDescription = (int)IExif.Tags.ImageDescription; foreach ((Face face, FileInfo? fileInfo, string fileName) in collection) { if (fileInfo is null) continue; - if (face.FaceEncoding is null || face?.Location is null) + if (face.FaceEncoding is null || face?.Location?.NormalizedPixelPercentage is null || face?.OutputResolution is null) continue; location = Shared.Models.Stateless.Methods.ILocation.GetLocation(face.Location, _Configuration.LocationDigits, _Configuration.LocationFactor, source.Height, source.Width, collection.Count); if (location is null) continue; width = location.Right - location.Left; height = location.Bottom - location.Top; + json = JsonSerializer.Serialize(face.FaceEncoding); + pixel = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(face.Location, _Configuration.LocationDigits, _Configuration.LocationFactor, face.OutputResolution); rectangle = new Rectangle(location.Left, location.Top, width, height); using (bitmap = new(width, height)) { using (graphics = Graphics.FromImage(bitmap)) graphics.DrawImage(source, new Rectangle(0, 0, width, height), rectangle, GraphicsUnit.Pixel); + propertyItem = GetPropertyItem(userComment, json); + bitmap.SetPropertyItem(propertyItem); + propertyItem = GetPropertyItem(imageDescription, pixel.ToString()); + bitmap.SetPropertyItem(propertyItem); + propertyItem = GetPropertyItem(software, face.Location.NormalizedPixelPercentage.Value.ToString()); + bitmap.SetPropertyItem(propertyItem); bitmap.Save(fileInfo.FullName, _ImageCodecInfo, _EncoderParameters); } if (File.Exists(fileName)) @@ -304,7 +344,6 @@ public class D_Face results = JsonSerializer.Deserialize>(json); if (results is null) throw new NullReferenceException(nameof(results)); - results = Shared.Models.Stateless.Methods.IFace.GetVerifiedFaces(_Configuration.LocationDigits, _Configuration.LocationFactor, results); if (!_Configuration.ForceFaceLastWriteTimeToCreationTime) { normalizedPixelPercentageCollection = Shared.Models.Stateless.Methods.IFace.GetInts(results); diff --git a/Instance/Models/_E_Distance.cs b/Instance/Models/_E_Distance.cs index 6521b29..248f602 100644 --- a/Instance/Models/_E_Distance.cs +++ b/Instance/Models/_E_Distance.cs @@ -116,11 +116,11 @@ internal class E_Distance : Shared.Models.Methods.IFaceDistance return results; } - internal static List GetSelectedFilteredFaces(Map.Models.Configuration configuration, List distinctFilteredFaces) + internal static List GetSelectedFilteredFaces(List distinctFilteredFaces) { List results; Face[] orderedFilteredFaces = (from l in distinctFilteredFaces orderby l.Mapping is not null, l.Mapping?.MappingFromItem.MinimumDateTime descending select l).ToArray(); - results = orderedFilteredFaces.Skip(configuration.SortingFacesToSkipAfterSortBeforeLoad).Take(configuration.SortingFacesToTakeAfterSortBeforeLoad).ToList(); + results = orderedFilteredFaces.ToList(); return results; } diff --git a/Instance/appsettings.Development.json b/Instance/appsettings.Development.json index eef913e..fdf03f3 100644 --- a/Instance/appsettings.Development.json +++ b/Instance/appsettings.Development.json @@ -66,8 +66,8 @@ "ForceResizeLastWriteTimeToCreationTime": false, "LoadOrCreateThenSaveIndex": false, "LocationConfidenceFactor": 2, - "LocationDigits": 6, - "LocationFactor": 1000000, + "LocationDigits": 9, + "LocationFactor": 10000, "MapLogicSigma": 3, "MappedMaxIndex": 1034720, "MappingDefaultName": "John Doe~25", @@ -113,8 +113,6 @@ "SaveResizedSubFiles": true, "SkipSearch": false, "SortingDaysDeltaTolerance": 700, - "SortingFacesToSkipAfterSortBeforeLoad": 0, - "SortingFacesToTakeAfterSortBeforeLoad": 55000, "SortingMaximumPerFaceShouldBeHigh": 1000, "SortingMaximumPerKey": 27, "SortingSigma": 3, diff --git a/Instance/appsettings.Staging.json b/Instance/appsettings.Staging.json index e3f778f..9203456 100644 --- a/Instance/appsettings.Staging.json +++ b/Instance/appsettings.Staging.json @@ -66,8 +66,8 @@ "ForceResizeLastWriteTimeToCreationTime": false, "LoadOrCreateThenSaveIndex": false, "LocationConfidenceFactor": 2, - "LocationDigits": 6, - "LocationFactor": 1000000, + "LocationDigits": 9, + "LocationFactor": 10000, "MapLogicSigma": 3, "MappedMaxIndex": 1034720, "MappingDefaultName": "John Doe~25", @@ -112,8 +112,6 @@ "SaveResizedSubFiles": true, "SkipSearch": false, "SortingDaysDeltaTolerance": 700, - "SortingFacesToSkipAfterSortBeforeLoad": 0, - "SortingFacesToTakeAfterSortBeforeLoad": 55000, "SortingMaximumPerFaceShouldBeHigh": 1000, "SortingMaximumPerKey": 27, "SortingSigma": 3, diff --git a/Instance/appsettings.json b/Instance/appsettings.json index 5825b7d..ed1642b 100644 --- a/Instance/appsettings.json +++ b/Instance/appsettings.json @@ -66,8 +66,8 @@ "ForceResizeLastWriteTimeToCreationTime": false, "LoadOrCreateThenSaveIndex": false, "LocationConfidenceFactor": 2, - "LocationDigits": 6, - "LocationFactor": 1000000, + "LocationDigits": 9, + "LocationFactor": 10000, "MapLogicSigma": 3, "MappedMaxIndex": 1034720, "MappingDefaultName": "John Doe~25", @@ -112,8 +112,6 @@ "SaveResizedSubFiles": true, "SkipSearch": false, "SortingDaysDeltaTolerance": 700, - "SortingFacesToSkipAfterSortBeforeLoad": 0, - "SortingFacesToTakeAfterSortBeforeLoad": 55000, "SortingMaximumPerFaceShouldBeHigh": 1000, "SortingMaximumPerKey": 27, "SortingSigma": 3, diff --git a/Map/Map.csproj b/Map/Map.csproj index f419436..3e1b382 100644 --- a/Map/Map.csproj +++ b/Map/Map.csproj @@ -35,6 +35,7 @@ + diff --git a/Map/Models/Configuration.cs b/Map/Models/Configuration.cs index 2a74388..33200f9 100644 --- a/Map/Models/Configuration.cs +++ b/Map/Models/Configuration.cs @@ -15,7 +15,6 @@ public class Configuration public int MapLogicSigma { init; get; } public string MappingDefaultName { init; get; } public bool MappingMoveUnableToMatch { init; get; } - public bool MappingSaveFaceEncoding { init; get; } public bool MappingSaveNotMapped { init; get; } public bool MappingSaveMapped { init; get; } public bool MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { init; get; } @@ -24,8 +23,6 @@ public class Configuration public string PersonBirthdayFormat { init; get; } public string PersonKeyFormat { init; get; } public int SortingDaysDeltaTolerance { init; get; } - public int SortingFacesToSkipAfterSortBeforeLoad { init; get; } - public int SortingFacesToTakeAfterSortBeforeLoad { init; get; } public int SortingMaximumPerFaceShouldBeHigh { init; get; } public int SortingMaximumPerKey { init; get; } public int SortingSigma { init; get; } @@ -40,7 +37,6 @@ public class Configuration int mapLogicSigma, string mappingDefaultName, bool mappingMoveUnableToMatch, - bool mappingSaveFaceEncoding, bool mappingSaveNotMapped, bool mappingSaveMapped, bool mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping, @@ -49,8 +45,6 @@ public class Configuration string personBirthdayFormat, string personKeyFormat, int sortingDaysDeltaTolerance, - int sortingFacesToSkipAfterSortBeforeLoad, - int sortingFacesToTakeAfterSortBeforeLoad, int sortingMaximumPerFaceShouldBeHigh, int sortingMaximumPerKey, int sortingSigma) @@ -64,7 +58,6 @@ public class Configuration MapLogicSigma = mapLogicSigma; MappingDefaultName = mappingDefaultName; MappingMoveUnableToMatch = mappingMoveUnableToMatch; - MappingSaveFaceEncoding = mappingSaveFaceEncoding; MappingSaveNotMapped = mappingSaveNotMapped; MappingSaveMapped = mappingSaveMapped; MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping = mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping; @@ -73,8 +66,6 @@ public class Configuration PersonBirthdayFormat = personBirthdayFormat; PersonKeyFormat = personKeyFormat; SortingDaysDeltaTolerance = sortingDaysDeltaTolerance; - SortingFacesToSkipAfterSortBeforeLoad = sortingFacesToSkipAfterSortBeforeLoad; - SortingFacesToTakeAfterSortBeforeLoad = sortingFacesToTakeAfterSortBeforeLoad; SortingMaximumPerFaceShouldBeHigh = sortingMaximumPerFaceShouldBeHigh; SortingMaximumPerKey = sortingMaximumPerKey; SortingSigma = sortingSigma; diff --git a/Map/Models/MapLogic.cs b/Map/Models/MapLogic.cs index 2faf701..1facd5d 100644 --- a/Map/Models/MapLogic.cs +++ b/Map/Models/MapLogic.cs @@ -584,7 +584,6 @@ public class MapLogic throw new NullReferenceException(nameof(_Configuration)); List results = new(); string by; - string json; string checkFile; string directory; string shortcutFile; @@ -643,20 +642,12 @@ public class MapLogic faceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesFileNameExtension}")); hiddenFaceFileHolder = new(Path.Combine(facesDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacesHiddenFileNameExtension}")); facePartsFileHolder = new(Path.Combine(facePartsDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}{_FacePartsFileNameExtension}")); - if (string.IsNullOrEmpty(personDirectory)) + if (string.IsNullOrEmpty(personDirectory) || face.Mapping.MappingFromPerson.By == Stateless.IMapLogic.Mapping) shortcutFile = string.Empty; else shortcutFile = Path.Combine(personDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.lnk"); saveContainer = new(checkFile, directory, faceFileHolder, hiddenFaceFileHolder, string.Empty, facePartsFileHolder, face.Mapping.MappingFromItem.ResizedFileHolder, shortcutFile); results.Add(saveContainer); - if (_Configuration.MappingSaveFaceEncoding) - { - checkFile = Path.Combine(personDirectory, $"{face.Mapping.MappingFromLocation.DeterministicHashCodeKey}{face.Mapping.MappingFromItem.ImageFileHolder.ExtensionLowered}.json"); - json = JsonSerializer.Serialize(face.FaceEncoding); - saveContainer = new(checkFile, personDirectory, json); - results.Add(saveContainer); - } - results.Add(saveContainer); } return results; } diff --git a/Map/Models/Stateless/MapLogic.cs b/Map/Models/Stateless/MapLogic.cs index c6704af..9596109 100644 --- a/Map/Models/Stateless/MapLogic.cs +++ b/Map/Models/Stateless/MapLogic.cs @@ -1,6 +1,5 @@ using Humanizer; using ShellProgressBar; -using System.Text.Json; using View_by_Distance.Shared.Models; using View_by_Distance.Shared.Models.Stateless.Methods; @@ -74,15 +73,12 @@ internal abstract class MapLogic } } - internal static List<(string, string[], string, List?)> DeleteEmptyDirectoriesAndGetCollection(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, List personKeyFormattedCollection, Dictionary> keyValuePairs) + internal static List<(string, string[], string)> DeleteEmptyDirectoriesAndGetCollection(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, List personKeyFormattedCollection) { - List<(string, string[], string, List?)> results = new(); + List<(string, string[], string)> results = new(); int? id; - bool check; string[] files; - List? faces; const int zero = 0; - List checks = new(); string[] yearDirectories; string personKeyFormatted; string ticksDirectoryName; @@ -94,7 +90,6 @@ internal abstract class MapLogic string[] personNameLinkDirectories; string? personFirstInitialDirectory; string[] personDisplayDirectoryNames; - bool keyValuePairsAny = keyValuePairs.Any(); string manualCopyHumanized = nameof(IMapLogic.ManualCopy).Humanize(LetterCasing.Title); int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds); string forceSingleImageHumanized = nameof(IMapLogic.ForceSingleImage).Humanize(LetterCasing.Title); @@ -156,31 +151,10 @@ internal abstract class MapLogic { if (file.EndsWith(".lnk") || file.EndsWith(".json")) continue; - (id, normalizedPixelPercentage, faces) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, facesFileNameExtension, keyValuePairsAny, keyValuePairs, file); + (id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, facesFileNameExtension, file); if (id is null || normalizedPixelPercentage is null) continue; - if (configuration.MappingMoveUnableToMatch) - { - if (faces is null) - check = false; - else - { - check = false; - checks.Clear(); - foreach (Face face in faces) - { - if (face.Mapping is null) - throw new NotSupportedException(); - checks.Add(face.Mapping.MappingFromLocation.NormalizedPixelPercentage); - if (normalizedPixelPercentage.Value != face.Mapping.MappingFromLocation.NormalizedPixelPercentage) - continue; - check = true; - } - if (!check) - checks.Add(normalizedPixelPercentage.Value); - } - } - results.Add(new(personKeyFormatted, personDisplayDirectoryNames, file, faces)); + results.Add(new(personKeyFormatted, personDisplayDirectoryNames, file)); } personNameLinkDirectories = Directory.GetDirectories(personFirstInitialDirectory, "*", SearchOption.TopDirectoryOnly); foreach (string personNameLinkDirectory in personNameLinkDirectories) @@ -221,13 +195,10 @@ internal abstract class MapLogic private static void SetKeyValuePairs(Configuration configuration, long ticks, List personContainers, List distinctFilteredFaces, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, Dictionary personKeyToPersonContainer, Dictionary> idThenNormalizedPixelPercentageToPersonContainers, List<(string[], PersonContainer)> possiblyNewPersonDisplayDirectoryNamesAndPersonContainer, Dictionary> incorrectIdThenNormalizedPixelPercentageToPersonContainers, Dictionary personKeyToRanges) { - string check; const int zero = 0; - string rightPadded; PersonBirthday? personBirthday; string newestPersonKeyFormatted; PersonContainer[] distinctPersonContainers; - int normalizedPixelPercentageInDecimalForm; Dictionary personKeyFormattedToPersonContainer = new(); Dictionary> personKeyToPersonContainerCollection = new(); Dictionary>> idThenNormalizedPixelPercentageToPersonContainerCollection = new(); @@ -272,21 +243,9 @@ internal abstract class MapLogic personDisplayDirectoryTo.Add(personDisplayDirectory, new(personDisplayDirectoryNames, personKeyFormattedToPersonContainer[personKeyFormatted])); if (!idThenNormalizedPixelPercentageToPersonContainerCollection.ContainsKey(id)) idThenNormalizedPixelPercentageToPersonContainerCollection.Add(id, new()); - check = normalizedPixelPercentage.ToString(); - if (check.Length == configuration.LocationDigits) - { - if (!idThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage)) - idThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new()); - idThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); - } - else - { - rightPadded = ILocation.GetRightPadded(configuration.LocationDigits, check); - normalizedPixelPercentageInDecimalForm = int.Parse(rightPadded); - if (!idThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentageInDecimalForm)) - idThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentageInDecimalForm, new()); - idThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); - } + if (!idThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage)) + idThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new()); + idThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); } foreach (KeyValuePair keyValuePair in personDisplayDirectoryTo) possiblyNewPersonDisplayDirectoryNamesAndPersonContainer.Add(keyValuePair.Value); @@ -311,27 +270,14 @@ internal abstract class MapLogic continue; if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection.ContainsKey(id)) incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection.Add(id, new()); - check = normalizedPixelPercentage.ToString(); if (!personKeyFormattedToPersonContainer.ContainsKey(personKeyFormatted)) { personContainer = new(personBirthday, configuration.MappingDefaultName); personKeyFormattedToPersonContainer.Add(personKeyFormatted, personContainer); } - if (check.Length == configuration.LocationDigits) - { - if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage)) - incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new()); - incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); - } - else - { - rightPadded = ILocation.GetRightPadded(configuration.LocationDigits, check); - normalizedPixelPercentageInDecimalForm = int.Parse(rightPadded); - if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentageInDecimalForm)) - incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentageInDecimalForm, new()); - incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); - } - + if (!incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].ContainsKey(normalizedPixelPercentage)) + incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id].Add(normalizedPixelPercentage, new()); + incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection[id][normalizedPixelPercentage].Add(personKeyFormattedToPersonContainer[personKeyFormatted]); } } foreach (KeyValuePair>> keyValuePair in incorrectIdThenNormalizedPixelPercentageToPersonContainerCollection) @@ -358,26 +304,6 @@ internal abstract class MapLogic return result; } - private static bool Valid(string checkFile, List faces) - { - bool result = false; - string json; - foreach (Face face in faces) - { - if (face.FaceEncoding is null) - throw new NotSupportedException(); - if (faces.Count != 1) - break; - result = true; - if (File.Exists(checkFile)) - continue; - json = JsonSerializer.Serialize(face.FaceEncoding); - if (IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null)) - continue; - } - return result; - } - private static void MoveUnableToMatch(Configuration configuration, string eDistanceContentDirectory, string file, string jsonFile) { bool result; @@ -407,7 +333,11 @@ internal abstract class MapLogic break; } if (string.IsNullOrEmpty(checkDirectoryName) || !directoryNames.Any() || !long.TryParse(directoryNames[^1][1..^1], out long directoryTicks)) + { result = false; + File.Delete(jsonFile); + File.Delete(file); + } else { bool jsonFileExists = File.Exists(jsonFile); @@ -430,28 +360,43 @@ internal abstract class MapLogic { } } - private static int SetCollectionsAndGetUnableToMatchCount(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, Shared.Models.Methods.IFaceDistance? distance, Dictionary personKeyFormattedToNewestPersonKeyFormatted, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, string[], string, List?)> collection) + private static int SetCollectionsAndGetUnableToMatchCount(Configuration configuration, string facesFileNameExtension, long ticks, string eDistanceContentDirectory, Shared.Models.Methods.IFaceDistance? distance, Dictionary> idToFaces, Dictionary personKeyFormattedToNewestPersonKeyFormatted, List<(string, string[], int, int)> personKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, int, int)> incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, List<(string, string[], string)> collection) { int? id; int result = 0; + bool debugCheck; string? checkFile; + List? faces; + List debugChecks = new(); List checkFaces = new(); int? normalizedPixelPercentage; string newestPersonKeyFormatted; + List duplicates = new(); string personDisplayDirectoryName; + bool idToFacesAny = idToFaces.Any(); + List normalizedPixelPercentages; + Dictionary> idToNormalizedPixelPercentages = new(); int totalSeconds = (int)Math.Floor(new TimeSpan(DateTime.Now.Ticks - ticks).TotalSeconds); string message = $") {collection.Count:000} join from ticks Director(ies) - B - {totalSeconds} total second(s)"; ProgressBarOptions options = new() { ProgressCharacter = '─', ProgressBarOnBottom = true, DisableBottomPercentage = true }; using ProgressBar progressBar = new(collection.Count, message, options); - foreach ((string personKeyFormatted, string[] personDisplayDirectoryNames, string file, List? faces) in collection) + foreach ((string personKeyFormatted, string[] personDisplayDirectoryNames, string file) in collection) { progressBar.Tick(); - (id, normalizedPixelPercentage, _) = IMapping.GetReversedDeterministicHashCodeKey(configuration.LocationDigits, facesFileNameExtension, file); + (id, normalizedPixelPercentage, faces) = IMapping.GetReversedDeterministicHashCodeKey( + configuration.LocationDigits, + facesFileNameExtension, + idToFacesAny, + idToFaces, + file); if (id is null || normalizedPixelPercentage is null) { result++; continue; } + if (!idToNormalizedPixelPercentages.ContainsKey(id.Value)) + idToNormalizedPixelPercentages.Add(id.Value, new()); + normalizedPixelPercentages = idToNormalizedPixelPercentages[id.Value]; checkFile = GetCheckFile(configuration, facesFileNameExtension, file, id.Value, normalizedPixelPercentage.Value); if (string.IsNullOrEmpty(checkFile)) throw new NotSupportedException(); @@ -460,20 +405,33 @@ internal abstract class MapLogic result++; continue; } + debugCheck = false; checkFaces.Clear(); + debugChecks.Clear(); foreach (Face face in faces) { if (face.Mapping is null) throw new NotSupportedException(); + debugChecks.Add(face.Mapping.MappingFromLocation.NormalizedPixelPercentage); if (normalizedPixelPercentage.Value != face.Mapping.MappingFromLocation.NormalizedPixelPercentage) continue; + if (normalizedPixelPercentages.Contains(face.Mapping.MappingFromLocation.NormalizedPixelPercentage)) + { + duplicates.Add(string.Concat(id.Value, '.', normalizedPixelPercentage.Value, ".jpg", facesFileNameExtension)); + continue; + } + debugCheck = true; checkFaces.Add(face); + if (!debugCheck) + debugChecks.Add(normalizedPixelPercentage.Value); } if (checkFaces.Count != 1 && distance is not null && File.Exists(checkFile)) { checkFaces.Clear(); checkFaces.AddRange(distance.GetMatchingFaces(configuration.FaceDistanceTolerance, checkFile, faces)); } + if (!checkFaces.Any() && faces.Count == 1) + checkFaces.AddRange(faces); if (!checkFaces.Any()) { result++; @@ -488,22 +446,22 @@ internal abstract class MapLogic MoveUnableToMatch(configuration, eDistanceContentDirectory, file, checkFile); continue; } - if (!Valid(checkFile, checkFaces)) - { - result++; - if (configuration.MappingMoveUnableToMatch) - MoveUnableToMatch(configuration, eDistanceContentDirectory, file, checkFile); - continue; - } + idToNormalizedPixelPercentages[id.Value].Add(normalizedPixelPercentage.Value); if (!personKeyFormattedToNewestPersonKeyFormatted.ContainsKey(personKeyFormatted)) newestPersonKeyFormatted = personKeyFormatted; else newestPersonKeyFormatted = personKeyFormattedToNewestPersonKeyFormatted[personKeyFormatted]; personDisplayDirectoryName = personDisplayDirectoryNames[^1]; - if (!string.IsNullOrEmpty(personDisplayDirectoryName) && personDisplayDirectoryName[0] != '!') - personKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, personDisplayDirectoryNames, id.Value, normalizedPixelPercentage.Value)); - else + if (string.IsNullOrEmpty(personDisplayDirectoryName) || personDisplayDirectoryName[0] == '!') incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, id.Value, normalizedPixelPercentage.Value)); + else + personKeyFormattedIdThenNormalizedPixelPercentageCollection.Add(new(newestPersonKeyFormatted, personDisplayDirectoryNames, id.Value, normalizedPixelPercentage.Value)); + } + if (duplicates.Any()) + { + duplicates.Sort(); + if (duplicates.Any()) + { } } return result; } @@ -686,18 +644,18 @@ internal abstract class MapLogic keyValuePairs.Add(face.Mapping.MappingFromItem.Id, new()); keyValuePairs[face.Mapping.MappingFromItem.Id].Add(face); } - List<(string, string[], string, List?)> collection = DeleteEmptyDirectoriesAndGetCollection(configuration, + List<(string, string[], string)> collection = DeleteEmptyDirectoriesAndGetCollection(configuration, facesFileNameExtension, ticks, eDistanceContentDirectory, - personKeyFormattedCollection, - keyValuePairs); + personKeyFormattedCollection); int unableToMatchCount = SetCollectionsAndGetUnableToMatchCount( configuration, facesFileNameExtension, ticks, eDistanceContentDirectory, faceDistance, + keyValuePairs, personKeyFormattedToNewestPersonKeyFormatted, personKeyFormattedIdThenNormalizedPixelPercentageCollection, incorrectPersonKeyFormattedIdThenNormalizedPixelPercentageCollection, diff --git a/Property/Models/Stateless/Container.cs b/Property/Models/Stateless/Container.cs index abe9284..2604ec9 100644 --- a/Property/Models/Stateless/Container.cs +++ b/Property/Models/Stateless/Container.cs @@ -153,6 +153,7 @@ public class Container Shared.Models.Container[] results; Item item; int length; + int itemCount; int additional; string inferred; List items; @@ -170,11 +171,6 @@ public class Container { foreach (FileHolder sourceDirectoryFileHolder in sourceDirectoryFileHolderCollection) { - if (sourceDirectory.Contains("Facebook")) - { - if (sourceDirectory.Contains("Facebook")) - { } - } relativePath = Shared.Models.Stateless.Methods.IPath.GetRelativePath(sourceDirectoryFileHolder.FullName, length, forceExtensionToLower: true); fileHolderKeyValuePairs.Add(relativePath, new(sourceDirectory, sourceDirectoryFileHolder)); } @@ -262,9 +258,9 @@ public class Container { additional = 0; container = keyValuePairs[sourceDirectory]; - length = items.Count; + itemCount = items.Count; existing = (from l in container.Items select l.ImageFileHolder?.FullName).ToArray(); - for (int i = 0; i < length; i++) + for (int i = 0; i < itemCount; i++) { item = items[i]; if (item.ImageFileHolder is null || existing.Contains(item.ImageFileHolder.FullName)) diff --git a/Shared/Models/Face.cs b/Shared/Models/Face.cs index 4ea7012..458c2e3 100644 --- a/Shared/Models/Face.cs +++ b/Shared/Models/Face.cs @@ -55,8 +55,8 @@ public class Face : Properties.IFace _DateTime = (from l in dateTimes where l.HasValue select l.Value).Min(); } - public Face(Face face, Location location, int locationDigits, int locationFactor, int zCount) : - this(face.DateTime, face.FaceDistance, face.FaceEncoding, face.FaceParts, new(location, locationDigits, locationFactor, zCount), face.LocationIndex, face.Mapping, face.OutputResolution, face.RelativePath) + public Face(Face face, int height, Location location, int locationDigits, int locationFactor, int width, int zCount) : + this(face.DateTime, face.FaceDistance, face.FaceEncoding, face.FaceParts, new(height, location, locationDigits, locationFactor, width, zCount), face.LocationIndex, face.Mapping, face.OutputResolution, face.RelativePath) { } public override string ToString() diff --git a/Shared/Models/Location.cs b/Shared/Models/Location.cs index 4b9f022..2fd6f71 100644 --- a/Shared/Models/Location.cs +++ b/Shared/Models/Location.cs @@ -6,42 +6,54 @@ namespace View_by_Distance.Shared.Models; public class Location : Properties.ILocation, IEquatable { - protected int _Bottom; - protected double _Confidence; - protected int _Left; - protected readonly int? _NormalizedPixelPercentage; - protected int _Right; - protected int _Top; - public double Confidence => _Confidence; - public int Bottom => _Bottom; - public int Left => _Left; - public int? NormalizedPixelPercentage => _NormalizedPixelPercentage; - public int Right => _Right; - public int Top => _Top; + public int Bottom { init; get; } + public double Confidence { init; get; } + public int Left { init; get; } + public int? NormalizedPixelPercentage { init; get; } + public int Right { init; get; } + public int Top { init; get; } [JsonConstructor] public Location(int bottom, double confidence, int left, int? normalizedPixelPercentage, int right, int top) { - _Confidence = confidence; - _Bottom = bottom; - _Left = left; - _NormalizedPixelPercentage = normalizedPixelPercentage; - _Right = right; - _Top = top; + Confidence = confidence; + Bottom = bottom; + Left = left; + NormalizedPixelPercentage = normalizedPixelPercentage; + Right = right; + Top = top; Stateless.Methods.Location.Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1); } public Location(double confidence, int height, Location location, int locationDigits, int locationFactor, int width, int zCount) : - this(location.Bottom, confidence, location.Left, Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, locationDigits, locationFactor, location.Right, location.Top, width, zCount), location.Right, location.Top) => - Stateless.Methods.Location.Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount); + this( + location.Bottom, + confidence, + location.Left, + Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, locationDigits, locationFactor, location.Right, location.Top, width, zCount), + location.Right, + location.Top) => + Stateless.Methods.Location.Check(Bottom, Left, NormalizedPixelPercentage, Right, Top, zCount); public Location(int bottom, double confidence, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) : - this(bottom, confidence, left, Stateless.Methods.Location.GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount), right, top) => - Stateless.Methods.Location.Check(_Bottom, height, _Left, _NormalizedPixelPercentage, _Right, _Top, width, zCount); + this( + bottom, + confidence, + left, + Stateless.Methods.Location.GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount), + right, + top) => + Stateless.Methods.Location.Check(Bottom, height, Left, NormalizedPixelPercentage, Right, Top, width, zCount); - public Location(Location location, int locationDigits, int locationFactor, int zCount) : - this(location.Bottom, location.Confidence, location.Left, Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height: location.Bottom - location.Top, location.Left, locationDigits, locationFactor, location.Right, location.Top, width: location.Right - location.Left, zCount), location.Right, location.Top) => - Stateless.Methods.Location.Check(_Bottom, _Left, _NormalizedPixelPercentage, _Right, _Top, zCount); + public Location(int height, Location location, int locationDigits, int locationFactor, int width, int zCount) : + this( + location.Bottom, + location.Confidence, + location.Left, + Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, locationDigits, locationFactor, location.Right, location.Top, width, zCount), + location.Right, + location.Top) => + Stateless.Methods.Location.Check(Bottom, Left, NormalizedPixelPercentage, Right, Top, zCount); public Location(double confidence, int factor, int height, Location location, int locationDigits, int locationFactor, int width, int zCount) { @@ -52,13 +64,15 @@ public class Location : Properties.ILocation, IEquatable int right = Math.Min(location.Right + x, width); int top = Math.Max(location.Top - y, 0); int normalizedPixelPercentage = Stateless.Methods.Location.GetNormalizedPixelPercentage(location.Bottom, height, location.Left, locationDigits, locationFactor, location.Right, location.Top, width, zCount); - Stateless.Methods.Location.Check(bottom, left, _NormalizedPixelPercentage, right, top, zCount); - _Confidence = confidence; - _Bottom = bottom; - _Left = left; - _NormalizedPixelPercentage = normalizedPixelPercentage; - _Right = right; - _Top = top; + if (location.NormalizedPixelPercentage is null || normalizedPixelPercentage != location.NormalizedPixelPercentage.Value) + throw new Exception(); + Stateless.Methods.Location.Check(bottom, left, NormalizedPixelPercentage, right, top, zCount); + Confidence = confidence; + Bottom = bottom; + Left = left; + NormalizedPixelPercentage = normalizedPixelPercentage; + Right = right; + Top = top; } public override bool Equals(object? obj) => Equals(obj as Location); @@ -72,20 +86,20 @@ public class Location : Properties.ILocation, IEquatable public override int GetHashCode() { int hashCode = -773114317; - hashCode = hashCode * -1521134295 + _Bottom.GetHashCode(); - hashCode = hashCode * -1521134295 + _Left.GetHashCode(); - hashCode = hashCode * -1521134295 + _Right.GetHashCode(); - hashCode = hashCode * -1521134295 + _Top.GetHashCode(); + hashCode = hashCode * -1521134295 + Bottom.GetHashCode(); + hashCode = hashCode * -1521134295 + Left.GetHashCode(); + hashCode = hashCode * -1521134295 + Right.GetHashCode(); + hashCode = hashCode * -1521134295 + Top.GetHashCode(); return hashCode; } public bool Equals(Location? location) { return location is not null - && _Bottom == location.Bottom - && _Left == location.Left - && _Right == location.Right - && _Top == location.Top; + && Bottom == location.Bottom + && Left == location.Left + && Right == location.Right + && Top == location.Top; } public static bool operator ==(Location location1, Location location2) => EqualityComparer.Default.Equals(location1, location2); diff --git a/Shared/Models/Properties/ILocation.cs b/Shared/Models/Properties/ILocation.cs index 2d8c9c9..0446f09 100644 --- a/Shared/Models/Properties/ILocation.cs +++ b/Shared/Models/Properties/ILocation.cs @@ -3,11 +3,11 @@ namespace View_by_Distance.Shared.Models.Properties; public interface ILocation { - public int Bottom { get; } - public double Confidence { get; } - public int Left { get; } - public int? NormalizedPixelPercentage { get; } - public int Right { get; } - public int Top { get; } + public int Bottom { init; get; } + public double Confidence { init; get; } + public int Left { init; get; } + public int? NormalizedPixelPercentage { init; get; } + public int Right { init; get; } + public int Top { init; get; } } \ No newline at end of file diff --git a/Shared/Models/Stateless/ILocation.cs b/Shared/Models/Stateless/ILocation.cs index 8051d28..55e1e96 100644 --- a/Shared/Models/Stateless/ILocation.cs +++ b/Shared/Models/Stateless/ILocation.cs @@ -3,7 +3,7 @@ public interface ILocation { - const int Digits = 6; - const int Factor = 1000000; + const int Digits = 9; + const int Factor = 10000; } \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/Face.cs b/Shared/Models/Stateless/Methods/Face.cs index b77f851..6958b7d 100644 --- a/Shared/Models/Stateless/Methods/Face.cs +++ b/Shared/Models/Stateless/Methods/Face.cs @@ -28,21 +28,6 @@ internal abstract class Face return result; } - internal static List GetVerifiedFaces(int locationDigits, int locationFactor, List faces) - { - List results = new(); - foreach (Models.Face face in faces) - { - if (face.Location?.NormalizedPixelPercentage is null) - results.Add(face); - else if (face.Location.NormalizedPixelPercentage.ToString() == ILocation.GetRightPadded(locationDigits, face.Location.NormalizedPixelPercentage.Value)) - results.Add(face); - else - results.Add(new(face, face.Location, locationDigits, locationFactor, faces.Count)); - } - return results; - } - private static JsonElement[] GetJsonElements(string jsonFileFullName) { string json = GetJson(jsonFileFullName); diff --git a/Shared/Models/Stateless/Methods/IFace.cs b/Shared/Models/Stateless/Methods/IFace.cs index 1f3ebbb..5274e26 100644 --- a/Shared/Models/Stateless/Methods/IFace.cs +++ b/Shared/Models/Stateless/Methods/IFace.cs @@ -18,11 +18,6 @@ public interface IFace static Models.Face GetFace(string jsonFileFullName) => Face.GetFace(jsonFileFullName); - List TestStatic_GetVerifiedFaces(int locationDigits, int locationFactor, List faces) => - GetVerifiedFaces(locationDigits, locationFactor, faces); - static List GetVerifiedFaces(int locationDigits, int locationFactor, List faces) => - Face.GetVerifiedFaces(locationDigits, locationFactor, faces); - Models.Face[] TestStatic_GetFaces(string jsonFileFullName) => GetFaces(jsonFileFullName); static Models.Face[] GetFaces(string jsonFileFullName) => diff --git a/Shared/Models/Stateless/Methods/ILocation.cs b/Shared/Models/Stateless/Methods/ILocation.cs index 5244d46..727586f 100644 --- a/Shared/Models/Stateless/Methods/ILocation.cs +++ b/Shared/Models/Stateless/Methods/ILocation.cs @@ -3,15 +3,15 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods; public interface ILocation { // ... - string TestStatic_GetRightPadded(int locationDigits, string value) => - GetRightPadded(locationDigits, value); - static string GetRightPadded(int locationDigits, string value) => - value.Length == locationDigits ? value : value.Length > locationDigits ? value[..locationDigits] : value.PadRight(locationDigits, '0'); + string TestStatic_GetLeftPadded(int locationDigits, string value) => + GetLeftPadded(locationDigits, value); + static string GetLeftPadded(int locationDigits, string value) => + value.Length == locationDigits ? value : value.Length > locationDigits ? value[..locationDigits] : value.PadLeft(locationDigits, '0'); - string TestStatic_GetRightPadded(int locationDigits, int value) => - GetRightPadded(locationDigits, value); - static string GetRightPadded(int locationDigits, int value) => - GetRightPadded(locationDigits, value.ToString()); + string TestStatic_GetLeftPadded(int locationDigits, int value) => + GetLeftPadded(locationDigits, value); + static string GetLeftPadded(int locationDigits, int value) => + GetLeftPadded(locationDigits, value.ToString()); Models.Location? TestStatic_GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) => GetLocation(location, locationDigits, locationFactor, height, width, zCount); @@ -19,7 +19,7 @@ public interface ILocation location is null ? null : new(location.Confidence, height, location, locationDigits, locationFactor, width, zCount); Models.Location? TestStatic_GetLocation(int factor, Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) => - GetLocation(location, locationDigits, locationFactor, height, width, zCount); + GetLocation(factor, location, locationDigits, locationFactor, height, width, zCount); static Models.Location? GetLocation(int factor, Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) => location is null ? null : new(location.Confidence, factor, height, location, locationDigits, locationFactor, width, zCount); @@ -28,10 +28,15 @@ public interface ILocation static int?[] GetInts(List locations) => (from l in locations where l.NormalizedPixelPercentage is not null select l.NormalizedPixelPercentage).ToArray(); - int TestStatic_GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) => - GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount); - static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) => - Location.GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount); + int TestStatic_GetNormalizedPixelPercentage(Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution) => + GetNormalizedPixelPercentage(location, locationDigits, locationFactor, outputResolution); + static int GetNormalizedPixelPercentage(Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution) => + Location.GetNormalizedPixelPercentage(location.Bottom, outputResolution.Height, location.Left, locationDigits, locationFactor, location.Right, location.Top, outputResolution.Width, zCount: 1); + + int TestStatic_GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width) => + GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width); + static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width) => + Location.GetNormalizedPixelPercentage(bottom, height, left, locationDigits, locationFactor, right, top, width, zCount: 1); Models.Location TestStatic_GetTrimBound(double detectionConfidence, System.Drawing.Rectangle rectangle, int width, int height, int facesCount) => TrimBound(detectionConfidence, rectangle, width, height, facesCount); diff --git a/Shared/Models/Stateless/Methods/IMapping.cs b/Shared/Models/Stateless/Methods/IMapping.cs index 46599f6..19444bf 100644 --- a/Shared/Models/Stateless/Methods/IMapping.cs +++ b/Shared/Models/Stateless/Methods/IMapping.cs @@ -3,8 +3,8 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods; public interface IMapping { // ... - static string GetDeterministicHashCodeKey(int id, int normalizedPixelPercentage) - => $"{id}.{normalizedPixelPercentage}"; + static string GetDeterministicHashCodeKey(int id, int pixel) + => $"{id}.{pixel}"; (string?, string?, string?, bool?) TestStatic_GetSegments(int locationDigits, string facesFileNameExtension, string fileName) => GetSegments(locationDigits, facesFileNameExtension, fileName); @@ -16,9 +16,9 @@ public interface IMapping static (int?, int?, List?) GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, string file) => Mapping.GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, false, new(), file); - (int?, int?, List?) TestStatic_GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, bool keyValuePairsAny, Dictionary> keyValuePairs, string file) => - GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, keyValuePairsAny, keyValuePairs, file); - static (int?, int?, List?) GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, bool keyValuePairsAny, Dictionary> keyValuePairs, string file) => - Mapping.GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, keyValuePairsAny, keyValuePairs, file); + (int?, int?, List?) TestStatic_GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, bool idToFacesAny, Dictionary> idToFaces, string file) => + GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, idToFacesAny, idToFaces, file); + static (int?, int?, List?) GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, bool idToFacesAny, Dictionary> idToFaces, string file) => + Mapping.GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, idToFacesAny, idToFaces, file); } \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/Location.cs b/Shared/Models/Stateless/Methods/Location.cs index ab0872d..224eb21 100644 --- a/Shared/Models/Stateless/Methods/Location.cs +++ b/Shared/Models/Stateless/Methods/Location.cs @@ -3,25 +3,6 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods; internal abstract class Location { - internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) - { - int result; - double value; - double total = width * height; - Check(bottom, left, right, top, zCount); - double xCenter = left + ((right - left) / 2); - double yCenter = top + ((bottom - top) / 2); - double at = ((yCenter - 1) * width) + xCenter; - value = at / total; - if (value < 0) - value = 3; - result = (int)(Math.Round(value, locationDigits) * locationFactor); - string rightPadded = ILocation.GetRightPadded(locationDigits, result); - if (result.ToString() != rightPadded) - result = int.Parse(rightPadded); - return result; - } - internal static void Check(int bottom, int left, int right, int top, int zCount) { if (left < 0) @@ -69,4 +50,41 @@ internal abstract class Location throw new Exception(); } + internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount) + { + int result; + int checksum; + decimal center = 2m; + string xCenterPadded; + string yCenterPadded; + decimal factor = locationFactor; + // int.MaxPercentage = 21 4748 3647; + int length = (locationDigits - 1) / 2; + Check(bottom, left, right, top, zCount); + Check(bottom, height, left, right, top, width, zCount); + decimal xCenterValue = left + ((right - left) / center); + decimal yCenterValue = top + ((bottom - top) / center); + if (xCenterValue > yCenterValue) + checksum = 1; + else + checksum = 2; + decimal xCenterPercentageFactored = xCenterValue / width * factor; + decimal yCenterPercentageFactored = yCenterValue / height * factor; + int xCenterRounded = (int)Math.Round(xCenterPercentageFactored, 0); + int yCenterRounded = (int)Math.Round(yCenterPercentageFactored, 0); + if (xCenterRounded != factor) + xCenterPadded = ILocation.GetLeftPadded(length, xCenterRounded); + else + xCenterPadded = ILocation.GetLeftPadded(length, xCenterRounded - 1); + if (yCenterRounded != factor) + yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded); + else + yCenterPadded = ILocation.GetLeftPadded(length, yCenterRounded - 1); + long check = long.Parse(string.Concat(xCenterPadded, yCenterPadded, checksum)); + if (check > int.MaxValue) + throw new Exception(); + result = (int)check; + return result; + } + } \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/Mapping.cs b/Shared/Models/Stateless/Methods/Mapping.cs index 40bc5ad..012f29e 100644 --- a/Shared/Models/Stateless/Methods/Mapping.cs +++ b/Shared/Models/Stateless/Methods/Mapping.cs @@ -3,48 +3,6 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods; internal abstract class Mapping { - private static void IfNotAlreadyFileMove(string facesFileNameExtension, string file, int idValue, int normalizedPixelPercentageValue, string extensionLowered) - { - string? directoryName = Path.GetDirectoryName(file); - if (string.IsNullOrEmpty(directoryName)) - throw new Exception(); - string checkFile = Path.Combine(directoryName, $"{IMapping.GetDeterministicHashCodeKey(idValue, normalizedPixelPercentageValue)}{extensionLowered}{facesFileNameExtension}"); - if (!File.Exists(checkFile)) - File.Move(file, checkFile); - } - - private static (int?, int?, List?) GetReversedDeterministicHashCodeKeysFromSegments(int locationDigits, string facesFileNameExtension, bool keyValuePairsAny, Dictionary> keyValuePairs, string file, string fileName) - { - int? id; - List? faces; - int? normalizedPixelPercentage; - (string? Id, string? NormalizedPixelPercentage, string? ExtensionLowered, bool? Check) segments = GetSegments(locationDigits, facesFileNameExtension, fileName); - if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.NormalizedPixelPercentage) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null) - { - id = null; - faces = null; - normalizedPixelPercentage = null; - } - else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(ILocation.GetRightPadded(locationDigits, segments.NormalizedPixelPercentage), out int normalizedPixelPercentageValue)) - { - id = null; - faces = null; - normalizedPixelPercentage = null; - } - else - { - id = idValue; - normalizedPixelPercentage = normalizedPixelPercentageValue; - if (segments.Check.Value || segments.NormalizedPixelPercentage.Length != locationDigits) - IfNotAlreadyFileMove(facesFileNameExtension, file, idValue, normalizedPixelPercentageValue, segments.ExtensionLowered); - if (!keyValuePairsAny || !keyValuePairs.ContainsKey(idValue)) - faces = null; - else - faces = keyValuePairs[idValue]; - } - return new(id, normalizedPixelPercentage, faces); - } - internal static (string?, string?, string?, bool?) GetSegments(int locationDigits, string facesFileNameExtension, string fileName) { string[] segments = fileName.Split('.'); @@ -52,7 +10,7 @@ internal abstract class Mapping string? extensionLowered; bool? needsFacesFileNameExtension; string? normalizedPixelPercentage; - if (segments.Length < 3 || (segments.Length == 4 && $".{segments[3]}" != facesFileNameExtension)) + if (segments.Length < 4 || $".{segments[3]}" != facesFileNameExtension) { id = null; extensionLowered = null; @@ -64,12 +22,42 @@ internal abstract class Mapping id = segments[0]; extensionLowered = $".{segments[2]}"; needsFacesFileNameExtension = segments.Length == 3; - normalizedPixelPercentage = ILocation.GetRightPadded(locationDigits, segments[1]); + normalizedPixelPercentage = segments[1].Length == locationDigits ? segments[1] : null; } return new(id, normalizedPixelPercentage, extensionLowered, needsFacesFileNameExtension); } - internal static (int?, int?, List?) GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, bool keyValuePairsAny, Dictionary> keyValuePairs, string file) + private static (int?, int?, List?) GetReversedDeterministicHashCodeKeysFromSegments(int locationDigits, string facesFileNameExtension, bool idToFacesAny, Dictionary> idToFaces, string fileName) + { + int? id; + List? faces; + int? normalizedPixelPercentage; + (string? Id, string? NormalizedPixelPercentage, string? ExtensionLowered, bool? Check) segments = GetSegments(locationDigits, facesFileNameExtension, fileName); + if (string.IsNullOrEmpty(segments.Id) || string.IsNullOrEmpty(segments.NormalizedPixelPercentage) || string.IsNullOrEmpty(segments.ExtensionLowered) || segments.Check is null) + { + id = null; + faces = null; + normalizedPixelPercentage = null; + } + else if (!int.TryParse(segments.Id, out int idValue) || !int.TryParse(segments.NormalizedPixelPercentage, out int normalizedPixelPercentageValue)) + { + id = null; + faces = null; + normalizedPixelPercentage = null; + } + else + { + id = idValue; + normalizedPixelPercentage = segments.NormalizedPixelPercentage.Length == locationDigits ? normalizedPixelPercentageValue : null; + if (!idToFacesAny || !idToFaces.ContainsKey(idValue)) + faces = null; + else + faces = idToFaces[idValue]; + } + return new(id, normalizedPixelPercentage, faces); + } + + internal static (int?, int?, List?) GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, bool idToFacesAny, Dictionary> idToFaces, string file) { int? id; List? faces; @@ -85,9 +73,8 @@ internal abstract class Mapping (id, normalizedPixelPercentage, faces) = GetReversedDeterministicHashCodeKeysFromSegments( locationDigits, facesFileNameExtension, - keyValuePairsAny, - keyValuePairs, - file, + idToFacesAny, + idToFaces, fileName); return new(id, normalizedPixelPercentage, faces); } diff --git a/Tests/UnitTestCalculations.cs b/Tests/UnitTestCalculations.cs index 6ba5bb3..c3d5979 100644 --- a/Tests/UnitTestCalculations.cs +++ b/Tests/UnitTestCalculations.cs @@ -5,6 +5,7 @@ using Phares.Shared; using Serilog; using System.Diagnostics; using System.Reflection; +using View_by_Distance.Shared.Models; using View_by_Distance.Shared.Models.Stateless.Methods; using View_by_Distance.Tests.Models; @@ -75,33 +76,12 @@ public class UnitTestCalculations [TestMethod] public void TestMethodGetAge() { - Shared.Models.PersonBirthday personBirthday = new(new(1980, 1, 17)); + PersonBirthday personBirthday = new(new(1980, 1, 17)); double? age = IPersonBirthday.GetAge(personBirthday); Assert.IsNotNull(age); Assert.IsTrue(age.Value > 42.6092); } - [TestMethod] - public void TestMethodRound() - { - Assert.IsTrue(Shared.Models.Stateless.ILocation.Digits == 6); - Assert.IsTrue(Shared.Models.Stateless.ILocation.Factor == 1000000); - double valueA = 0.00001d; - int checkA = (int)(Math.Round(valueA, Shared.Models.Stateless.ILocation.Digits) * Shared.Models.Stateless.ILocation.Factor); - Assert.IsTrue(checkA == 10); - double valueB = 0.01d; - int checkB = (int)(Math.Round(valueB, Shared.Models.Stateless.ILocation.Digits) * Shared.Models.Stateless.ILocation.Factor); - Assert.IsTrue(checkB == 10000); - Assert.IsTrue(checkB > checkA); - double valueC = 0.06673685709635417; - int checkC = (int)(Math.Round(valueC, Shared.Models.Stateless.ILocation.Digits) * Shared.Models.Stateless.ILocation.Factor); - string rightPadded = ILocation.GetRightPadded(Shared.Models.Stateless.ILocation.Digits, checkC); - Assert.IsTrue(checkC == 66737); - Assert.IsTrue(checkC.ToString() != rightPadded); - checkC = int.Parse(rightPadded); - Assert.IsTrue(checkC == 667370); - } - [TestMethod] public void TestMethodParse() { @@ -130,6 +110,43 @@ public class UnitTestCalculations Assert.IsTrue(successfull == "_ Manual Copy Successfull"); } + [TestMethod] + public void TestMethodDamn() + { + string name; + string[] directories; + string? directoryName; + string checkDirectory; + string sourceDirectory = @"F:\Tmp\Phares\Compare\Images 2022-09-15 - 7390c13 - III - Results\E) Distance\2022-09-15\7680 x 4320\7680x4320 - Hog - Large\()"; + directories = Directory.GetDirectories(sourceDirectory, "*", SearchOption.TopDirectoryOnly); + foreach (string directory in directories) + { + directoryName = Path.GetDirectoryName(directory); + if (directoryName is null) + continue; + name = Path.GetFileName(directory); + if (name.Length is 1 or 20) + continue; + checkDirectory = Path.Combine(directoryName, "b", name); + Directory.Move(directory, checkDirectory); + } + directories = Directory.GetDirectories(Path.Combine(sourceDirectory, "b"), "*", SearchOption.TopDirectoryOnly); + foreach (string directory in directories) + { + directoryName = Path.GetDirectoryName(directory); + if (directoryName is null) + continue; + name = Path.GetFileName(directory); + if (name.Length is 1 or 20) + continue; + checkDirectory = Path.Combine(directoryName, $"{name[..^4]})"); + if (Directory.Exists(checkDirectory)) + continue; + Directory.Move(directory, checkDirectory); + } + Assert.IsTrue(true); + } + [TestMethod] public void TestMethodDel() { @@ -170,4 +187,118 @@ public class UnitTestCalculations // "()" } + [TestMethod] + public void TestGetLocation() + { + double confidence = 0.1D; + int left, top, right, bottom, width, height; + left = 20; + top = 40; + right = 60; + bottom = 80; + width = 100; + height = 100; + Location location = new(bottom, confidence, left, null, right, top); + _ = new Location(confidence, height, location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, width, 1); + _ = new Location(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); + } + + [TestMethod] + public void TestGetPixelPercentage() + { + int normalizedPixelPercentage; + int bottom, height, left, right, top, width; + left = 1; + top = 1; + right = 10; + bottom = 10; + width = 100; + height = 100; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 055005502); + left = 50; + top = 50; + right = 60; + bottom = 60; + width = 100; + height = 100; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 550055002); + } + + [TestMethod] + public void TestGetPixelPercentageB() + { + int normalizedPixelPercentage; + int bottom, height, left, right, top, width; + left = 240; + top = 240; + right = 260; + bottom = 260; + width = 500; + height = 500; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 500050002); + left = 490; + top = 490; + right = 510; + bottom = 510; + width = 1000; + height = 1000; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 500050002); + left++; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 500550001); + left++; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 501050001); + } + + [TestMethod] + public void TestGetPixelPercentageC() + { + int normalizedPixelPercentage; + int bottom, height, left, right, top, width; + left = 20; + top = 40; + right = 60; + bottom = 80; + width = 100; + height = 100; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 400060002); + left = 20; + top = 40; + right = 60; + bottom = 80; + width = 100; + height = 100; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 400060002); + } + + [TestMethod] + public void TestGetPixelPercentageD() + { + int normalizedPixelPercentage; + int bottom, height, left, right, top, width; + left = 7678; + top = 4318; + right = 7680; + bottom = 4320; + width = 7680; + height = 4320; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 999999981); + left = 7680; + top = 4320; + right = 7680; + bottom = 4320; + width = 7680; + height = 4320; + normalizedPixelPercentage = ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width); + Assert.IsTrue(normalizedPixelPercentage == 999999991); + } + } \ No newline at end of file diff --git a/Tests/UnitTestResize.cs b/Tests/UnitTestResize.cs index 8a7d9b9..2138bf3 100644 --- a/Tests/UnitTestResize.cs +++ b/Tests/UnitTestResize.cs @@ -73,91 +73,6 @@ public class UnitTestResize Assert.IsFalse(_PropertyConfiguration is null); } - [TestMethod] - public void TestGetLocation() - { - double confidence = 0.1D; - int left, top, right, bottom, width, height; - left = 20; - top = 40; - right = 60; - bottom = 80; - width = 100; - height = 100; - Location location = new(bottom, confidence, left, null, right, top); - _ = new Location(confidence, height, location, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, width, 1); - _ = new Location(bottom, confidence, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); - } - - [TestMethod] - public void TestGetPixelPercentage() - { - int normalizedPixelPercentage; - int left, top, right, bottom, width, height; - left = 1; - top = 1; - right = 10; - bottom = 10; - width = 100; - height = 100; - normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); - Assert.IsTrue(normalizedPixelPercentage == 40500); - left = 50; - top = 50; - right = 60; - bottom = 60; - width = 100; - height = 100; - normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); - Assert.IsTrue(normalizedPixelPercentage == 545500); - } - - [TestMethod] - public void TestGetPixelPercentageB() - { - int normalizedPixelPercentage; - int left, top, right, bottom, width, height; - left = 240; - top = 240; - right = 260; - bottom = 260; - width = 500; - height = 500; - normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); - Assert.IsTrue(normalizedPixelPercentage == 499000); - left = 490; - top = 490; - right = 510; - bottom = 510; - width = 1000; - height = 1000; - normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); - Assert.IsTrue(normalizedPixelPercentage == 499500); - } - - [TestMethod] - public void TestGetPixelPercentageC() - { - int normalizedPixelPercentage; - int left, top, right, bottom, width, height; - left = 20; - top = 40; - right = 60; - bottom = 80; - width = 100; - height = 100; - normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 1); - Assert.IsTrue(normalizedPixelPercentage == 594000); - left = 20; - top = 40; - right = 60; - bottom = 80; - width = 100; - height = 100; - normalizedPixelPercentage = Shared.Models.Stateless.Methods.ILocation.GetNormalizedPixelPercentage(bottom, height, left, Shared.Models.Stateless.ILocation.Digits, Shared.Models.Stateless.ILocation.Factor, right, top, width, 10); - Assert.IsTrue(normalizedPixelPercentage == 594000); - } - private Property.Models.A_Property GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel) { Property.Models.A_Property result; diff --git a/TestsWithFaceRecognitionDotNet/Models/Binder/Configuration.cs b/TestsWithFaceRecognitionDotNet/Models/Binder/Configuration.cs index 80988a7..0cc0afc 100644 --- a/TestsWithFaceRecognitionDotNet/Models/Binder/Configuration.cs +++ b/TestsWithFaceRecognitionDotNet/Models/Binder/Configuration.cs @@ -34,7 +34,6 @@ public class Configuration [Display(Name = "Mapped Max Index"), Required] public int? MappedMaxIndex { get; set; } [Display(Name = "Mapping Default Name"), Required] public string MappingDefaultName { get; set; } [Display(Name = "Mapping Move Unable to Match by 1 Tick"), Required] public bool? MappingMoveUnableToMatch { get; set; } - [Display(Name = "Mapping Save Face Encoding"), Required] public bool? MappingSaveFaceEncoding { get; set; } [Display(Name = "Mapping Save Mapped"), Required] public bool? MappingSaveMapped { get; set; } [Display(Name = "Mapping Save Not Mapped"), Required] public bool? MappingSaveNotMapped { get; set; } [Display(Name = "Mapping Use Deterministic Hash Code Unknown Face Key Value Pairs for Add to Mapping"), Required] public bool? MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { get; set; } @@ -69,8 +68,6 @@ public class Configuration [Display(Name = "Save Shortcuts"), Required] public string[] SaveShortcutsForOutputResolutions { get; set; } [Display(Name = "Skip Search"), Required] public bool? SkipSearch { get; set; } [Display(Name = "Sorting Days Delta Tolerance"), Required] public int? SortingDaysDeltaTolerance { get; set; } - [Display(Name = "Sorting Faces To Skip After Sort Before Load"), Required] public int? SortingFacesToSkipAfterSortBeforeLoad { get; set; } - [Display(Name = "Sorting Faces To Take After Sort Before Load"), Required] public int? SortingFacesToTakeAfterSortBeforeLoad { get; set; } [Display(Name = "SortingMaximumPerFaceShould be High"), Required] public int? SortingMaximumPerFaceShouldBeHigh { get; set; } [Display(Name = "Sorting Maximum Per Key"), Required] public int? SortingMaximumPerKey { get; set; } [Display(Name = "Sorting Sigma"), Required] public int? SortingSigma { get; set; } @@ -132,8 +129,6 @@ public class Configuration throw new NullReferenceException(nameof(configuration.MappingDefaultName)); if (configuration.MappingMoveUnableToMatch is null) throw new NullReferenceException(nameof(configuration.MappingMoveUnableToMatch)); - if (configuration.MappingSaveFaceEncoding is null) - throw new NullReferenceException(nameof(configuration.MappingSaveFaceEncoding)); if (configuration.MappingSaveNotMapped is null) throw new NullReferenceException(nameof(configuration.MappingSaveNotMapped)); if (configuration.MappingSaveMapped is null) @@ -194,10 +189,6 @@ public class Configuration throw new NullReferenceException(nameof(configuration.SkipSearch)); if (configuration.SortingDaysDeltaTolerance is null) throw new NullReferenceException(nameof(configuration.SortingDaysDeltaTolerance)); - if (configuration.SortingFacesToSkipAfterSortBeforeLoad is null) - throw new NullReferenceException(nameof(configuration.SortingFacesToSkipAfterSortBeforeLoad)); - if (configuration.SortingFacesToTakeAfterSortBeforeLoad is null) - throw new NullReferenceException(nameof(configuration.SortingFacesToTakeAfterSortBeforeLoad)); if (configuration.SortingMaximumPerFaceShouldBeHigh is null) throw new NullReferenceException(nameof(configuration.SortingMaximumPerFaceShouldBeHigh)); if (configuration.SortingMaximumPerKey is null) @@ -241,7 +232,6 @@ public class Configuration configuration.MappedMaxIndex, configuration.MappingDefaultName, configuration.MappingMoveUnableToMatch.Value, - configuration.MappingSaveFaceEncoding.Value, configuration.MappingSaveNotMapped.Value, configuration.MappingSaveMapped.Value, configuration.MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping.Value, @@ -275,8 +265,6 @@ public class Configuration configuration.SaveShortcutsForOutputResolutions, configuration.SkipSearch.Value, configuration.SortingDaysDeltaTolerance.Value, - configuration.SortingFacesToSkipAfterSortBeforeLoad.Value, - configuration.SortingFacesToTakeAfterSortBeforeLoad.Value, configuration.SortingMaximumPerFaceShouldBeHigh.Value, configuration.SortingMaximumPerKey.Value, configuration.SortingSigma.Value, diff --git a/TestsWithFaceRecognitionDotNet/Models/Configuration.cs b/TestsWithFaceRecognitionDotNet/Models/Configuration.cs index 145e94c..d649e79 100644 --- a/TestsWithFaceRecognitionDotNet/Models/Configuration.cs +++ b/TestsWithFaceRecognitionDotNet/Models/Configuration.cs @@ -33,7 +33,6 @@ public class Configuration public int? MappedMaxIndex { init; get; } public string MappingDefaultName { init; get; } public bool MappingMoveUnableToMatch { init; get; } - public bool MappingSaveFaceEncoding { init; get; } public bool MappingSaveNotMapped { init; get; } public bool MappingSaveMapped { init; get; } public bool MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping { init; get; } @@ -67,8 +66,6 @@ public class Configuration public string[] SaveShortcutsForOutputResolutions { init; get; } public bool SkipSearch { init; get; } public int SortingDaysDeltaTolerance { init; get; } - public int SortingFacesToSkipAfterSortBeforeLoad { init; get; } - public int SortingFacesToTakeAfterSortBeforeLoad { init; get; } public int SortingMaximumPerFaceShouldBeHigh { init; get; } public int SortingMaximumPerKey { init; get; } public int SortingSigma { init; get; } @@ -101,7 +98,6 @@ public class Configuration int? mappedMaxIndex, string mappingDefaultName, bool mappingMoveUnableToMatch, - bool mappingSaveFaceEncoding, bool mappingSaveNotMapped, bool mappingSaveMapped, bool mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping, @@ -135,8 +131,6 @@ public class Configuration string[] saveShortcutsForOutputResolutions, bool skipSearch, int sortingDaysDeltaTolerance, - int sortingFacesToSkipAfterSortBeforeLoad, - int sortingFacesToTakeAfterSortBeforeLoad, int sortingMaximumPerFaceShouldBeHigh, int sortingMaximumPerKey, int sortingSigma, @@ -168,7 +162,6 @@ public class Configuration MappedMaxIndex = mappedMaxIndex; MappingDefaultName = mappingDefaultName; MappingMoveUnableToMatch = mappingMoveUnableToMatch; - MappingSaveFaceEncoding = mappingSaveFaceEncoding; MappingSaveNotMapped = mappingSaveNotMapped; MappingSaveMapped = mappingSaveMapped; MappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping = mappingUseDeterministicHashCodeUnknownFaceKeyValuePairsForAddToMapping; @@ -202,8 +195,6 @@ public class Configuration SaveShortcutsForOutputResolutions = saveShortcutsForOutputResolutions; SkipSearch = skipSearch; SortingDaysDeltaTolerance = sortingDaysDeltaTolerance; - SortingFacesToSkipAfterSortBeforeLoad = sortingFacesToSkipAfterSortBeforeLoad; - SortingFacesToTakeAfterSortBeforeLoad = sortingFacesToTakeAfterSortBeforeLoad; SortingMaximumPerFaceShouldBeHigh = sortingMaximumPerFaceShouldBeHigh; SortingMaximumPerKey = sortingMaximumPerKey; SortingSigma = sortingSigma;