PhotoPrism for more locations
This commit is contained in:
@ -5,6 +5,21 @@ namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
public interface ILocation
|
||||
{ // ...
|
||||
|
||||
Rectangle? TestStatic_GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
GetRectangle(outputResolution, databaseFile, marker);
|
||||
static Rectangle? GetRectangle(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
Location.GetRectangle(outputResolution, databaseFile, marker);
|
||||
|
||||
Models.Location? TestStatic_GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
GetLocation(outputResolution, databaseFile, marker);
|
||||
static Models.Location? GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker) =>
|
||||
Location.GetLocation(outputResolution, databaseFile, marker);
|
||||
|
||||
List<Models.Location> TestStatic_GetLocations(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces) =>
|
||||
GetLocations(mappingFromPhotoPrismCollection, faces);
|
||||
static List<Models.Location> GetLocations(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces) =>
|
||||
Location.GetLocations(mappingFromPhotoPrismCollection, faces);
|
||||
|
||||
Rectangle TestStatic_GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) =>
|
||||
GetRectangle(checkRectangle, locationDigits, locationFactor, normalizedRectangle, outputResolution, useOldWay);
|
||||
static Rectangle GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangle, Models.OutputResolution outputResolution, bool useOldWay) =>
|
||||
|
@ -17,6 +17,7 @@ public interface IPath
|
||||
DeleteEmptyDirectories(rootDirectory, deletedDirectories);
|
||||
static void DeleteEmptyDirectories(string rootDirectory, List<string> deletedDirectories) =>
|
||||
XPath.DeleteEmptyDirectories(rootDirectory, deletedDirectories);
|
||||
// $dirs = gci "" -directory -recurse | Where { (gci $_.fullName).count -eq 0 } | select -expandproperty FullName $dirs | Foreach-Object { Remove-Item $_ }
|
||||
|
||||
string[] TestStatic_GetDirectoryNames(string directory) =>
|
||||
GetDirectoryNames(directory);
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user