Get Unable to Match Count and Rename Matches
This commit is contained in:
@ -134,7 +134,7 @@ public class FaceRecognition : DisposableObject
|
||||
}
|
||||
}
|
||||
|
||||
public List<Location> FaceLocations(Image image, bool sortByNormalizedPixelPercentage)
|
||||
public List<Location> FaceLocations(Image image)
|
||||
{
|
||||
if (image is null)
|
||||
throw new NullReferenceException(nameof(image));
|
||||
@ -150,14 +150,6 @@ public class FaceRecognition : DisposableObject
|
||||
mModRect.Dispose();
|
||||
results.Add(location);
|
||||
}
|
||||
if (sortByNormalizedPixelPercentage)
|
||||
{
|
||||
results = (from l in results orderby l.NormalizedPixelPercentage select l).ToList();
|
||||
int?[] normalizedPixelPercentageCollection = Shared.Models.Stateless.Methods.ILocation.GetInts(results);
|
||||
int normalizedPixelPercentageDistinctCount = normalizedPixelPercentageCollection.Distinct().Count();
|
||||
if (normalizedPixelPercentageDistinctCount != normalizedPixelPercentageCollection.Length)
|
||||
throw new Exception("Not distinct!");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
@ -187,7 +179,7 @@ public class FaceRecognition : DisposableObject
|
||||
return results;
|
||||
}
|
||||
|
||||
private List<Location> GetLocations(Image image, bool sortByNormalizedPixelPercentage)
|
||||
private List<Location> GetLocations(Image image)
|
||||
{
|
||||
List<Location> results = new();
|
||||
MModRect[] mModRects = GetMModRects(image);
|
||||
@ -203,33 +195,25 @@ public class FaceRecognition : DisposableObject
|
||||
results.Add(location);
|
||||
}
|
||||
}
|
||||
if (sortByNormalizedPixelPercentage)
|
||||
{
|
||||
results = (from l in results orderby l.NormalizedPixelPercentage select l).ToList();
|
||||
int?[] normalizedPixelPercentageCollection = Shared.Models.Stateless.Methods.ILocation.GetInts(results);
|
||||
int normalizedPixelPercentageDistinctCount = normalizedPixelPercentageCollection.Distinct().Count();
|
||||
if (normalizedPixelPercentageDistinctCount != normalizedPixelPercentageCollection.Length)
|
||||
throw new Exception("Not distinct!");
|
||||
}
|
||||
return results;
|
||||
}
|
||||
|
||||
public List<(int, Location, FaceEncoding?, Dictionary<FacePart, FacePoint[]>?)> GetCollection(Image image, bool includeFaceEncoding, bool includeFaceParts, bool sortByNormalizedPixelPercentage)
|
||||
public List<(Location, FaceEncoding?, Dictionary<FacePart, FacePoint[]>?)> GetCollection(Image image, bool includeFaceEncoding, bool includeFaceParts)
|
||||
{
|
||||
List<(int, Location, FaceEncoding?, Dictionary<FacePart, FacePoint[]>?)> results = new();
|
||||
List<(Location, FaceEncoding?, Dictionary<FacePart, FacePoint[]>?)> results = new();
|
||||
if (image is null)
|
||||
throw new NullReferenceException(nameof(image));
|
||||
image.ThrowIfDisposed();
|
||||
ThrowIfDisposed();
|
||||
if (_PredictorModel == PredictorModel.Custom)
|
||||
throw new NotSupportedException("FaceRecognition.PredictorModel.Custom is not supported.");
|
||||
List<Location> locations = GetLocations(image, sortByNormalizedPixelPercentage);
|
||||
List<Location> locations = GetLocations(image);
|
||||
List<FullObjectDetection> fullObjectDetections = GetFullObjectDetections(image, locations);
|
||||
if (fullObjectDetections.Count != locations.Count)
|
||||
throw new Exception();
|
||||
List<(int LocationIndex, Location Location, List<FaceEncoding?> FaceEncodings, List<List<(FacePart, FacePoint[])>> FaceParts)> collection = new();
|
||||
for (int i = 0; i < locations.Count; i++)
|
||||
collection.Add(new(i, locations[i], new(), new()));
|
||||
List<(Location Location, List<FaceEncoding?> FaceEncodings, List<List<(FacePart, FacePoint[])>> FaceParts)> collection = new();
|
||||
foreach (Location location in locations)
|
||||
collection.Add(new(location, new(), new()));
|
||||
if (locations.Count != collection.Count)
|
||||
throw new Exception();
|
||||
if (!includeFaceEncoding)
|
||||
@ -266,18 +250,18 @@ public class FaceRecognition : DisposableObject
|
||||
fullObjectDetection.Dispose();
|
||||
const int indexZero = 0;
|
||||
Dictionary<FacePart, FacePoint[]> keyValuePairs;
|
||||
foreach ((int locationIndex, Location location, List<FaceEncoding?> faceEncodings, List<List<(FacePart, FacePoint[])>> faceParts) in collection)
|
||||
foreach ((Location location, List<FaceEncoding?> faceEncodings, List<List<(FacePart, FacePoint[])>> faceParts) in collection)
|
||||
{
|
||||
if (faceEncodings.Count != 1 || faceParts.Count != 1)
|
||||
continue;
|
||||
if (!faceParts[indexZero].Any())
|
||||
results.Add(new(locationIndex, location, faceEncodings[indexZero], null));
|
||||
results.Add(new(location, faceEncodings[indexZero], null));
|
||||
else
|
||||
{
|
||||
keyValuePairs = new();
|
||||
foreach ((FacePart facePart, FacePoint[] facePoints) in faceParts[indexZero])
|
||||
keyValuePairs.Add(facePart, facePoints);
|
||||
results.Add(new(locationIndex, location, faceEncodings[indexZero], keyValuePairs));
|
||||
results.Add(new(location, faceEncodings[indexZero], keyValuePairs));
|
||||
}
|
||||
}
|
||||
return results;
|
||||
|
Reference in New Issue
Block a user