Re-write
This commit is contained in:
@ -11,9 +11,9 @@ using View_by_Distance.Resize.Models;
|
||||
using View_by_Distance.Shared.Models;
|
||||
using View_by_Distance.Shared.Models.Stateless;
|
||||
using View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
using View_by_Distance.TestsWithFaceRecognitionDotNet.Models;
|
||||
using View_by_Distance.Tests.Models;
|
||||
|
||||
namespace View_by_Distance.TestsWithFaceRecognitionDotNet;
|
||||
namespace View_by_Distance.Tests;
|
||||
|
||||
[TestClass]
|
||||
public class UnitTestFace
|
||||
@ -50,8 +50,8 @@ public class UnitTestFace
|
||||
_ = ConfigurationLoggerConfigurationExtensions.Configuration(loggerConfiguration.ReadFrom, configurationRoot);
|
||||
Log.Logger = loggerConfiguration.CreateLogger();
|
||||
logger = Log.ForContext<UnitTestFace>();
|
||||
propertyConfiguration = Property.Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory);
|
||||
configuration = Models.Stateless.Configuration.Get(isEnvironment, configurationRoot, workingDirectory, propertyConfiguration);
|
||||
propertyConfiguration = Property.Models.Binder.Configuration.Get(isEnvironment, configurationRoot);
|
||||
configuration = Models.Binder.Configuration.Get(isEnvironment, configurationRoot, propertyConfiguration);
|
||||
logger.Information("Complete");
|
||||
_Logger = logger;
|
||||
_AppSettings = appSettings;
|
||||
@ -74,12 +74,12 @@ public class UnitTestFace
|
||||
Assert.IsFalse(_PropertyConfiguration is null);
|
||||
}
|
||||
|
||||
private Property.Models.PropertyLogic GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel)
|
||||
private Property.Models.A_Property GetPropertyLogic(bool reverse, Model? model, PredictorModel? predictorModel)
|
||||
{
|
||||
Property.Models.PropertyLogic result;
|
||||
Property.Models.A_Property result;
|
||||
if (_Configuration?.PropertyConfiguration is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertyConfiguration));
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, reverse, model, predictorModel);
|
||||
result = new(_AppSettings.MaxDegreeOfParallelism, _Configuration.PropertyConfiguration, _Configuration.OutputExtension, reverse, model, predictorModel);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -124,42 +124,11 @@ public class UnitTestFace
|
||||
return result;
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestGetPixelPercentage()
|
||||
{
|
||||
int normalizedPixelPercentage;
|
||||
int left, top, right, bottom, width, height;
|
||||
left = 1;
|
||||
top = 1;
|
||||
right = 10;
|
||||
bottom = 10;
|
||||
width = 100;
|
||||
height = 100;
|
||||
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width);
|
||||
Assert.IsTrue(normalizedPixelPercentage == 0505);
|
||||
left = 50;
|
||||
top = 50;
|
||||
right = 60;
|
||||
bottom = 60;
|
||||
width = 100;
|
||||
height = 100;
|
||||
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width);
|
||||
Assert.IsTrue(normalizedPixelPercentage == 5555);
|
||||
left = 20;
|
||||
top = 40;
|
||||
right = 60;
|
||||
bottom = 80;
|
||||
width = 100;
|
||||
height = 100;
|
||||
normalizedPixelPercentage = Location.GetNormalizedPixelPercentage(bottom, height, left, right, top, width);
|
||||
Assert.IsTrue(normalizedPixelPercentage == 6040);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void TestMethodFace()
|
||||
{
|
||||
string sourceFileName = "IMG_0067.jpg";
|
||||
string sourceDirectoryName = "Mackenzie Prom 2017";
|
||||
// string sourceFileName = "IMG_0067.jpg";
|
||||
// string sourceDirectoryName = "Mackenzie Prom 2017";
|
||||
// string sourceFileName = "Fall 2005 (113).jpg";
|
||||
// string sourceDirectoryName = "=2005.3 Fall";
|
||||
// string sourceFileName = "DSCN0534.jpg";
|
||||
@ -168,38 +137,24 @@ public class UnitTestFace
|
||||
// string sourceDirectoryName = "Disneyland 2014";
|
||||
// string sourceFileName = "Logan Michael Sept 08 (193).jpg";
|
||||
// string sourceDirectoryName = "=2008.2 Summer Logan Michael";
|
||||
if (_Configuration.ForceMetadataLastWriteTimeToCreationTime is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.ForceMetadataLastWriteTimeToCreationTime));
|
||||
if (_Configuration.ForceResizeLastWriteTimeToCreationTime is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.ForceResizeLastWriteTimeToCreationTime));
|
||||
if (_Configuration.OutputQuality is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.OutputQuality));
|
||||
if (_Configuration.OverrideForResizeImages is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.OverrideForResizeImages));
|
||||
if (_Configuration.PropertiesChangedForMetadata is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertiesChangedForMetadata));
|
||||
if (_Configuration.PropertiesChangedForResize is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.PropertiesChangedForResize));
|
||||
if (_Configuration.NumberOfJitters is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.NumberOfJitters));
|
||||
if (_Configuration.NumberOfTimesToUpsample is null)
|
||||
throw new NullReferenceException(nameof(_Configuration.NumberOfTimesToUpsample));
|
||||
string sourceFileName = "Halloween 2006 (112).jpg";
|
||||
string sourceDirectoryName = "Halloween 2006";
|
||||
Item item;
|
||||
bool reverse = false;
|
||||
Property.Models.Item item;
|
||||
string original = "Original";
|
||||
string aResultsFullGroupDirectory;
|
||||
string bResultsFullGroupDirectory;
|
||||
string cResultsFullGroupDirectory;
|
||||
List<string> parseExceptions = new();
|
||||
bool isValidImageFormatExtension = true;
|
||||
Property.Models.A_Property? property = null;
|
||||
Shared.Models.Property? property = null;
|
||||
Dictionary<string, int[]> imageResizeKeyValuePairs;
|
||||
List<Tuple<string, DateTime>> subFileTuples = new();
|
||||
List<KeyValuePair<string, string>> metadataCollection;
|
||||
int length = _PropertyConfiguration.RootDirectory.Length;
|
||||
string outputResolution = _Configuration.OutputResolutions[0];
|
||||
(Model model, PredictorModel predictorModel, ModelParameter modelParameter) = GetModel(_Configuration);
|
||||
Property.Models.PropertyLogic propertyLogic = GetPropertyLogic(reverse, model, predictorModel);
|
||||
Property.Models.A_Property propertyLogic = GetPropertyLogic(reverse, model, predictorModel);
|
||||
string sourceDirectory = Path.Combine(_PropertyConfiguration.RootDirectory, sourceDirectoryName);
|
||||
_Logger.Information(_Configuration.ModelDirectory);
|
||||
aResultsFullGroupDirectory = Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(
|
||||
@ -209,9 +164,11 @@ public class UnitTestFace
|
||||
cResultsFullGroupDirectory = Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(
|
||||
_PropertyConfiguration, model, predictorModel, nameof(C_Resize), outputResolution, includeResizeGroup: true, includeModel: false, includePredictorModel: false);
|
||||
string aPropertySingletonDirectory = Property.Models.Stateless.IResult.GetResultsDateGroupDirectory(_PropertyConfiguration, nameof(Property.Models.A_Property), "{}");
|
||||
B_Metadata metadata = new(_Configuration.ForceMetadataLastWriteTimeToCreationTime.Value, _Configuration.PropertiesChangedForMetadata.Value);
|
||||
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters) = C_Resize.GetTuple(_Configuration.OutputExtension, _Configuration.OutputQuality.Value);
|
||||
C_Resize resize = new(_Configuration.ForceResizeLastWriteTimeToCreationTime.Value, _Configuration.OverrideForResizeImages.Value, _Configuration.PropertiesChangedForResize.Value, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters);
|
||||
B_Metadata metadata = new(_Configuration.ForceMetadataLastWriteTimeToCreationTime, _Configuration.PropertiesChangedForMetadata);
|
||||
_ = metadata.ToString();
|
||||
(ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension) = C_Resize.GetTuple(_Configuration.OutputExtension, _Configuration.OutputQuality);
|
||||
C_Resize resize = new(_Configuration.ForceResizeLastWriteTimeToCreationTime, _Configuration.OverrideForResizeImages, _Configuration.PropertiesChangedForResize, _Configuration.ValidResolutions, imageCodecInfo, encoderParameters, filenameExtension);
|
||||
_ = resize.ToString();
|
||||
propertyLogic.AngleBracketCollection.AddRange(Property.Models.Stateless.IResult.GetDirectoryInfoCollection(
|
||||
_PropertyConfiguration,
|
||||
sourceDirectory,
|
||||
@ -237,8 +194,8 @@ public class UnitTestFace
|
||||
collectionDescription: string.Empty,
|
||||
converted: true));
|
||||
string sourceDirectoryFile = ".json";
|
||||
Property.Models.FileHolder fileHolder = new(Path.Combine(sourceDirectory, sourceFileName));
|
||||
string relativePath = Property.Models.Stateless.IPath.GetRelativePath(fileHolder.FullName, length);
|
||||
FileHolder fileHolder = new(Path.Combine(sourceDirectory, sourceFileName));
|
||||
string relativePath = IPath.GetRelativePath(fileHolder.FullName, length);
|
||||
sourceDirectory = Path.Combine(aPropertySingletonDirectory, sourceDirectoryName);
|
||||
item = new(sourceDirectoryFile, relativePath, fileHolder, isValidImageFormatExtension, property, false, false);
|
||||
Assert.IsNotNull(item.ImageFileHolder);
|
||||
@ -249,22 +206,18 @@ public class UnitTestFace
|
||||
}
|
||||
(int _, metadataCollection) = metadata.GetMetadataCollection(bResultsFullGroupDirectory, subFileTuples, parseExceptions, item);
|
||||
imageResizeKeyValuePairs = resize.GetResizeKeyValuePairs(cResultsFullGroupDirectory, subFileTuples, parseExceptions, original, metadataCollection, item);
|
||||
Property.Models.FileHolder resizedFileHolder = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(item.ImageFileHolder.FullName)));
|
||||
item.SetResizedFileHolder(resizedFileHolder);
|
||||
FileHolder resizedFileHolder = new(Path.Combine(resize.AngleBracketCollection[0].Replace("<>", "()"), Path.GetFileName(item.ImageFileHolder.FullName)));
|
||||
item.SetResizedFileHolder(resize.FilenameExtension, resizedFileHolder);
|
||||
resize.SaveResizedSubfile(outputResolution, cResultsFullGroupDirectory, subFileTuples, item, original, imageResizeKeyValuePairs);
|
||||
item.SetResizedFileHolder(Property.Models.FileHolder.Refresh(resizedFileHolder));
|
||||
item.SetResizedFileHolder(resize.FilenameExtension, IFileHolder.Refresh(resizedFileHolder));
|
||||
Assert.IsNotNull(item.ResizedFileHolder);
|
||||
Image? image = FaceRecognition.LoadImageFile(item.ResizedFileHolder.FullName);
|
||||
Image image = FaceRecognition.LoadImageFile(item.ResizedFileHolder.FullName);
|
||||
Assert.IsNotNull(image);
|
||||
FaceRecognition faceRecognition = FaceRecognition.Create(modelParameter);
|
||||
List<Location> locations = faceRecognition.FaceLocations(model, image, _Configuration.NumberOfTimesToUpsample.Value, sortByNormalizedPixelPercentage: true);
|
||||
Assert.IsTrue(locations.Count == 2);
|
||||
List<(FacePart, FacePoint[])[]> faceLandmarks = faceRecognition.GetFaceLandmarkCollection(image, _Configuration.NumberOfTimesToUpsample.Value, locations, predictorModel, model);
|
||||
Assert.IsTrue(faceLandmarks.Count == 2);
|
||||
faceLandmarks = faceRecognition.GetFaceLandmarkCollection(image, _Configuration.NumberOfTimesToUpsample.Value, faceLocations: null, predictorModel, model);
|
||||
Assert.IsTrue(faceLandmarks.Count == 2);
|
||||
List<FaceRecognitionDotNet.FaceEncoding> faceEncodings = faceRecognition.FaceEncodings(image, _Configuration.NumberOfTimesToUpsample.Value, knownFaceLocation: null, _Configuration.NumberOfJitters.Value, predictorModel, model);
|
||||
Assert.IsTrue(faceEncodings.Count == 2);
|
||||
FaceRecognition faceRecognition = new(_Configuration.NumberOfTimesToUpsample, _Configuration.NumberOfJitters, predictorModel, model, modelParameter);
|
||||
List<(Location Location, FaceRecognitionDotNet.FaceEncoding? FaceEncoding, Dictionary<FacePart, FacePoint[]>? FaceParts)> collection;
|
||||
collection = faceRecognition.GetCollection(image, includeFaceEncoding: true, includeFaceParts: true, sortByNormalizedPixelPercentage: true);
|
||||
Assert.IsTrue(collection.Count == 2);
|
||||
FaceRecognitionDotNet.FaceEncoding[] faceEncodings = (from l in collection where l.FaceEncoding is not null select l.FaceEncoding).ToArray();
|
||||
List<double> faceDistances = FaceRecognition.FaceDistances(faceEncodings, faceEncodings[0]);
|
||||
Assert.IsTrue(faceDistances.Count == 2);
|
||||
Assert.IsNotNull(sourceFileName);
|
||||
|
Reference in New Issue
Block a user