Change to support 7680 x 4320 and
Configuration additions
This commit is contained in:
@ -34,14 +34,14 @@ public class MappingFromLocation : Properties.IMappingFromLocation
|
||||
{
|
||||
|
||||
public double Confidence { init; get; }
|
||||
public string DeterministicHashCodeKeyDisplay { init; get; }
|
||||
public string DeterministicHashCodeKey { init; get; }
|
||||
public int NormalizedPixelPercentage { init; get; }
|
||||
|
||||
[JsonConstructor]
|
||||
public MappingFromLocation(double confidence, string deterministicHashCodeKeyDisplay, int normalizedPixelPercentage)
|
||||
{
|
||||
Confidence = confidence;
|
||||
DeterministicHashCodeKeyDisplay = deterministicHashCodeKeyDisplay;
|
||||
DeterministicHashCodeKey = deterministicHashCodeKeyDisplay;
|
||||
NormalizedPixelPercentage = normalizedPixelPercentage;
|
||||
}
|
||||
|
||||
|
8
Shared/Models/Methods/IFaceDistance.cs
Normal file
8
Shared/Models/Methods/IFaceDistance.cs
Normal file
@ -0,0 +1,8 @@
|
||||
namespace View_by_Distance.Shared.Models.Methods;
|
||||
|
||||
public interface IFaceDistance
|
||||
{
|
||||
|
||||
List<Face> GetMatchingFaces(double faceDistanceTolerance, string checkFile, List<Face> faces);
|
||||
|
||||
}
|
@ -15,7 +15,7 @@ public interface IMappingFromLocation
|
||||
{
|
||||
|
||||
public double Confidence { init; get; }
|
||||
public string DeterministicHashCodeKeyDisplay { init; get; }
|
||||
public string DeterministicHashCodeKey { init; get; }
|
||||
public int NormalizedPixelPercentage { init; get; }
|
||||
|
||||
}
|
||||
|
@ -1,15 +0,0 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
public interface IFaceDistance
|
||||
{
|
||||
|
||||
const int HiddenImageFactor = 2;
|
||||
const int Permyriad = 10000;
|
||||
const double MinimumConfidence = 1.25d;
|
||||
const double Tolerance = 0.23d;
|
||||
|
||||
// (637987888254767613) Tolerance = 0.31d; MinimumConfidence = 0.80d; => 1003 in 20 minutes with 9 failures
|
||||
// (637987913910140924) Tolerance = 0.21d; MinimumConfidence = 0.95d; => 0254 in 04 minutes with 1 failures
|
||||
// (??????????????????) Tolerance = 0.23d; MinimumConfidence = 1.25d; => ____ in __ minutes with _ failures
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
public interface IMapping
|
||||
{
|
||||
|
||||
const bool SaveFaceEncoding = false;
|
||||
const bool SaveMapped = false;
|
||||
|
||||
}
|
@ -1,7 +0,0 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
public interface IPerson
|
||||
{
|
||||
const string KeyFormat = "yyyy-MM-dd_HH";
|
||||
|
||||
}
|
@ -1,9 +0,0 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
public interface IPersonBirthday
|
||||
{
|
||||
|
||||
const int FirstYear = 1500;
|
||||
const string Format = "yyyy-MM-dd_HH";
|
||||
|
||||
}
|
@ -1,16 +0,0 @@
|
||||
namespace View_by_Distance.Shared.Models.Stateless;
|
||||
|
||||
public interface ISorting
|
||||
{
|
||||
|
||||
const int DaysDeltaTolerance = 700;
|
||||
const int FacesToSkipAfterSortBeforeLoad = 0;
|
||||
const int FacesToTakeAfterSortBeforeLoad = 123000;
|
||||
const int ForceSingleImage = 3;
|
||||
const int Mapping = 1;
|
||||
const int MaximumPerFaceShouldBeHigh = 1000;
|
||||
const int MaximumPerKey = 27;
|
||||
const int Sigma = 3;
|
||||
const int Sorting = 2;
|
||||
|
||||
}
|
@ -23,4 +23,18 @@ public interface ILocation
|
||||
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);
|
||||
|
||||
Models.Location TestStatic_GetTrimBound(double detectionConfidence, System.Drawing.Rectangle rectangle, int width, int height, int facesCount) =>
|
||||
TrimBound(detectionConfidence, rectangle, width, height, facesCount);
|
||||
static Models.Location TrimBound(double detectionConfidence, System.Drawing.Rectangle rectangle, int width, int height, int facesCount) =>
|
||||
new(Math.Min(rectangle.Bottom, height),
|
||||
detectionConfidence,
|
||||
height,
|
||||
Math.Max(rectangle.Left, 0),
|
||||
Stateless.ILocation.Digits,
|
||||
Stateless.ILocation.Factor,
|
||||
Math.Min(rectangle.Right, width),
|
||||
Math.Max(rectangle.Top, 0),
|
||||
width,
|
||||
facesCount);
|
||||
|
||||
}
|
@ -3,15 +3,12 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
public interface IMapping
|
||||
{ // ...
|
||||
|
||||
static string GetDeterministicHashCodeKeyDisplay(int id, int normalizedPixelPercentage)
|
||||
static string GetDeterministicHashCodeKey(int id, int normalizedPixelPercentage)
|
||||
=> $"{id}.{normalizedPixelPercentage}";
|
||||
|
||||
static double GetDeterministicHashCodeKeyValue(int locationDigits, int id, int normalizedPixelPercentage)
|
||||
=> Math.Round(double.Parse($"{id}.{normalizedPixelPercentage}"), locationDigits);
|
||||
|
||||
(int?, int?) TestStatic_GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
|
||||
(int?, int?, List<Models.Face>?) TestStatic_GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
|
||||
GetReversedDeterministicHashCodeKey(locationDigits, keyValuePairsAny, keyValuePairs, file);
|
||||
static (int?, int?) GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
|
||||
static (int?, int?, List<Models.Face>?) GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file) =>
|
||||
Mapping.GetReversedDeterministicHashCodeKey(locationDigits, keyValuePairsAny, keyValuePairs, file);
|
||||
|
||||
}
|
@ -1,80 +1,68 @@
|
||||
using System.Text.Json;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
|
||||
internal abstract class Mapping
|
||||
{
|
||||
|
||||
private static void UseKeyValuePairsSaveFaceEncoding(int locationDigits, Dictionary<int, List<Models.Face>> keyValuePairs, string file, int id, int normalizedPixelPercentageValue, double deterministicHashCodeKey, string extensionLowered)
|
||||
private static void IfNotAlreadyFileMove(string file, int idValue, int normalizedPixelPercentageValue, string extensionLowered)
|
||||
{
|
||||
string json;
|
||||
string checkFile;
|
||||
string? directoryName;
|
||||
List<Models.Face> collection = new();
|
||||
List<Models.Face> faces = keyValuePairs[id];
|
||||
foreach (Models.Face face in faces)
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
continue;
|
||||
if (normalizedPixelPercentageValue != face.Location.NormalizedPixelPercentage.Value && deterministicHashCodeKey != IMapping.GetDeterministicHashCodeKeyValue(locationDigits, id, face.Location.NormalizedPixelPercentage.Value))
|
||||
continue;
|
||||
collection.Add(face);
|
||||
}
|
||||
if (collection.Count != 1)
|
||||
string? directoryName = Path.GetDirectoryName(file);
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
throw new Exception();
|
||||
foreach (Models.Face face in collection)
|
||||
{
|
||||
directoryName = Path.GetDirectoryName(file);
|
||||
if (string.IsNullOrEmpty(directoryName))
|
||||
continue;
|
||||
checkFile = Path.Combine(directoryName, $"{deterministicHashCodeKey}{extensionLowered}.json");
|
||||
if (File.Exists(checkFile))
|
||||
continue;
|
||||
json = JsonSerializer.Serialize(face.FaceEncoding);
|
||||
_ = IPath.WriteAllText(checkFile, json, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
}
|
||||
string checkFile = Path.Combine(directoryName, $"{IMapping.GetDeterministicHashCodeKey(idValue, normalizedPixelPercentageValue)}{extensionLowered}");
|
||||
if (!File.Exists(checkFile))
|
||||
File.Move(file, checkFile);
|
||||
}
|
||||
|
||||
private static (int?, int?, double?) GetReversedDeterministicHashCodeKeysFromSegments(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
|
||||
{
|
||||
double? result;
|
||||
if (segments.Length != 3)
|
||||
throw new Exception();
|
||||
string id = segments[0];
|
||||
int normalizedPixelPercentageValue;
|
||||
string normalizedPixelPercentage = segments[1];
|
||||
if (!int.TryParse(id, out int idValue) | !int.TryParse(normalizedPixelPercentage, out normalizedPixelPercentageValue))
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
result = IMapping.GetDeterministicHashCodeKeyValue(locationDigits, idValue, normalizedPixelPercentageValue);
|
||||
if (keyValuePairsAny && keyValuePairs.ContainsKey(idValue))
|
||||
UseKeyValuePairsSaveFaceEncoding(locationDigits, keyValuePairs, file, idValue, normalizedPixelPercentageValue, result.Value, $".{segments[2]}");
|
||||
}
|
||||
return new(idValue, normalizedPixelPercentageValue, result);
|
||||
}
|
||||
|
||||
internal static (int?, int?) GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
|
||||
private static (int?, int?, List<Models.Face>?) GetReversedDeterministicHashCodeKeysFromSegments(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file, string[] segments)
|
||||
{
|
||||
int? id;
|
||||
List<Models.Face>? faces;
|
||||
int? normalizedPixelPercentage;
|
||||
if (segments.Length != 3)
|
||||
{
|
||||
id = null;
|
||||
faces = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else if (!int.TryParse(segments[0], out int idValue) || !int.TryParse(segments[1].PadRight(locationDigits, '0'), out int normalizedPixelPercentageValue))
|
||||
{
|
||||
id = null;
|
||||
faces = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
id = idValue;
|
||||
string extensionLowered = $".{segments[2]}";
|
||||
normalizedPixelPercentage = normalizedPixelPercentageValue;
|
||||
if (segments[1].Length != locationDigits)
|
||||
IfNotAlreadyFileMove(file, idValue, normalizedPixelPercentageValue, extensionLowered);
|
||||
if (!keyValuePairsAny || !keyValuePairs.ContainsKey(idValue))
|
||||
faces = null;
|
||||
else
|
||||
faces = keyValuePairs[idValue];
|
||||
}
|
||||
return new(id, normalizedPixelPercentage, faces);
|
||||
}
|
||||
|
||||
internal static (int?, int?, List<Models.Face>?) GetReversedDeterministicHashCodeKey(int locationDigits, bool keyValuePairsAny, Dictionary<int, List<Models.Face>> keyValuePairs, string file)
|
||||
{
|
||||
int? id;
|
||||
List<Models.Face>? faces;
|
||||
int? normalizedPixelPercentage;
|
||||
string fileName = Path.GetFileName(file);
|
||||
if (fileName.Length < 2 || fileName[1..].Contains('-'))
|
||||
{
|
||||
id = null;
|
||||
faces = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
string[] segments = fileName.Split('.');
|
||||
(id, normalizedPixelPercentage, double? result) = GetReversedDeterministicHashCodeKeysFromSegments(locationDigits, keyValuePairsAny, keyValuePairs, file, segments);
|
||||
if (result is null)
|
||||
{
|
||||
id = null;
|
||||
normalizedPixelPercentage = null;
|
||||
}
|
||||
(id, normalizedPixelPercentage, faces) = GetReversedDeterministicHashCodeKeysFromSegments(locationDigits, keyValuePairsAny, keyValuePairs, file, segments);
|
||||
}
|
||||
return new(id, normalizedPixelPercentage);
|
||||
return new(id, normalizedPixelPercentage, faces);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user