Re-Write without checking mapped
This commit is contained in:
@ -2,6 +2,7 @@ using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Drawing.Imaging;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using View_by_Distance.FaceRecognitionDotNet;
|
||||
using View_by_Distance.Metadata.Models;
|
||||
using View_by_Distance.Property.Models;
|
||||
@ -35,7 +36,7 @@ public class D_Face
|
||||
private readonly EncoderParameters _EncoderParameters;
|
||||
private readonly ImageCodecInfo _HiddenImageCodecInfo;
|
||||
private readonly EncoderParameters _HiddenEncoderParameters;
|
||||
private readonly JsonSerializerOptions _WriteIndentedJsonSerializerOptions;
|
||||
private readonly JsonSerializerOptions _WriteIndentedAndWhenWritingNull;
|
||||
|
||||
internal D_Face(Configuration configuration, string argZero, Model model, ModelParameter modelParameter, PredictorModel predictorModel, ImageCodecInfo imageCodecInfo, EncoderParameters encoderParameters, string filenameExtension, ImageCodecInfo hiddenImageCodecInfo, EncoderParameters hiddenEncoderParameters, string hiddenFilenameExtension)
|
||||
{
|
||||
@ -52,7 +53,7 @@ public class D_Face
|
||||
_HiddenImageCodecInfo = hiddenImageCodecInfo;
|
||||
_HiddenEncoderParameters = hiddenEncoderParameters;
|
||||
_HiddenFilenameExtension = hiddenFilenameExtension;
|
||||
_WriteIndentedJsonSerializerOptions = new JsonSerializerOptions { WriteIndented = true };
|
||||
_WriteIndentedAndWhenWritingNull = new JsonSerializerOptions { WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull };
|
||||
}
|
||||
|
||||
private static void GetPointBounds(PointF[] points, out float xMinimum, out float xMaximum, out float yMinimum, out float yMaximum)
|
||||
@ -321,7 +322,7 @@ public class D_Face
|
||||
if (results is null)
|
||||
{
|
||||
results = GetFaces(item, property, outputResolutionWidth, outputResolutionHeight, outputResolutionOrientation);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedAndWhenWritingNull);
|
||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
if (Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
|
||||
@ -334,7 +335,7 @@ public class D_Face
|
||||
normalizedPixelPercentageDistinctCount = normalizedPixelPercentageCollection.Distinct().Count();
|
||||
if (normalizedPixelPercentageDistinctCount != normalizedPixelPercentageCollection.Length)
|
||||
throw new Exception($"Not distinct! <{fileInfo.FullName}>");
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedJsonSerializerOptions);
|
||||
json = JsonSerializer.Serialize(results, _WriteIndentedAndWhenWritingNull);
|
||||
bool updateDateWhenMatches = dateTimes.Any() && fileInfo.Exists && dateTimes.Max() > fileInfo.LastWriteTime;
|
||||
DateTime? dateTime = !updateDateWhenMatches ? null : dateTimes.Max();
|
||||
if (Shared.Models.Stateless.Methods.IPath.WriteAllText(fileInfo.FullName, json, updateDateWhenMatches, compareBeforeWrite: true, updateToWhenMatches: dateTime))
|
||||
@ -356,7 +357,7 @@ public class D_Face
|
||||
FileInfo fileInfo;
|
||||
bool check = false;
|
||||
string parentCheck;
|
||||
double deterministicHashCodeKey;
|
||||
string deterministicHashCodeKeyDisplay;
|
||||
List<(Face, FileInfo?, string)> collection = new();
|
||||
string[] changesFrom = new string[] { nameof(A_Property), nameof(B_Metadata), nameof(C_Resize) };
|
||||
string facesDirectory = Path.Combine(AngleBracketCollection[0].Replace("<>", "()"), item.ImageFileHolder.NameWithoutExtension);
|
||||
@ -366,13 +367,13 @@ public class D_Face
|
||||
_ = Directory.CreateDirectory(facesDirectory);
|
||||
foreach (Face face in faceCollection)
|
||||
{
|
||||
if (face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
if (item.Property?.Id is null || face.FaceEncoding is null || face.Location?.NormalizedPixelPercentage is null)
|
||||
{
|
||||
collection.Add(new(face, null, string.Empty));
|
||||
continue;
|
||||
}
|
||||
deterministicHashCodeKey = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKey(item, face);
|
||||
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_FilenameExtension}"));
|
||||
deterministicHashCodeKeyDisplay = Shared.Models.Stateless.Methods.IMapping.GetDeterministicHashCodeKeyDisplay(item.Property.Id.Value, face.Location.NormalizedPixelPercentage.Value);
|
||||
fileInfo = new FileInfo(Path.Combine(facesDirectory, $"{deterministicHashCodeKeyDisplay}{item.ImageFileHolder.ExtensionLowered}{_FilenameExtension}"));
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
if (fileInfo.Directory?.Parent is null)
|
||||
@ -381,7 +382,7 @@ public class D_Face
|
||||
if (File.Exists(parentCheck))
|
||||
File.Delete(parentCheck);
|
||||
}
|
||||
collection.Add(new(face, fileInfo, Path.Combine(facesDirectory, $"{deterministicHashCodeKey}{item.ImageFileHolder.ExtensionLowered}{_HiddenFilenameExtension}")));
|
||||
collection.Add(new(face, fileInfo, Path.Combine(facesDirectory, $"{deterministicHashCodeKeyDisplay}{item.ImageFileHolder.ExtensionLowered}{_HiddenFilenameExtension}")));
|
||||
if (_Configuration.OverrideForFaceImages)
|
||||
check = true;
|
||||
else if (!fileInfo.Exists)
|
||||
|
||||
Reference in New Issue
Block a user