Get Unable to Match Count and Rename Matches

This commit is contained in:
2022-09-24 16:39:15 -07:00
parent e64c713926
commit 751a61529c
32 changed files with 983 additions and 668 deletions

View File

@ -12,7 +12,6 @@ public class Face : Properties.IFace
protected Dictionary<Stateless.FacePart, FacePoint[]>? _FaceParts;
protected readonly OutputResolution? _OutputResolution;
protected Location? _Location;
protected readonly int? _LocationIndex;
protected Mapping? _Mapping;
protected readonly string _RelativePath;
public DateTime DateTime => _DateTime;
@ -20,34 +19,32 @@ public class Face : Properties.IFace
public FaceEncoding? FaceEncoding => _FaceEncoding;
public Dictionary<Stateless.FacePart, FacePoint[]>? FaceParts => _FaceParts;
public Location? Location => _Location;
public int? LocationIndex => _LocationIndex;
public Mapping? Mapping => _Mapping;
public OutputResolution? OutputResolution => _OutputResolution;
public string RelativePath => _RelativePath;
[JsonConstructor]
public Face(DateTime dateTime, FaceDistance? faceDistance, FaceEncoding? faceEncoding, Dictionary<Stateless.FacePart, FacePoint[]>? faceParts, Location? location, int? locationIndex, Mapping? mapping, OutputResolution? outputResolution, string relativePath)
public Face(DateTime dateTime, FaceDistance? faceDistance, FaceEncoding? faceEncoding, Dictionary<Stateless.FacePart, FacePoint[]>? faceParts, Location? location, Mapping? mapping, OutputResolution? outputResolution, string relativePath)
{
_DateTime = dateTime;
_FaceDistance = faceDistance;
_FaceEncoding = faceEncoding;
_FaceParts = faceParts;
_Location = location;
_LocationIndex = locationIndex;
_Mapping = mapping;
_OutputResolution = outputResolution;
_RelativePath = relativePath;
}
public Face(int locationDigits, int locationFactor, int facesCount, Face face) :
this(face.DateTime, null, face.FaceEncoding, face.FaceParts, face.Location, face.LocationIndex, null, face.OutputResolution, face.RelativePath)
this(face.DateTime, null, face.FaceEncoding, face.FaceParts, face.Location, null, face.OutputResolution, face.RelativePath)
{
if (face.Location?.Confidence is not null && face.OutputResolution is not null)
_Location = new(face.Location.Confidence, face.OutputResolution.Height, face.Location, locationDigits, locationFactor, face.OutputResolution.Width, facesCount);
}
public Face(Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string relativePath, int? i, Location? location) :
this(DateTime.MinValue, null, null, null, location, i, null, null, relativePath)
public Face(Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string relativePath, Location? location) :
this(DateTime.MinValue, null, null, null, location, null, null, relativePath)
{
DateTime?[] dateTimes;
_OutputResolution = new(outputResolutionHeight, outputResolutionOrientation, outputResolutionWidth);
@ -56,7 +53,7 @@ public class Face : Properties.IFace
}
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)
this(face.DateTime, face.FaceDistance, face.FaceEncoding, face.FaceParts, new(height, location, locationDigits, locationFactor, width, zCount), face.Mapping, face.OutputResolution, face.RelativePath)
{ }
public override string ToString()
@ -73,6 +70,8 @@ public class Face : Properties.IFace
public void SetMapping(Mapping mapping) => _Mapping = mapping;
public void FaceDistanceAdd(FaceDistance faceDistance) => _FaceDistance = faceDistance;
public void SetFaceDistance(FaceDistance? faceDistance) => _FaceDistance = faceDistance;
public void ClearFaceDistance() => _FaceDistance = null;
}

View File

