Optimizations and fix memory leak/build up by disposing the mats

This commit is contained in:
whoswhip
2025-06-17 21:11:01 -04:00
parent 8b529af9c4
commit f8b90d7b63
3 changed files with 15 additions and 4 deletions
+8 -1
View File
@@ -114,11 +114,15 @@ namespace Spectrum
}
}
public static void AddToQueue(Mat mat, Rectangle bounds, OpenCvSharp.Point[][] filteredContours)
{
if (!Config.AutoLabel || filteredContours.Length == 0)
return;
if (labelingQueue.Count > 250)
return;
Mat clone = mat.Clone();
labelingQueue.Enqueue(new LabelingData
{
@@ -138,6 +142,9 @@ namespace Spectrum
if (detectionAttemps < Config.BackgroundImageInterval || detected)
return;
if (backgroundQueue.Count > 250)
return;
Mat clone = mat.Clone();
backgroundQueue.Enqueue(new BackgroundImageData
{
+1 -1
View File
@@ -29,7 +29,7 @@ namespace Spectrum
public static bool ClosestToMouse { get; set; } = true; // if false it will use the center of the screen
public static int Keybind { get; set; } = 0x06; // first side button on mouse
public static double Sensitivity { get; set; } = 0.5;
public static MovementType AimMovementType { get; set; } = MovementType.CubicBezier;
public static MovementType AimMovementType { get; set; } = MovementType.Adaptive;
// Display settings
public static bool ShowDetectionWindow { get; set; } = true;
+6 -2
View File
@@ -14,7 +14,6 @@ namespace Spectrum
Config.LoadConfig();
Config.StartFileWatcher();
var screenSize = SystemHelper.GetPrimaryScreenSize();
bounds = new Rectangle(
(screenSize.Width - Config.ImageWidth) / 2,
@@ -251,11 +250,16 @@ namespace Spectrum
}
}
}
else if (Config.ShowDetectionWindow)
else if (Config.ShowDetectionWindow || Config.CollectData)
{
Cv2.ImShow("Spectrum Detection", drawing);
Cv2.WaitKey(1);
if (Config.CollectData)
AutoLabeling.AddBackgroundImage(drawing, false);
}
screenshot?.Dispose();
mat.Dispose();
drawing.Dispose();
}
else
{