From dd13b99249f888e228c15e6e2938cb49d421bdb3 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Wed, 18 Jun 2025 13:41:31 -0400 Subject: [PATCH] Clean up code --- Spectrum/AutoLabeling.cs | 6 +----- Spectrum/Config.cs | 15 ++++++++------- Spectrum/Program.cs | 1 - 3 files changed, 9 insertions(+), 13 deletions(-) diff --git a/Spectrum/AutoLabeling.cs b/Spectrum/AutoLabeling.cs index 369ea47..5177ba5 100644 --- a/Spectrum/AutoLabeling.cs +++ b/Spectrum/AutoLabeling.cs @@ -1,11 +1,7 @@ using OpenCvSharp; -using System; using System.Collections.Concurrent; -using System.Collections.Generic; using System.Drawing; -using System.Linq; using System.Text; -using System.Threading.Tasks; namespace Spectrum { @@ -123,7 +119,7 @@ namespace Spectrum if (labelingQueue.Count > 250) return; - Mat clone = mat.Clone(); + Mat clone = mat.Clone(); labelingQueue.Enqueue(new LabelingData { Mat = clone, diff --git a/Spectrum/Config.cs b/Spectrum/Config.cs index b71357a..d2f8367 100644 --- a/Spectrum/Config.cs +++ b/Spectrum/Config.cs @@ -40,7 +40,7 @@ namespace Spectrum public static int BackgroundImageInterval { get; set; } = 10; // after 10 loops with no detection, save a background image // Color settings - public static Scalar UpperHSV { get; set; } = new Scalar(150, 255, 229); + public static Scalar UpperHSV { get; set; } = new Scalar(150, 255, 229); public static Scalar LowerHSV { get; set; } = new Scalar(150, 255, 229); #endregion @@ -48,12 +48,12 @@ namespace Spectrum { if (File.Exists("config.json")) { - string config_content = File.ReadAllText("config.json"); + string config_content = File.ReadAllText("config.json"); try { var config = JObject.Parse(config_content); bool error = false; - + var imageSettings = config["ImageSettings"]; ImageWidth = imageSettings?["ImageWidth"]?.Value() ?? config["ImageWidth"]?.Value() ?? ImageWidth; ImageHeight = imageSettings?["ImageHeight"]?.Value() ?? config["ImageHeight"]?.Value() ?? ImageHeight; @@ -61,7 +61,7 @@ namespace Spectrum var offsetSettings = config["OffsetSettings"]; YOffsetPercent = offsetSettings?["YOffsetPercent"]?.Value() ?? config["YOffsetPercent"]?.Value() ?? YOffsetPercent; XOffsetPercent = offsetSettings?["XOffsetPercent"]?.Value() ?? config["XOffsetPercent"]?.Value() ?? XOffsetPercent; - + var aimSettings = config["AimSettings"]; EnableAim = aimSettings?["EnableAim"]?.Value() ?? config["EnableAim"]?.Value() ?? EnableAim; ClosestToMouse = aimSettings?["ClosestToMouse"]?.Value() ?? config["ClosestToMouse"]?.Value() ?? ClosestToMouse; @@ -121,7 +121,7 @@ namespace Spectrum Sensitivity = 0.5; error = true; } - if (AutoLabel && !CollectData ) + if (AutoLabel && !CollectData) { Console.ForegroundColor = ConsoleColor.Yellow; Console.WriteLine("[WARNING] AutoLabel is enabled but CollectData is not. Disabling AutoLabel."); @@ -161,7 +161,8 @@ namespace Spectrum Console.ResetColor(); SaveConfig(); } - } public static void SaveConfig() + } + public static void SaveConfig() { var config = new JObject { @@ -198,7 +199,7 @@ namespace Spectrum ["UpperHSV"] = JToken.FromObject(UpperHSV), ["LowerHSV"] = JToken.FromObject(LowerHSV) } - }; File.WriteAllText("config.json", config.ToString(Formatting.Indented)); + }; File.WriteAllText("config.json", config.ToString(Formatting.Indented)); } public static void StartFileWatcher() diff --git a/Spectrum/Program.cs b/Spectrum/Program.cs index 26ec0e6..79fdc2f 100644 --- a/Spectrum/Program.cs +++ b/Spectrum/Program.cs @@ -1,5 +1,4 @@ using OpenCvSharp; -using OpenCvSharp.Internal.Vectors; using System.Drawing; using System.Drawing.Imaging; using System.Runtime.InteropServices;