@ -122,16 +122,8 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem
string locationDisplayIndex;
int locationIndex;
long sourceSize;
if (face.LocationIndex is null)
{
locationIndex = 0;
locationDisplayIndex = "01";
}
else
{
locationIndex = face.LocationIndex.Value;
locationDisplayIndex = (face.LocationIndex.Value + 1).ToString("00");
}
locationIndex = 0;
locationDisplayIndex = "01";
if (face.Location is null)
{
faceTop = null;
@ -161,7 +153,7 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem
string faceRelativePath = string.Concat(requestPath, new Uri(faceFullFileName).AbsoluteUri[rootResultsDirectoryAbsoluteUriLength..]);
string sourceRelativePath = string.Concat(requestPath, new Uri(sourceFullFileName).AbsoluteUri[rootResultsDirectoryAbsoluteUriLength..]);
FileInfo fileInfo = new(sourceFullFileName);
if (face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null && !File.Exists(faceFullFileName))
if (face.FaceEncoding is not null && face.Location is not null && face.OutputResolution is not null && !File.Exists(faceFullFileName))
Stateless.Methods.IFaceFileSystem.SearchForMissingFile(faceFullFileName, fileInfo: new FileInfo(string.Empty), dataFullFileName);
if (fileInfo.Exists)
FileExists(face, faceBottom, faceRight, out imageHeight, out imageWidth, out sourceSize, fileInfo);
@ -180,8 +172,8 @@ public class FaceFileSystem : FileSystem, Properties.IFaceFileSystem
_LastModified = face.DateTime;
_FaceLeft = faceLeft;
_LocationDisplayIndex = locationDisplayIndex;
_LocationIndex = face.LocationIndex;
_Populated = face.FaceEncoding is not null && face.Location?.NormalizedPixelPercentage is not null;
_LocationIndex = null;
_Populated = face.FaceEncoding is not null && face.Location is not null && face.OutputResolution is not null;
_RelativePath = string.Empty;
_FaceRight = faceRight;
_SourceFullFileName = sourceFullFileName;

View File

@ -9,20 +9,18 @@ public class Location : Properties.ILocation, IEquatable<Location>
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)
public Location(int bottom, double confidence, int left, int right, int top)
{
Confidence = confidence;
Bottom = bottom;
Left = left;
NormalizedPixelPercentage = normalizedPixelPercentage;
Right = right;
Top = top;
Stateless.Methods.Location.Check(bottom, left, normalizedPixelPercentage, right, top, zCount: 1);
Stateless.Methods.Location.Check(bottom, left, right, top, zCount: 1);
}
public Location(double confidence, int height, Location location, int locationDigits, int locationFactor, int width, int zCount) :
@ -30,30 +28,27 @@ public class Location : Properties.ILocation, IEquatable<Location>
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);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, 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);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, 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);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount);
public Location(double confidence, int factor, int height, Location location, int locationDigits, int locationFactor, int width, int zCount)
{
@ -63,14 +58,10 @@ public class Location : Properties.ILocation, IEquatable<Location>
int left = Math.Max(location.Left - x, 0);
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);
if (location.NormalizedPixelPercentage is null || normalizedPixelPercentage != location.NormalizedPixelPercentage.Value)
throw new Exception();
Stateless.Methods.Location.Check(bottom, left, NormalizedPixelPercentage, right, top, zCount);
Stateless.Methods.Location.Check(Bottom, height, Left, Right, Top, width, zCount);
Confidence = confidence;
Bottom = bottom;
Left = left;
NormalizedPixelPercentage = normalizedPixelPercentage;
Right = right;
Top = top;
}

View File

@ -38,10 +38,10 @@ public class MappingFromLocation : Properties.IMappingFromLocation
public int NormalizedPixelPercentage { init; get; }
[JsonConstructor]
public MappingFromLocation(double confidence, string deterministicHashCodeKeyDisplay, int normalizedPixelPercentage)
public MappingFromLocation(double confidence, string deterministicHashCodeKey, int normalizedPixelPercentage)
{
Confidence = confidence;
DeterministicHashCodeKey = deterministicHashCodeKeyDisplay;
DeterministicHashCodeKey = deterministicHashCodeKey;
NormalizedPixelPercentage = normalizedPixelPercentage;
}

