From 89bb87bd1425cc9bda46f51414914f8aa678a17b Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sat, 5 Jul 2025 13:13:00 -0700 Subject: [PATCH] export-faces (Day-Helper-2025-07-05) --- .vscode/launch.json | 10 +++ ADO2025/PI6/Helper-2025-07-05.cs | 112 +++++++++++++++++++++++++++++++ Day/HelperDay.cs | 2 + File-Folder-Helper.csproj | 1 + 4 files changed, 125 insertions(+) create mode 100644 ADO2025/PI6/Helper-2025-07-05.cs diff --git a/.vscode/launch.json b/.vscode/launch.json index 6beb8e0..3e3e421 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -11,6 +11,16 @@ "preLaunchTask": "build", "program": "${workspaceFolder}/bin/Debug/net8.0/win-x64/File-Folder-Helper.dll", "args": [ + "s", + "X", + "V:/Tmp/Phares/Pictures/2023 TI2023.6 Fall Samsung", + "Day-Helper-2025-07-05", + "x-653889110721.jpg~401223300869.jpg", + "3648,2736,1~3024,4032,6", + "0.341694,0.599963,0.1642,0.279605~0.552357,0.65095,0.195175,0.32383~0.31002,0.42328,0.0379464,0.0459656", + "0.259594,0.460161,0.1642,0.279605~0.45477,0.489035,0.195175,0.32383~0.328993,0.446263,0.0379464,0.0459656", + "9", + "x-825511723~x-444522128~831410304", "s", "X", "\\\\mesfs.infineon.com\\EC_APC\\Production\\Traces\\DEP08CEPIEPSILON\\PollPath", diff --git a/ADO2025/PI6/Helper-2025-07-05.cs b/ADO2025/PI6/Helper-2025-07-05.cs new file mode 100644 index 0000000..721a77a --- /dev/null +++ b/ADO2025/PI6/Helper-2025-07-05.cs @@ -0,0 +1,112 @@ + +using System.Drawing; + +using Microsoft.Extensions.Logging; + +namespace File_Folder_Helper.ADO2025.PI6; + +internal static partial class Helper20250705 { + + internal static void ExportFaces(ILogger logger, List args) { + string checkFile; + logger.LogInformation(args[0]); + logger.LogInformation(args[1]); + logger.LogInformation(args[2]); + logger.LogInformation(args[3]); + logger.LogInformation(args[4]); + logger.LogInformation(args[5]); + logger.LogInformation(args[6]); + logger.LogInformation(args[7]); + string locationDigits = args[6]; + string[] mp = args[4].Split('~'); + string[] mwg = args[5].Split('~'); + string[] xyz = args[3].Split(','); + string[] fileNames = args[2].Split('~'); + string[] wholePercentages = args[7].Split('~'); + string sourceDirectory = Path.GetFullPath(args[0].Split('~')[0]); + if (mp.Length != mwg.Length || mp.Length != wholePercentages.Length) { + logger.LogWarning("Lengths don't match!"); + } else { + foreach (string fileName in fileNames) { + checkFile = Path.Combine(sourceDirectory, fileName); + if (!File.Exists(checkFile)) { + logger.LogWarning("<{file}> doesn't exist!", args[2]); + continue; + } + for (int i = 0; i < mp.Length; i++) { + if (wholePercentages[i].StartsWith("x-")) { + logger.LogWarning("Skipping {wholePercentages}", wholePercentages[i]); + continue; + } + Ext(checkFile, xyz, i, mp[i], mwg[i], locationDigits, wholePercentages[i]); + } + } + } + } + + private static void Ext(string checkFile, string[] xyz, int i, string mp, string mwg, string locationDigits, string wholePercentages) { + int width = int.Parse(xyz[0]); + int height = int.Parse(xyz[1]); + string[] mpValues = mp.Split(','); + string[] mwgValues = mwg.Split(','); + float mpWidth = float.Parse(mpValues[2]) * width; + float mpHeight = float.Parse(mpValues[3]) * height; + double mpLeft = (float.Parse(mpValues[0]) * width) - (mpWidth * .5); + double mpTop = (float.Parse(mpValues[1]) * height) - (mpHeight * .5); + Extract(file: checkFile, + width: mpWidth, + height: mpHeight, + left: mpLeft, + top: mpTop, + suffix: $"-{i}mp.jpg"); + float mwgWidth = float.Parse(mwgValues[2]) * width; + float mwgHeight = float.Parse(mwgValues[3]) * height; + double mwgLeft = double.Parse(mwgValues[0]) * width; + double mwgTop = double.Parse(mwgValues[1]) * height; + Extract(file: checkFile, + width: mwgWidth, + height: mwgHeight, + left: mwgLeft, + top: mwgTop, + suffix: $"-{i}mwg.jpg"); + int length = (int.Parse(locationDigits) - 1) / 4; + string[] segments = + [ + wholePercentages[..1], + wholePercentages.Substring(1, length), + wholePercentages.Substring(3, length), + wholePercentages.Substring(5, length), + wholePercentages.Substring(7, length) + ]; + if (string.Join(string.Empty, segments) == wholePercentages) { + if (int.TryParse(segments[1], out int xWholePercent) + && int.TryParse(segments[2], out int yWholePercent) + && int.TryParse(segments[3], out int wWholePercent) + && int.TryParse(segments[4], out int hWholePercent)) { + float factor = 100; + RectangleF rectangleF = new(xWholePercent / factor, yWholePercent / factor, wWholePercent / factor, hWholePercent / factor); + float rectangleFWidth = rectangleF.Width * width; + float rectangleFHeight = rectangleF.Height * height; + double rectangleFLeft = rectangleF.Left * width; + double rectangleFTop = rectangleF.Top * height; + Extract(file: checkFile, + width: rectangleFWidth, + height: rectangleFHeight, + left: rectangleFLeft, + top: rectangleFTop, + suffix: $"-{i}whole-percentages.jpg"); + } + } + } + + private static void Extract(string file, float width, float height, double left, double top, string suffix) { + RectangleF rectangle = new((float)left, (float)top, width, height); + using (Bitmap source = new(file)) { + using (Bitmap bitmap = new((int)width, (int)height)) { + using (Graphics graphics = Graphics.FromImage(bitmap)) + graphics.DrawImage(source, new RectangleF(0, 0, width, height), rectangle, GraphicsUnit.Pixel); + bitmap.Save($"{file}{suffix}"); + } + } + } +} \ No newline at end of file diff --git a/Day/HelperDay.cs b/Day/HelperDay.cs index f10d1d6..72874b3 100644 --- a/Day/HelperDay.cs +++ b/Day/HelperDay.cs @@ -175,6 +175,8 @@ internal static class HelperDay ADO2025.PI6.Helper20250628.LogIsoInformation(logger, args); else if (args[1] == "Day-Helper-2025-07-01") ADO2025.PI6.Helper20250701.ProcessDataStandardFormatTo(logger, args); + else if (args[1] == "Day-Helper-2025-07-05") + ADO2025.PI6.Helper20250705.ExportFaces(logger, args); else throw new Exception(appSettings.Company); } diff --git a/File-Folder-Helper.csproj b/File-Folder-Helper.csproj index ee3aab8..fbe8106 100644 --- a/File-Folder-Helper.csproj +++ b/File-Folder-Helper.csproj @@ -18,6 +18,7 @@ +