IgnoreExtensions-nef
Config-LoadPhotoPrismLocations TestMethodIntersect
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
using System.Drawing;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using View_by_Distance.Shared.Models;
|
||||
@ -139,14 +140,14 @@ public class F_PhotoPrism
|
||||
return results;
|
||||
}
|
||||
|
||||
private static void PopulateSubjects(string mappingDefaultName, string personBirthdayFormat, List<string> subjects, StringBuilder stringBuilder, PersonContainer[] personContainers, (MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)[] sortedCollection)
|
||||
private static void PopulateSubjects(string mappingDefaultName, string personBirthdayFormat, List<string> subjects, StringBuilder stringBuilder, PersonContainer[] personContainers, (MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, float Percent)[] sortedCollection)
|
||||
{
|
||||
long? personKey;
|
||||
string personName;
|
||||
const int zero = 0;
|
||||
string personKeyFormatted;
|
||||
PersonBirthday personBirthday;
|
||||
foreach ((MappingFromPhotoPrism mappingFromPhotoPrism, Shared.Models.Marker marker, double percent) in sortedCollection)
|
||||
foreach ((MappingFromPhotoPrism mappingFromPhotoPrism, Shared.Models.Marker marker, float percent) in sortedCollection)
|
||||
{
|
||||
foreach (PersonContainer personContainer in personContainers)
|
||||
{
|
||||
@ -173,18 +174,22 @@ public class F_PhotoPrism
|
||||
{
|
||||
string file;
|
||||
string text;
|
||||
double percent;
|
||||
float dlibArea;
|
||||
float? percent;
|
||||
string directory;
|
||||
int width, height;
|
||||
int? wholePercentages;
|
||||
RectangleF? prismRectangle;
|
||||
List<string> subjects = new();
|
||||
DateTime dateTime = new(ticks);
|
||||
int dlibLocationWholePercentages;
|
||||
PersonContainer[]? personContainers;
|
||||
StringBuilder stringBuilder = new();
|
||||
System.Drawing.Rectangle dlibRectangle;
|
||||
System.Drawing.Rectangle? prismRectangle;
|
||||
System.Drawing.Rectangle intersectRectangle;
|
||||
RectangleF? dlibPercentagesRectangle;
|
||||
float rectangleIntersectMinimum = rectangleIntersectMinimums.Min();
|
||||
Dictionary<int, PersonContainer[]>? wholePercentagesToPersonContainers;
|
||||
(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)[] sortedCollection;
|
||||
List<(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, double Percent)> collection = new();
|
||||
(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, float Percent)[] sortedCollection;
|
||||
List<(MappingFromPhotoPrism MappingFromPhotoPrism, Shared.Models.Marker Marker, float Percent)> collection = new();
|
||||
foreach (Face face in distinctFilteredFaces)
|
||||
{
|
||||
collection.Clear();
|
||||
@ -198,21 +203,23 @@ public class F_PhotoPrism
|
||||
(_, wholePercentagesToPersonContainers) = mapLogic.GetWholePercentagesToPersonContainers(face.Mapping.MappingFromItem.Id);
|
||||
if (wholePercentagesToPersonContainers is null || !wholePercentagesToPersonContainers.TryGetValue(wholePercentages.Value, out personContainers))
|
||||
continue;
|
||||
dlibRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top);
|
||||
(width, height) = IOutputResolution.Get(face.OutputResolution);
|
||||
dlibLocationWholePercentages = ILocation.GetWholePercentages(height, face.Location, Shared.Models.Stateless.ILocation.Digits, width);
|
||||
dlibPercentagesRectangle = ILocation.GetPercentagesRectangle(Shared.Models.Stateless.ILocation.Digits, dlibLocationWholePercentages);
|
||||
if (dlibPercentagesRectangle is null)
|
||||
continue;
|
||||
dlibArea = dlibPercentagesRectangle.Value.Width * dlibPercentagesRectangle.Value.Height;
|
||||
foreach (MappingFromPhotoPrism mappingFromPhotoPrism in face.Mapping.MappingFromPhotoPrismCollection)
|
||||
{
|
||||
foreach (Shared.Models.Marker marker in mappingFromPhotoPrism.Markers)
|
||||
{
|
||||
prismRectangle = ILocation.GetRectangle(mappingFromPhotoPrism.DatabaseFile, marker, face.OutputResolution);
|
||||
prismRectangle = ILocation.GetPercentagesRectangle(mappingFromPhotoPrism.DatabaseFile, marker, face.OutputResolution);
|
||||
if (prismRectangle is null)
|
||||
continue;
|
||||
intersectRectangle = System.Drawing.Rectangle.Intersect(dlibRectangle, prismRectangle.Value);
|
||||
if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0)
|
||||
percent = ILocation.GetIntersectPercent(dlibPercentagesRectangle.Value, dlibArea, prismRectangle.Value);
|
||||
if (percent is null || percent < rectangleIntersectMinimum)
|
||||
continue;
|
||||
percent = (double)intersectRectangle.Width * intersectRectangle.Height / (dlibRectangle.Width * dlibRectangle.Height);
|
||||
if (percent < rectangleIntersectMinimum)
|
||||
continue;
|
||||
collection.Add(new(mappingFromPhotoPrism, marker, percent));
|
||||
collection.Add(new(mappingFromPhotoPrism, marker, percent.Value));
|
||||
}
|
||||
}
|
||||
if (!collection.Any())
|
||||
@ -222,10 +229,13 @@ public class F_PhotoPrism
|
||||
}
|
||||
if (subjects.Any())
|
||||
{
|
||||
file = Path.Combine(fPhotoPrismContentDirectory, $"{ticks}-{rectangleIntersectMinimum}-subject_alias_update.sql");
|
||||
directory = Path.Combine(fPhotoPrismContentDirectory, dateTime.ToString("yyyy-MM-dd"));
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
file = Path.Combine(directory, $"{ticks}-{rectangleIntersectMinimum}-subject_alias_update.sql");
|
||||
text = string.Join(Environment.NewLine, subjects.Distinct());
|
||||
_ = IPath.WriteAllText(file, text, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
file = Path.Combine(fPhotoPrismContentDirectory, $"{ticks}-{rectangleIntersectMinimum}-marker_name_update.sql");
|
||||
file = Path.Combine(directory, $"{ticks}-{rectangleIntersectMinimum}-marker_name_update.sql");
|
||||
text = stringBuilder.ToString();
|
||||
_ = IPath.WriteAllText(file, text, updateDateWhenMatches: false, compareBeforeWrite: true, updateToWhenMatches: null);
|
||||
}
|
||||
|
Reference in New Issue
Block a user