View File

@ -3,7 +3,6 @@ namespace View_by_Distance.Shared.Models.Methods;
public interface IFaceDistance
{
List<Face> GetMatchingFaces(double faceDistanceTolerance, string checkFile, List<Face> faces);
void SavePossiblyNewPersonContainers(Properties.IPropertyConfiguration propertyConfiguration, string personBirthdayFormat, string facesFileNameExtension, string a2PeopleContentDirectory, Dictionary<long, PersonContainer> personKeyToPersonContainer, List<(string[], PersonContainer)> possiblyNewPersonDisplayDirectoryNamesAndPersonContainer);
}

View File

@ -7,8 +7,6 @@ public interface IFace
public FaceDistance? FaceDistance { get; }
public FaceEncoding? FaceEncoding { get; }
public Dictionary<Stateless.FacePart, FacePoint[]>? FaceParts { get; }
public Location? Location { get; }
public int? LocationIndex { get; }
public Mapping? Mapping { get; }
public OutputResolution? OutputResolution { get; }
public string RelativePath { get; }

View File

@ -6,7 +6,6 @@ public interface ILocation
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; }

View File

@ -58,11 +58,7 @@ internal abstract class FaceFileSystem
{
if (face[i] is null)
continue;
locationIndex = face[i].LocationIndex;
if (locationIndex is null)
locationIndex = 0;
else
locationIndex = locationIndex.Value;
locationIndex = 0;
directoryName = Path.GetDirectoryName(face[i].RelativePath);
if (directoryName is null)
continue;

View File

@ -28,9 +28,4 @@ public interface IFace
static double? Getα(Dictionary<FacePart, Models.FacePoint[]> faceParts) =>
Face.Getα(faceParts);
int?[] TestStatic_GetInts(List<Models.Face> faces) =>
GetInts(faces);
static int?[] GetInts(List<Models.Face> faces) =>
(from l in faces where l.FaceEncoding is not null && l.Location?.NormalizedPixelPercentage is not null select l.Location?.NormalizedPixelPercentage).ToArray();
}

View File

@ -6,13 +6,18 @@ public interface ILocation
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');
Location.GetLeftPadded(locationDigits, value);
string TestStatic_GetLeftPadded(int locationDigits, int value) =>
GetLeftPadded(locationDigits, value);
static string GetLeftPadded(int locationDigits, int value) =>
GetLeftPadded(locationDigits, value.ToString());
(int?, int?) TestStatic_GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage) =>
GetXY(locationDigits, locationFactor, width, height, normalizedPixelPercentage);
static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage) =>
Location.GetXY(locationDigits, locationFactor, width, height, normalizedPixelPercentage);
Models.Location? TestStatic_GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
GetLocation(location, locationDigits, locationFactor, height, width, zCount);
static Models.Location? GetLocation(Models.Location? location, int locationDigits, int locationFactor, int height, int width, int zCount) =>
@ -23,11 +28,6 @@ public interface ILocation
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);
int?[] TestStatic_GetInts(List<Models.Location> locations) =>
GetInts(locations);
static int?[] GetInts(List<Models.Location> locations) =>
(from l in locations where l.NormalizedPixelPercentage is not null select l.NormalizedPixelPercentage).ToArray();
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) =>

View File

