NullReferenceException
This commit is contained in:
@ -251,15 +251,17 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
}
|
||||
}
|
||||
|
||||
private List<D_Face> GetFaces(FileHolder resizedFileHolder, PropertyHolder propertyHolder, A_Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string facesDirectory)
|
||||
private List<D_Face> GetFaces(FileHolder resizedFileHolder, Item item, A_Property property, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation, string facesDirectory)
|
||||
{
|
||||
List<D_Face> results = new();
|
||||
if (_Configuration.PaddingLoops is null)
|
||||
throw new Exception();
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
if (_Configuration.NumberOfJitters is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.NumberOfJitters));
|
||||
throw new NullReferenceException(nameof(_Configuration.NumberOfJitters));
|
||||
if (_Configuration.NumberOfTimesToUpsample is null)
|
||||
throw new ArgumentNullException(nameof(_Configuration.NumberOfTimesToUpsample));
|
||||
throw new NullReferenceException(nameof(_Configuration.NumberOfTimesToUpsample));
|
||||
List<Location> locations;
|
||||
FaceRecognitionDotNet.Image? unknownImage = null;
|
||||
if (resizedFileHolder.Exists)
|
||||
@ -269,13 +271,13 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
catch (Exception) { }
|
||||
}
|
||||
if (unknownImage is null)
|
||||
results.Add(new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i: null, location: null));
|
||||
results.Add(new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, item.RelativePath, i: null, location: null));
|
||||
else
|
||||
{
|
||||
FaceRecognition faceRecognition = FaceRecognition.Create(_ModelParameter);
|
||||
locations = faceRecognition.FaceLocations(_Model, unknownImage, _Configuration.NumberOfTimesToUpsample.Value, sortByPixelPercentage: true);
|
||||
if (!locations.Any())
|
||||
results.Add(new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i: null, location: null));
|
||||
results.Add(new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, item.RelativePath, i: null, location: null));
|
||||
else
|
||||
{
|
||||
double? α;
|
||||
@ -312,7 +314,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
locations[i].Top - (padding * p),
|
||||
source.Width,
|
||||
source.Height);
|
||||
face = new(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i, location);
|
||||
face = new(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, item.RelativePath, i, location);
|
||||
width = location.Right - location.Left;
|
||||
height = location.Bottom - location.Top;
|
||||
rectangle = new Rectangle(location.Left, location.Top, width, height);
|
||||
@ -329,7 +331,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
using (knownImage = FaceRecognition.LoadImage(preRotated))
|
||||
{
|
||||
if (knownImage is null || knownImage.IsDisposed)
|
||||
throw new ArgumentNullException(nameof(knownImage));
|
||||
throw new NullReferenceException(nameof(knownImage));
|
||||
facesLandmarks = faceRecognition.GetFaceLandmarkCollection(knownImage, _Configuration.NumberOfTimesToUpsample.Value, faceLocations: null, _PredictorModel, _Model);
|
||||
}
|
||||
if (facesLandmarks.Count == 0 && p < _Configuration.PaddingLoops.Value)
|
||||
@ -361,7 +363,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
using (rotatedImage = FaceRecognition.LoadImage(rotated))
|
||||
{
|
||||
if (rotatedImage is null || rotatedImage.IsDisposed)
|
||||
throw new ArgumentNullException(nameof(rotatedImage));
|
||||
throw new NullReferenceException(nameof(rotatedImage));
|
||||
faceEncodings = faceRecognition.FaceEncodings(rotatedImage, _Configuration.NumberOfTimesToUpsample.Value, knownFaceLocation: null, _Configuration.NumberOfJitters.Value, _PredictorModel, _Model);
|
||||
}
|
||||
if (faceEncodings.Count == 0 && p < _Configuration.PaddingLoops.Value)
|
||||
@ -372,7 +374,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
faceEncoding = new(rawEncoding, faceEncodings[0].Size);
|
||||
face.Update(α, faceEncoding, populated: true);
|
||||
}
|
||||
faceFile = Path.Combine(facesDirectory, $"{i} - {propertyHolder.ImageFileNameWithoutExtension}.png");
|
||||
faceFile = Path.Combine(facesDirectory, $"{i} - {item.ImageFileHolder.NameWithoutExtension}.png");
|
||||
preRotated.Save(faceFile, System.Drawing.Imaging.ImageFormat.Png);
|
||||
results.Add(face);
|
||||
}
|
||||
@ -388,7 +390,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
locations[i].Top,
|
||||
source.Width,
|
||||
source.Height);
|
||||
face = new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, propertyHolder.RelativePath, i, location);
|
||||
face = new D_Face(property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, item.RelativePath, i, location);
|
||||
results.Add(face);
|
||||
}
|
||||
}
|
||||
@ -410,18 +412,20 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
_Populated = populated;
|
||||
}
|
||||
|
||||
internal List<D_Face> GetFaces(Property.Models.Configuration configuration, string outputResolution, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, A_Property property, FileHolder resizedFileHolder, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation)
|
||||
internal List<D_Face> GetFaces(Property.Models.Configuration configuration, string outputResolution, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Item item, A_Property property, FileHolder resizedFileHolder, int outputResolutionWidth, int outputResolutionHeight, int outputResolutionOrientation)
|
||||
{
|
||||
List<D_Face>? results;
|
||||
if (_Configuration.PropertiesChangedForFaces is null)
|
||||
throw new Exception();
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
string json;
|
||||
D_Face face;
|
||||
bool checkForOutputResolutionChange = false;
|
||||
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), propertyHolder.ImageFileNameWithoutExtension);
|
||||
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "[]"), $"{propertyHolder.ImageFileNameWithoutExtension}.json"));
|
||||
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), item.ImageFileHolder.NameWithoutExtension);
|
||||
FileInfo fileInfo = new(Path.Combine(AngleBracketCollection[0].Replace("<>", "[]"), $"{item.ImageFileHolder.NameWithoutExtension}.json"));
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
if (fileInfo.Directory?.Parent is null)
|
||||
@ -445,7 +449,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
{
|
||||
results = JsonSerializer.Deserialize<List<D_Face>>(json);
|
||||
if (results is null)
|
||||
throw new ArgumentNullException(nameof(results));
|
||||
throw new NullReferenceException(nameof(results));
|
||||
for (int i = 0; i < results.Count; i++)
|
||||
{
|
||||
face = results[i];
|
||||
@ -473,7 +477,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
}
|
||||
else if (results is null)
|
||||
{
|
||||
results = GetFaces(resizedFileHolder, propertyHolder, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
|
||||
results = GetFaces(resizedFileHolder, item, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation, facesDirectory);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
@ -483,18 +487,20 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
return results;
|
||||
}
|
||||
|
||||
internal void SaveFaces(Property.Models.Configuration configuration, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, PropertyHolder propertyHolder, List<D_Face> faceCollection)
|
||||
internal void SaveFaces(Property.Models.Configuration configuration, List<Tuple<string, DateTime>> subFileTuples, List<string> parseExceptions, Item item, List<D_Face> faceCollection)
|
||||
{
|
||||
if (_Configuration.OverrideForFaceImages is null)
|
||||
throw new Exception();
|
||||
if (propertyHolder.ResizedFileHolder is null)
|
||||
throw new Exception($"{propertyHolder.ResizedFileHolder} is null!");
|
||||
if (item.ImageFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ImageFileHolder));
|
||||
if (item.ResizedFileHolder is null)
|
||||
throw new NullReferenceException(nameof(item.ResizedFileHolder));
|
||||
FileInfo fileInfo;
|
||||
bool check = false;
|
||||
string parentCheck;
|
||||
List<string> imageFiles = new();
|
||||
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
|
||||
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), propertyHolder.ImageFileNameWithoutExtension);
|
||||
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), item.ImageFileHolder.NameWithoutExtension);
|
||||
List<DateTime> dateTimes = (from l in subFileTuples where changesFrom.Contains(l.Item1) select l.Item2).ToList();
|
||||
bool facesDirectoryExisted = Directory.Exists(facesDirectory);
|
||||
if (!facesDirectoryExisted)
|
||||
@ -506,7 +512,7 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
imageFiles.Add(string.Empty);
|
||||
continue;
|
||||
}
|
||||
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{i} - {propertyHolder.ImageFileNameWithoutExtension}.png"));
|
||||
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{i} - {item.ImageFileHolder.NameWithoutExtension}.png"));
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
if (fileInfo.Directory?.Parent is null)
|
||||
@ -524,19 +530,20 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
check = true;
|
||||
}
|
||||
if (check)
|
||||
SaveFaces(faceCollection, propertyHolder.ResizedFileHolder, imageFiles);
|
||||
SaveFaces(faceCollection, item.ResizedFileHolder, imageFiles);
|
||||
}
|
||||
|
||||
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, PropertyHolder[] filteredPropertyHolderCollection)
|
||||
internal static void SaveShortcuts(Property.Models.Configuration configuration, Model? model, PredictorModel? predictorModel, string[] juliePhares, long ticks, Dictionary<string, List<Person>> peopleCollection, PropertyLogic propertyLogic, string outputResolution, Item[] filteredItems)
|
||||
{
|
||||
Person person;
|
||||
string fileName;
|
||||
string fullName;
|
||||
DateTime? minimumDateTime;
|
||||
WindowsShortcut windowsShortcut;
|
||||
const string pattern = @"[\\,\/,\:,\*,\?,\"",\<,\>,\|]";
|
||||
string dFacesContentDirectory = Path.Combine(Property.Models.Stateless.IResult.GetResultsFullGroupDirectory(configuration, model, predictorModel, nameof(D_Face), outputResolution, includeResizeGroup: true, includeModel: true, includePredictorModel: true), $"({ticks})");
|
||||
List<(PropertyHolder, (string, Shared.Models.Properties.IFace?, (string, string, string, string))[])> collections = PropertyHolder.GetCollection(propertyLogic, filteredPropertyHolderCollection, dFacesContentDirectory);
|
||||
foreach ((PropertyHolder propertyHolder, (string personKey, Shared.Models.Properties.IFace? _, (string, string, string, string))[] collection) in collections)
|
||||
List<(Item, (string, Shared.Models.Properties.IFace?, (string, string, string, string))[])> collections = Item.GetCollection(propertyLogic, filteredItems, dFacesContentDirectory);
|
||||
foreach ((Item item, (string personKey, Shared.Models.Properties.IFace? _, (string, string, string, string))[] collection) in collections)
|
||||
{
|
||||
if (collection.Length != 1)
|
||||
continue;
|
||||
@ -544,7 +551,10 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
{
|
||||
if (string.IsNullOrEmpty(personKey))
|
||||
continue;
|
||||
if (propertyHolder.Property?.Id is null || propertyHolder.ImageFileHolder is null || propertyHolder.MinimumDateTime is null || propertyHolder.ResizedFileHolder is null)
|
||||
if (item.Property?.Id is null || item.ImageFileHolder is null || item.ResizedFileHolder is null)
|
||||
continue;
|
||||
minimumDateTime = Property.Models.Stateless.A_Property.GetMinimumDateTime(item.Property);
|
||||
if (minimumDateTime is null)
|
||||
continue;
|
||||
if (!Directory.Exists(directory))
|
||||
{
|
||||
@ -560,19 +570,19 @@ public class D_Face : Shared.Models.Properties.IFace, IFace
|
||||
{
|
||||
if (!Directory.Exists(copyDirectory))
|
||||
_ = Directory.CreateDirectory(copyDirectory);
|
||||
fileName = Path.Combine(copyDirectory, $"{propertyHolder.Property.Id.Value}{propertyHolder.ResizedFileHolder.Extension}");
|
||||
fileName = Path.Combine(copyDirectory, $"{item.Property.Id.Value}{item.ResizedFileHolder.ExtensionLowered}");
|
||||
if (!File.Exists(fileName))
|
||||
File.Copy(propertyHolder.ResizedFileHolder.FullName, fileName);
|
||||
File.Copy(item.ResizedFileHolder.FullName, fileName);
|
||||
}
|
||||
fileName = Path.Combine(directory, $"{propertyHolder.Property.Id.Value}.lnk");
|
||||
fileName = Path.Combine(directory, $"{item.Property.Id.Value}.lnk");
|
||||
if (File.Exists(fileName))
|
||||
continue;
|
||||
windowsShortcut = new() { Path = propertyHolder.ImageFileHolder.FullName };
|
||||
windowsShortcut = new() { Path = item.ImageFileHolder.FullName };
|
||||
windowsShortcut.Save(fileName);
|
||||
windowsShortcut.Dispose();
|
||||
if (!File.Exists(fileName))
|
||||
continue;
|
||||
File.SetLastWriteTime(fileName, propertyHolder.MinimumDateTime.Value);
|
||||
File.SetLastWriteTime(fileName, minimumDateTime.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user