PhotoPrism for more locations

This commit is contained in:
2022-12-25 13:54:17 -07:00
parent a510019c1d
commit 37c7b6760d
31 changed files with 395 additions and 509 deletions

View File

@ -189,4 +189,81 @@ internal abstract class Location
return result.Value;
}
private static bool Matches(Models.OutputResolution outputResolution, DatabaseFile databaseFile)
{
bool result = outputResolution.Height == databaseFile.FileHeight && outputResolution.Width == databaseFile.FileWidth;
return result;
}
internal static Rectangle? GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker)
{
Rectangle? result;
bool matches = Matches(outputResolution, databaseFile);
if (!matches)
result = null;
else
result = new((int)Math.Ceiling(marker.X * databaseFile.FileWidth), (int)Math.Ceiling(marker.Y * databaseFile.FileHeight), (int)Math.Ceiling(marker.W * databaseFile.FileWidth), (int)Math.Ceiling(marker.H * databaseFile.FileHeight));
return result;
}
internal static Models.Location? GetLocation(Marker marker, Rectangle rectangle)
{
Models.Location? result;
bool verified = Check(rectangle.Bottom, rectangle.Height, rectangle.Left, rectangle.Right, rectangle.Top, rectangle.Width, zCount: 1, throwException: false);
if (!verified)
result = null;
else
result = new(rectangle.Bottom, marker.Score / 100, rectangle.Left, rectangle.Right, rectangle.Top);
return result;
}
internal static Models.Location? GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker)
{
Models.Location? result;
Rectangle? rectangle = GetRectangle(outputResolution, databaseFile, marker);
if (rectangle is null)
result = null;
else
result = GetLocation(marker, rectangle.Value);
return result;
}
internal static List<Models.Location> GetLocations(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces)
{
List<Models.Location> results = new();
double percent;
Rectangle dlibRectangle;
Rectangle? prismRectangle;
Models.Location? location;
Rectangle intersectRectangle;
foreach (Models.Face face in faces)
{
if (face.Location is null || face.OutputResolution is null)
continue;
foreach (MappingFromPhotoPrism mappingFromPhotoPrism in mappingFromPhotoPrismCollection)
{
dlibRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top);
foreach (Marker marker in mappingFromPhotoPrism.Markers)
{
prismRectangle = GetRectangle(face.OutputResolution, mappingFromPhotoPrism.DatabaseFile, marker);
if (prismRectangle is null)
{
location = new(1, 0, 0, 1, 0);
results.Add(location);
continue;
}
location = GetLocation(marker, prismRectangle.Value);
if (location is null)
continue;
intersectRectangle = Rectangle.Intersect(dlibRectangle, prismRectangle.Value);
percent = (double)intersectRectangle.Width * intersectRectangle.Height / (dlibRectangle.Width * dlibRectangle.Height);
if (percent > 0.000001)
continue;
results.Add(location);
}
}
}
return results;
}
}