LocationContainer
This commit is contained in:
@ -167,26 +167,43 @@ internal abstract class Location
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Rectangle GetRectangle(Rectangle checkRectangle, int locationDigits, int locationFactor, int normalizedRectangleValue, int height, int width, bool useOldWay)
|
||||
internal static Rectangle? GetRectangle(Rectangle checkRectangle, int height, int locationDigits, int locationFactor, string normalizedRectangle, int width, bool useOldWay)
|
||||
{
|
||||
Rectangle? result;
|
||||
string normalizedRectangle = normalizedRectangleValue.ToString();
|
||||
if (normalizedRectangle.Length != locationDigits)
|
||||
throw new NotImplementedException();
|
||||
if (!useOldWay)
|
||||
{
|
||||
result = GetRectangle(locationDigits, height, normalizedRectangle, width);
|
||||
if (result is null)
|
||||
throw new NullReferenceException(nameof(result));
|
||||
}
|
||||
else
|
||||
if (useOldWay)
|
||||
{
|
||||
(int? x, int? y) = GetXY(locationDigits, locationFactor, width, height, normalizedRectangle);
|
||||
if (x is null || y is null)
|
||||
throw new Exception();
|
||||
result = new(x.Value - (checkRectangle.Width / 2), y.Value - (checkRectangle.Height / 2), checkRectangle.Width, checkRectangle.Height);
|
||||
}
|
||||
return result.Value;
|
||||
else
|
||||
{
|
||||
if (normalizedRectangle.Length != locationDigits)
|
||||
result = null;
|
||||
else
|
||||
{
|
||||
result = GetRectangle(locationDigits, height, normalizedRectangle, width);
|
||||
if (result is null)
|
||||
throw new NullReferenceException(nameof(result));
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Rectangle? GetRectangle(int height, int locationDigits, int locationFactor, string normalizedRectangle, int outputResolutionHeight, int outputResolutionWidth, int width)
|
||||
{
|
||||
Rectangle? result;
|
||||
if (normalizedRectangle.Length == locationDigits && normalizedRectangle[0] is '4' or '8')
|
||||
result = GetRectangle(locationDigits, outputResolutionHeight, normalizedRectangle, outputResolutionWidth);
|
||||
else
|
||||
{
|
||||
(int? x, int? y) = GetXY(locationDigits, locationFactor, outputResolutionWidth, outputResolutionHeight, normalizedRectangle);
|
||||
if (x is null || y is null)
|
||||
throw new Exception();
|
||||
result = new(x.Value - (width / 2), y.Value - (height / 2), width, height);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
private static bool Matches(Models.OutputResolution outputResolution, DatabaseFile databaseFile)
|
||||
@ -217,6 +234,18 @@ internal abstract class Location
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Models.Location? GetLocation(int height, Rectangle rectangle, int width)
|
||||
{
|
||||
Models.Location? result;
|
||||
double confidence = 0;
|
||||
bool verified = Check(rectangle.Bottom, height, rectangle.Left, rectangle.Right, rectangle.Top, width, zCount: 1, throwException: false);
|
||||
if (!verified)
|
||||
result = null;
|
||||
else
|
||||
result = new(rectangle.Bottom, confidence, rectangle.Left, rectangle.Right, rectangle.Top);
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static Models.Location? GetLocation(Models.OutputResolution outputResolution, DatabaseFile databaseFile, Marker marker)
|
||||
{
|
||||
Models.Location? result;
|
||||
@ -228,7 +257,7 @@ internal abstract class Location
|
||||
return result;
|
||||
}
|
||||
|
||||
internal static List<Models.Location> GetLocations(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces)
|
||||
internal static List<Models.Location> GetLocations<T>(List<MappingFromPhotoPrism> mappingFromPhotoPrismCollection, List<Models.Face> faces, List<LocationContainer<T>> containers)
|
||||
{
|
||||
List<Models.Location> results = new();
|
||||
bool any;
|
||||
@ -246,6 +275,12 @@ internal abstract class Location
|
||||
outputResolution ??= face.OutputResolution;
|
||||
}
|
||||
int before = results.Count;
|
||||
foreach (LocationContainer<T> locationContainer in containers)
|
||||
{
|
||||
if (locationContainer.Location is null)
|
||||
continue;
|
||||
results.Add(locationContainer.Location);
|
||||
}
|
||||
foreach (MappingFromPhotoPrism mappingFromPhotoPrism in mappingFromPhotoPrismCollection)
|
||||
{
|
||||
if (outputResolution is null)
|
||||
@ -262,12 +297,27 @@ internal abstract class Location
|
||||
location = GetLocation(mappingFromPhotoPrism.DatabaseFile, marker, prismRectangle.Value);
|
||||
if (location is null)
|
||||
break;
|
||||
foreach (LocationContainer<T> locationContainer in containers)
|
||||
{
|
||||
if (any)
|
||||
continue;
|
||||
if (locationContainer.Location is null)
|
||||
continue;
|
||||
dlibRectangle = new(locationContainer.Location.Left, locationContainer.Location.Top, locationContainer.Location.Right - locationContainer.Location.Left, locationContainer.Location.Bottom - locationContainer.Location.Top);
|
||||
intersectRectangle = Rectangle.Intersect(prismRectangle.Value, dlibRectangle);
|
||||
if (intersectRectangle.Width == 0 && intersectRectangle.Height == 0)
|
||||
continue;
|
||||
any = true;
|
||||
break;
|
||||
}
|
||||
foreach (Models.Face face in faces)
|
||||
{
|
||||
if (any)
|
||||
continue;
|
||||
if (face.Location is null || face.OutputResolution is null)
|
||||
continue;
|
||||
dlibRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top);
|
||||
intersectRectangle = Rectangle.Intersect(dlibRectangle, prismRectangle.Value);
|
||||
intersectRectangle = Rectangle.Intersect(prismRectangle.Value, dlibRectangle);
|
||||
if (intersectRectangle.Width == 0 && intersectRectangle.Height == 0)
|
||||
continue;
|
||||
any = true;
|
||||
@ -282,4 +332,35 @@ internal abstract class Location
|
||||
return results;
|
||||
}
|
||||
|
||||
internal static List<Models.Face> FilterByIntersect(Models.Face[] faces, int normalizedRectangle)
|
||||
{
|
||||
List<Models.Face> results = new();
|
||||
bool useOldWay;
|
||||
double? percent;
|
||||
Rectangle checkRectangle;
|
||||
Rectangle? sourceRectangle;
|
||||
Rectangle intersectRectangle;
|
||||
foreach (Models.Face face in faces)
|
||||
{
|
||||
if (face.Location is null || face.OutputResolution is null)
|
||||
continue;
|
||||
checkRectangle = new(face.Location.Left, face.Location.Top, face.Location.Right - face.Location.Left, face.Location.Bottom - face.Location.Top);
|
||||
for (int i = 1; i < 3; i++)
|
||||
{
|
||||
useOldWay = i == 1;
|
||||
sourceRectangle = ILocation.GetRectangle(checkRectangle, Stateless.ILocation.Digits, Stateless.ILocation.Factor, normalizedRectangle, face.OutputResolution, useOldWay);
|
||||
if (sourceRectangle is null)
|
||||
continue;
|
||||
intersectRectangle = Rectangle.Intersect(checkRectangle, sourceRectangle.Value);
|
||||
if (intersectRectangle.Width == 0 || intersectRectangle.Height == 0)
|
||||
continue;
|
||||
percent = (double)intersectRectangle.Width * intersectRectangle.Height / (checkRectangle.Width * checkRectangle.Height);
|
||||
if (percent < 0.000001)
|
||||
continue;
|
||||
results.Add(face);
|
||||
}
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user