@ -3,14 +3,16 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
public interface IMapping
{ // ...
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);
static (string?, string?, string?, bool?) GetSegments(int locationDigits, string facesFileNameExtension, string fileName)
=> Mapping.GetSegments(locationDigits, facesFileNameExtension, fileName);
string TestStatic_GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution)
=> GetDeterministicHashCodeKey(id, location, locationDigits, locationFactor, outputResolution);
static string GetDeterministicHashCodeKey(int id, Models.Location location, int locationDigits, int locationFactor, OutputResolution outputResolution)
=> $"{id}.{ILocation.GetNormalizedPixelPercentage(location, locationDigits, locationFactor, outputResolution)}";
(int?, int?, List<Models.Face>?) TestStatic_GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, string file) =>
GetReversedDeterministicHashCodeKey(locationDigits, facesFileNameExtension, file);
static (int?, int?, List<Models.Face>?) GetReversedDeterministicHashCodeKey(int locationDigits, string facesFileNameExtension, string file) =>

View File

@ -33,26 +33,25 @@ internal abstract class Location
throw new Exception();
if (zCount < 0)
throw new Exception();
Check(bottom, left, right, top, zCount);
}
internal static void Check(int bottom, int left, int? normalizedPixelPercentage, int right, int top, int zCount)
internal static string GetLeftPadded(int locationDigits, string value)
{
Check(bottom, left, right, top, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
}
internal static void Check(int bottom, int height, int left, int? normalizedPixelPercentage, int right, int top, int width, int zCount)
{
Check(bottom, left, right, top, zCount);
Check(bottom, height, left, right, top, width, zCount);
if (normalizedPixelPercentage.HasValue && normalizedPixelPercentage.Value < 0)
throw new Exception();
string result;
if (value.Length == locationDigits)
result = value;
else if (value.Length > locationDigits)
result = value[..locationDigits];
else
result = value.PadLeft(locationDigits, '0');
return result;
}
internal static int GetNormalizedPixelPercentage(int bottom, int height, int left, int locationDigits, int locationFactor, int right, int top, int width, int zCount)
{
int result;
Check(bottom, height, left, right, top, width, zCount);
int checksum;
decimal center = 2m;
string xCenterPadded;
@ -60,10 +59,12 @@ internal abstract class Location
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);
decimal xCenterValue = (left + right) / center;
decimal yCenterValue = (top + bottom) / center;
if (xCenterValue < left || xCenterValue > right)
throw new Exception();
if (yCenterValue < top || yCenterValue > bottom)
throw new Exception();
if (xCenterValue > yCenterValue)
checksum = 1;
else
@ -87,4 +88,28 @@ internal abstract class Location
return result;
}
internal static (int?, int?) GetXY(int locationDigits, int locationFactor, int width, int height, string normalizedPixelPercentage)
{
int? x;
int? y;
int center = 2;
decimal factor = locationFactor;
int each = (locationDigits - 1) / center;
string segmentA = normalizedPixelPercentage[..each];
string segmentB = normalizedPixelPercentage[each..^1];
if (!int.TryParse(segmentA, out int xNormalized) || !int.TryParse(segmentB, out int yNormalized))
{
x = null;
y = null;
}
else
{
decimal xValue = xNormalized / factor * width;
decimal yValue = yNormalized / factor * height;
x = (int)Math.Round(xValue, 0);
y = (int)Math.Round(yValue, 0);
}
return new(x, y);
}
}

View File

@ -112,6 +112,7 @@ internal abstract class PersonBirthday
internal static List<Models.PersonBirthday> GetPersonBirthdays(string personBirthdayFormat, string[] personKeyDirectories, string personDisplayDirectory)
{
List<Models.PersonBirthday> results = new();
string[] files;
string personKeyFormatted;
Models.PersonBirthday? personBirthday;
foreach (string personKeyDirectory in personKeyDirectories)
@ -124,6 +125,10 @@ internal abstract class PersonBirthday
if (personBirthday is null)
continue;
results.Add(personBirthday);
files = Directory.GetFiles(personKeyDirectory, "*", SearchOption.TopDirectoryOnly);
if (files.Any())
continue;
File.WriteAllText(Path.Combine(personKeyDirectory, $"{personKeyFormatted}.txt"), string.Empty);
}
return results;
}