mirror of
https://github.com/whoswhip/Spectrum.git
synced 2026-12-06 01:28:42 +00:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8b529af9c4 | ||
|
|
aed83ebacd | ||
|
|
206135368a | ||
|
|
77d4b5d21b | ||
|
|
6a6fb2e2ee | ||
|
|
6bb49b90b7 |
@@ -1,159 +1,66 @@
|
|||||||
# Spectrum
|
# Spectrum
|
||||||
|
Spectrum is a semi-universal colorbot that uses C# and OpenCV for image processing.
|
||||||
A real-time computer vision application for object detection and automated targeting using OpenCV and C#. Spectrum captures screen regions, detects objects based on HSV color filtering, and can automatically move the mouse cursor to target detected objects.
|
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
- Extensive configuration file
|
||||||
- **Real-time Screen Capture**: Captures specific screen regions for processing
|
- Dataset collection
|
||||||
- **HSV Color-based Detection**: Uses HSV color space filtering to detect objects
|
- Multiple mouse movement paths
|
||||||
- **Automated Targeting**: Automatically moves mouse cursor to detected targets
|
|
||||||
- **Dataset Collection**: Automatically generates labeled datasets for machine learning
|
|
||||||
- **Configurable Parameters**: Extensive configuration options via JSON file
|
|
||||||
- **Visual Feedback**: Optional detection window showing real-time results
|
|
||||||
- **Hotkey Support**: Configurable keybinding for activation
|
|
||||||
|
|
||||||
## Requirements
|
|
||||||
|
|
||||||
- .NET 8.0 or later
|
|
||||||
- Windows operating system
|
|
||||||
- OpenCV 4.11.0+
|
|
||||||
|
|
||||||
## Installation
|
|
||||||
|
|
||||||
1. Clone the repository:
|
|
||||||
```powershell
|
|
||||||
git clone https://github.com/whoswhip/Spectrum.git
|
|
||||||
cd Spectrum
|
|
||||||
```
|
|
||||||
|
|
||||||
2. Build the project:
|
|
||||||
```powershell
|
|
||||||
dotnet build
|
|
||||||
```
|
|
||||||
|
|
||||||
3. Run the application:
|
|
||||||
```powershell
|
|
||||||
dotnet run --project Spectrum
|
|
||||||
```
|
|
||||||
|
|
||||||
## Configuration
|
## Configuration
|
||||||
|
On first run, a default configuration file is created.
|
||||||
|
### Parameters
|
||||||
|
#### `ImageSettings`
|
||||||
|
`ImageWidth`: 1 - ScreenSize (Default: 640)
|
||||||
|
|
||||||
The application uses a `config.json` file for configuration. On first run, a default configuration file will be created. You can modify the following parameters:
|
`ImageHeight`: 1 - ScreenSize (Default: 640)
|
||||||
|
#### `OffsetSettings
|
||||||
|
`YOffsetPercent`: 0.0 - 1 (Default: 0.8)
|
||||||
|
|
||||||
### Display Settings
|
`XOffsetPercent`: 0.0 - 1 (Default: 0.5)
|
||||||
- `ImageWidth`: Width of the capture region (default: 640)
|
#### `AimSettings`
|
||||||
- `ImageHeight`: Height of the capture region (default: 640)
|
`EnableAim`: true or false (Default: true)
|
||||||
- `ShowDetectionWindow`: Show real-time detection window (default: true)
|
|
||||||
|
|
||||||
### Detection Settings
|
`ClosestToMouse`: true or false (Default: true)
|
||||||
- `UpperHSV`: Upper HSV color bounds for detection
|
|
||||||
- `LowerHSV`: Lower HSV color bounds for detection
|
|
||||||
- `YOffsetPercent`: Y-axis offset percentage for targeting (default: 0.8)
|
|
||||||
- `XOffsetPercent`: X-axis offset percentage for targeting (default: 0.5)
|
|
||||||
|
|
||||||
### Control Settings
|
`Keybind`: 1 - 254 (Default: 6), these are [virtual key codes](https://learn.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes)
|
||||||
- `EnableAim`: Enable automatic mouse movement (default: true)
|
|
||||||
- `ClosestToMouse`: Target closest object to mouse cursor (default: true)
|
|
||||||
- `Keybind`: Activation key code (default: 6 - mouse side button)
|
|
||||||
- `Sensitivity`: Mouse movement sensitivity (default: 0.5)
|
|
||||||
|
|
||||||
### Data Collection
|
`Sensitivity`: 0.1 - 2 (Default: 0.5)
|
||||||
- `CollectData`: Enable dataset collection (default: false)
|
|
||||||
- `AutoLabel`: Enable automatic labeling for YOLO format (default: false)
|
|
||||||
- `BackgroundImageInterval`: Interval for background image collection (default: 10)
|
|
||||||
|
|
||||||
### Example Configuration
|
`AimMovementType`: CubicBezier, Linear & Adaptive (Default: CubicBezier)
|
||||||
|
|
||||||
```json
|
#### `DisplaySettings`
|
||||||
{
|
`ShowDetectionWindow`: true or false (Default: true)
|
||||||
"ImageWidth": 640,
|
|
||||||
"ImageHeight": 640,
|
|
||||||
"YOffsetPercent": 0.8,
|
|
||||||
"XOffsetPercent": 0.5,
|
|
||||||
"EnableAim": true,
|
|
||||||
"ClosestToMouse": true,
|
|
||||||
"Keybind": 6,
|
|
||||||
"Sensitivity": 0.1,
|
|
||||||
"ShowDetectionWindow": true,
|
|
||||||
"CollectData": false,
|
|
||||||
"AutoLabel": false,
|
|
||||||
"BackgroundImageInterval": 10,
|
|
||||||
"UpperHSV": {
|
|
||||||
"Val0": 150.0,
|
|
||||||
"Val1": 255.0,
|
|
||||||
"Val2": 229.0,
|
|
||||||
"Val3": 0.0
|
|
||||||
},
|
|
||||||
"LowerHSV": {
|
|
||||||
"Val0": 150.0,
|
|
||||||
"Val1": 255.0,
|
|
||||||
"Val2": 229.0,
|
|
||||||
"Val3": 0.0
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
## Usage
|
#### `DataCollectionSettings`
|
||||||
|
`CollectData`: true or false (Default: false)
|
||||||
|
|
||||||
1. **Start the application**: Run the executable or use `dotnet run`
|
`AutoLabel`: true or false (Default: false), this is dependent on `CollectData`
|
||||||
2. **Configure detection**: Adjust HSV values in `config.json` for your target objects
|
|
||||||
3. **Activate detection**: Press the configured keybind (default: mouse side button)
|
|
||||||
4. **Real-time targeting**: The application will automatically detect and target objects
|
|
||||||
5. **Reload configuration**: Press F5 or R to reload configuration without restarting
|
|
||||||
|
|
||||||
### Keyboard Controls
|
`BackgroundImageInterval`: 1 - 100 (Default: 10)
|
||||||
|
|
||||||
- **Escape**: Exit the application
|
#### `ColorSettings`
|
||||||
- **F5/R**: Reload configuration from file
|
`UpperHSV`
|
||||||
- **Configured Keybind**: Activate detection and targeting
|
- `Val0`: 0 - 255 (Default: 150) Hue
|
||||||
|
- `Val1`: 0 - 255 (Default: 255) Saturation
|
||||||
|
- `Val2`: 0 - 255 (Default: 229) Value
|
||||||
|
- `Val3`: 0 (Default: 0) ?
|
||||||
|
|
||||||
|
`LowerHSV`
|
||||||
|
- `Val0`: 0 - 255 (Default: 150) Hue
|
||||||
|
- `Val1`: 0 - 255 (Default: 255) Saturation
|
||||||
|
- `Val2`: 0 - 255 (Default: 229) Value
|
||||||
|
- `Val3`: 0 (Default: 0) ?
|
||||||
|
|
||||||
## Dataset Collection
|
## Dataset Collection
|
||||||
|
|
||||||
When `CollectData` and `AutoLabel` are enabled, Spectrum automatically generates:
|
When `CollectData` and `AutoLabel` are enabled, Spectrum automatically generates:
|
||||||
|
- **Images**: Captured screenshots saved to `dataset/images`
|
||||||
- **Images**: Captured screenshots saved to `dataset/images/`
|
- **Labels**: YOLO format annotation files saved to `dataset/labels`
|
||||||
- **Labels**: YOLO format annotation files saved to `dataset/labels/`
|
- **Background Images**: Screenshots without any labels, helps training balance
|
||||||
- **Background Images**: Non-detection samples for training balance
|
This feature is very useful for creating training datasets for machine learning models.
|
||||||
|
|
||||||
This feature is useful for creating training datasets for machine learning models.
|
|
||||||
|
|
||||||
## Technical Details
|
|
||||||
|
|
||||||
### Dependencies
|
|
||||||
|
|
||||||
- **OpenCvSharp4**: OpenCV bindings for .NET
|
|
||||||
- **Newtonsoft.Json**: JSON configuration handling
|
|
||||||
- **System.Drawing.Common**: Screen capture and image processing
|
|
||||||
|
|
||||||
### Architecture
|
|
||||||
|
|
||||||
- **Program.cs**: Main application loop and screen capture
|
|
||||||
- **Config.cs**: Configuration management and validation
|
|
||||||
- **AutoLabeling.cs**: Dataset generation and YOLO labeling
|
|
||||||
- **InputManager.cs**: Mouse input simulation
|
|
||||||
|
|
||||||
### Detection Pipeline
|
|
||||||
|
|
||||||
1. **Screen Capture**: Captures specified screen region
|
|
||||||
2. **Color Space Conversion**: Converts BGR to HSV
|
|
||||||
3. **Color Filtering**: Applies HSV range mask
|
|
||||||
4. **Morphological Operations**: Dilates image to fill gaps
|
|
||||||
5. **Contour Detection**: Finds object boundaries
|
|
||||||
6. **Filtering**: Removes small contours (area < 100)
|
|
||||||
7. **Target Selection**: Chooses closest target to reference point
|
|
||||||
8. **Mouse Movement**: Moves cursor to calculated target position
|
|
||||||
|
|
||||||
## Contributing
|
|
||||||
|
|
||||||
1. Fork the repository
|
|
||||||
2. Create a feature branch
|
|
||||||
3. Make your changes
|
|
||||||
4. Test thoroughly
|
|
||||||
5. Submit a pull request
|
|
||||||
|
|
||||||
## License
|
## License
|
||||||
|
|
||||||
See LICENSE.txt for license information.
|
See [LICENSE.txt](LICENSE.txt) for license information.
|
||||||
|
|
||||||
## Disclaimer
|
## Disclaimer
|
||||||
|
|
||||||
|
|||||||
+143
-34
@@ -6,23 +6,40 @@ namespace Spectrum
|
|||||||
{
|
{
|
||||||
public static class Config
|
public static class Config
|
||||||
{
|
{
|
||||||
|
private static FileSystemWatcher? _configWatcher;
|
||||||
#region Variables
|
#region Variables
|
||||||
|
|
||||||
|
public enum MovementType
|
||||||
|
{
|
||||||
|
Linear,
|
||||||
|
CubicBezier,
|
||||||
|
QuadraticBezier,
|
||||||
|
Adaptive
|
||||||
|
}
|
||||||
|
// Image settings
|
||||||
public static int ImageWidth { get; set; } = 640;
|
public static int ImageWidth { get; set; } = 640;
|
||||||
public static int ImageHeight { get; set; } = 640;
|
public static int ImageHeight { get; set; } = 640;
|
||||||
|
|
||||||
|
// Offset settings
|
||||||
public static double YOffsetPercent { get; set; } = 0.8;
|
public static double YOffsetPercent { get; set; } = 0.8;
|
||||||
public static double XOffsetPercent { get; set; } = 0.5;
|
public static double XOffsetPercent { get; set; } = 0.5;
|
||||||
|
|
||||||
|
// Aim settings
|
||||||
public static bool EnableAim { get; set; } = true;
|
public static bool EnableAim { get; set; } = true;
|
||||||
public static bool ClosestToMouse { get; set; } = true; // if false it will use the center of the screen
|
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 int Keybind { get; set; } = 0x06; // first side button on mouse
|
||||||
public static double Sensitivity { get; set; } = 0.5;
|
public static double Sensitivity { get; set; } = 0.5;
|
||||||
|
public static MovementType AimMovementType { get; set; } = MovementType.CubicBezier;
|
||||||
|
|
||||||
|
// Display settings
|
||||||
public static bool ShowDetectionWindow { get; set; } = true;
|
public static bool ShowDetectionWindow { get; set; } = true;
|
||||||
|
|
||||||
|
// Data collection settings
|
||||||
public static bool CollectData { get; set; } = false;
|
public static bool CollectData { get; set; } = false;
|
||||||
public static bool AutoLabel { get; set; } = false; // collect data needs to be enabled
|
public static bool AutoLabel { get; set; } = false; // collect data needs to be enabled
|
||||||
public static int BackgroundImageInterval { get; set; } = 10; // after 10 loops with no detection, save a background image
|
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);
|
public static Scalar LowerHSV { get; set; } = new Scalar(150, 255, 229);
|
||||||
#endregion
|
#endregion
|
||||||
@@ -31,28 +48,44 @@ namespace Spectrum
|
|||||||
{
|
{
|
||||||
if (File.Exists("config.json"))
|
if (File.Exists("config.json"))
|
||||||
{
|
{
|
||||||
string config_content = File.ReadAllText("config.json");
|
string config_content = File.ReadAllText("config.json");
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
var config = JObject.Parse(config_content);
|
var config = JObject.Parse(config_content);
|
||||||
ImageWidth = config["ImageWidth"]?.Value<int>() ?? ImageWidth;
|
bool error = false;
|
||||||
ImageHeight = config["ImageHeight"]?.Value<int>() ?? ImageHeight;
|
|
||||||
|
var imageSettings = config["ImageSettings"];
|
||||||
|
ImageWidth = imageSettings?["ImageWidth"]?.Value<int>() ?? config["ImageWidth"]?.Value<int>() ?? ImageWidth;
|
||||||
|
ImageHeight = imageSettings?["ImageHeight"]?.Value<int>() ?? config["ImageHeight"]?.Value<int>() ?? ImageHeight;
|
||||||
|
|
||||||
YOffsetPercent = config["YOffsetPercent"]?.Value<double>() ?? YOffsetPercent;
|
var offsetSettings = config["OffsetSettings"];
|
||||||
XOffsetPercent = config["XOffsetPercent"]?.Value<double>() ?? XOffsetPercent;
|
YOffsetPercent = offsetSettings?["YOffsetPercent"]?.Value<double>() ?? config["YOffsetPercent"]?.Value<double>() ?? YOffsetPercent;
|
||||||
EnableAim = config["EnableAim"]?.Value<bool>() ?? EnableAim;
|
XOffsetPercent = offsetSettings?["XOffsetPercent"]?.Value<double>() ?? config["XOffsetPercent"]?.Value<double>() ?? XOffsetPercent;
|
||||||
ClosestToMouse = config["ClosestToMouse"]?.Value<bool>() ?? ClosestToMouse;
|
|
||||||
Keybind = config["Keybind"]?.Value<int>() ?? Keybind;
|
var aimSettings = config["AimSettings"];
|
||||||
Sensitivity = config["Sensitivity"]?.Value<double>() ?? Sensitivity;
|
EnableAim = aimSettings?["EnableAim"]?.Value<bool>() ?? config["EnableAim"]?.Value<bool>() ?? EnableAim;
|
||||||
|
ClosestToMouse = aimSettings?["ClosestToMouse"]?.Value<bool>() ?? config["ClosestToMouse"]?.Value<bool>() ?? ClosestToMouse;
|
||||||
|
Keybind = aimSettings?["Keybind"]?.Value<int>() ?? config["Keybind"]?.Value<int>() ?? Keybind;
|
||||||
|
Sensitivity = aimSettings?["Sensitivity"]?.Value<double>() ?? config["Sensitivity"]?.Value<double>() ?? Sensitivity;
|
||||||
|
AimMovementType = aimSettings?["AimMovementType"]?.Value<string>() switch
|
||||||
|
{
|
||||||
|
"Linear" => MovementType.Linear,
|
||||||
|
"CubicBezier" => MovementType.CubicBezier,
|
||||||
|
"Adaptive" => MovementType.Adaptive,
|
||||||
|
_ => AimMovementType
|
||||||
|
};
|
||||||
|
|
||||||
ShowDetectionWindow = config["ShowDetectionWindow"]?.Value<bool>() ?? ShowDetectionWindow;
|
var displaySettings = config["DisplaySettings"];
|
||||||
|
ShowDetectionWindow = displaySettings?["ShowDetectionWindow"]?.Value<bool>() ?? config["ShowDetectionWindow"]?.Value<bool>() ?? ShowDetectionWindow;
|
||||||
|
|
||||||
CollectData = config["CollectData"]?.Value<bool>() ?? CollectData;
|
var dataSettings = config["DataCollectionSettings"];
|
||||||
AutoLabel = config["AutoLabel"]?.Value<bool>() ?? AutoLabel;
|
CollectData = dataSettings?["CollectData"]?.Value<bool>() ?? config["CollectData"]?.Value<bool>() ?? CollectData;
|
||||||
BackgroundImageInterval = config["BackgroundImageInterval"]?.Value<int>() ?? BackgroundImageInterval;
|
AutoLabel = dataSettings?["AutoLabel"]?.Value<bool>() ?? config["AutoLabel"]?.Value<bool>() ?? AutoLabel;
|
||||||
|
BackgroundImageInterval = dataSettings?["BackgroundImageInterval"]?.Value<int>() ?? config["BackgroundImageInterval"]?.Value<int>() ?? BackgroundImageInterval;
|
||||||
|
|
||||||
UpperHSV = config["UpperHSV"]?.ToObject<Scalar>() ?? UpperHSV;
|
var colorSettings = config["ColorSettings"];
|
||||||
LowerHSV = config["LowerHSV"]?.ToObject<Scalar>() ?? LowerHSV;
|
UpperHSV = colorSettings?["UpperHSV"]?.ToObject<Scalar>() ?? config["UpperHSV"]?.ToObject<Scalar>() ?? UpperHSV;
|
||||||
|
LowerHSV = colorSettings?["LowerHSV"]?.ToObject<Scalar>() ?? config["LowerHSV"]?.ToObject<Scalar>() ?? LowerHSV;
|
||||||
|
|
||||||
if (ImageWidth <= 0 || ImageHeight <= 0)
|
if (ImageWidth <= 0 || ImageHeight <= 0)
|
||||||
{
|
{
|
||||||
@@ -61,6 +94,7 @@ namespace Spectrum
|
|||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
ImageWidth = 640;
|
ImageWidth = 640;
|
||||||
ImageHeight = 640;
|
ImageHeight = 640;
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
if (YOffsetPercent < 0 || YOffsetPercent > 1 || XOffsetPercent < 0 || XOffsetPercent > 1)
|
if (YOffsetPercent < 0 || YOffsetPercent > 1 || XOffsetPercent < 0 || XOffsetPercent > 1)
|
||||||
{
|
{
|
||||||
@@ -69,6 +103,7 @@ namespace Spectrum
|
|||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
YOffsetPercent = 0.8;
|
YOffsetPercent = 0.8;
|
||||||
XOffsetPercent = 0.5;
|
XOffsetPercent = 0.5;
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
if (Keybind < 0 || Keybind > 255)
|
if (Keybind < 0 || Keybind > 255)
|
||||||
{
|
{
|
||||||
@@ -76,13 +111,15 @@ namespace Spectrum
|
|||||||
Console.WriteLine("[ERROR] Invalid keybind in config.json, using default value.");
|
Console.WriteLine("[ERROR] Invalid keybind in config.json, using default value.");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
Keybind = 0x06;
|
Keybind = 0x06;
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
if (Sensitivity < 0 || Sensitivity > 1)
|
if (Sensitivity < 0 || Sensitivity > 2)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine("[ERROR] Invalid sensitivity in config.json, using default value.");
|
Console.WriteLine("[ERROR] Invalid sensitivity in config.json, using default value.");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
Sensitivity = 0.5;
|
Sensitivity = 0.5;
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
if (AutoLabel && !CollectData )
|
if (AutoLabel && !CollectData )
|
||||||
{
|
{
|
||||||
@@ -90,15 +127,18 @@ namespace Spectrum
|
|||||||
Console.WriteLine("[WARNING] AutoLabel is enabled but CollectData is not. Disabling AutoLabel.");
|
Console.WriteLine("[WARNING] AutoLabel is enabled but CollectData is not. Disabling AutoLabel.");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
AutoLabel = false;
|
AutoLabel = false;
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
if (BackgroundImageInterval <= 0)
|
if (BackgroundImageInterval <= 0)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Red;
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
Console.WriteLine("[ERROR] Invalid BackgroundImageInterval in config.json, using default value.");
|
Console.WriteLine("[ERROR] Invalid BackgroundImageInterval in config.json, using default value.");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
|
error = true;
|
||||||
}
|
}
|
||||||
|
if (error)
|
||||||
|
SaveConfig();
|
||||||
|
|
||||||
SaveConfig();
|
|
||||||
if (!silent)
|
if (!silent)
|
||||||
{
|
{
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
@@ -121,27 +161,96 @@ namespace Spectrum
|
|||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
SaveConfig();
|
SaveConfig();
|
||||||
}
|
}
|
||||||
}
|
} public static void SaveConfig()
|
||||||
public static void SaveConfig()
|
|
||||||
{
|
{
|
||||||
var config = new JObject
|
var config = new JObject
|
||||||
{
|
{
|
||||||
["ImageWidth"] = ImageWidth,
|
["ImageSettings"] = new JObject
|
||||||
["ImageHeight"] = ImageHeight,
|
{
|
||||||
["YOffsetPercent"] = YOffsetPercent,
|
["ImageWidth"] = ImageWidth,
|
||||||
["XOffsetPercent"] = XOffsetPercent,
|
["ImageHeight"] = ImageHeight
|
||||||
["EnableAim"] = EnableAim,
|
},
|
||||||
["ClosestToMouse"] = ClosestToMouse,
|
["OffsetSettings"] = new JObject
|
||||||
["Keybind"] = Keybind,
|
{
|
||||||
["Sensitivity"] = Sensitivity,
|
["YOffsetPercent"] = YOffsetPercent,
|
||||||
["ShowDetectionWindow"] = ShowDetectionWindow,
|
["XOffsetPercent"] = XOffsetPercent
|
||||||
["CollectData"] = CollectData,
|
},
|
||||||
["AutoLabel"] = AutoLabel,
|
["AimSettings"] = new JObject
|
||||||
["BackgroundImageInterval"] = BackgroundImageInterval,
|
{
|
||||||
["UpperHSV"] = JToken.FromObject(UpperHSV),
|
["EnableAim"] = EnableAim,
|
||||||
["LowerHSV"] = JToken.FromObject(LowerHSV)
|
["ClosestToMouse"] = ClosestToMouse,
|
||||||
|
["Keybind"] = Keybind,
|
||||||
|
["Sensitivity"] = Sensitivity,
|
||||||
|
["AimMovementType"] = AimMovementType.ToString()
|
||||||
|
},
|
||||||
|
["DisplaySettings"] = new JObject
|
||||||
|
{
|
||||||
|
["ShowDetectionWindow"] = ShowDetectionWindow
|
||||||
|
},
|
||||||
|
["DataCollectionSettings"] = new JObject
|
||||||
|
{
|
||||||
|
["CollectData"] = CollectData,
|
||||||
|
["AutoLabel"] = AutoLabel,
|
||||||
|
["BackgroundImageInterval"] = BackgroundImageInterval
|
||||||
|
},
|
||||||
|
["ColorSettings"] = new JObject
|
||||||
|
{
|
||||||
|
["UpperHSV"] = JToken.FromObject(UpperHSV),
|
||||||
|
["LowerHSV"] = JToken.FromObject(LowerHSV)
|
||||||
|
}
|
||||||
|
}; File.WriteAllText("config.json", config.ToString(Formatting.Indented));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StartFileWatcher()
|
||||||
|
{
|
||||||
|
if (_configWatcher != null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
_configWatcher = new FileSystemWatcher(Directory.GetCurrentDirectory(), "config.json")
|
||||||
|
{
|
||||||
|
NotifyFilter = NotifyFilters.LastWrite | NotifyFilters.Size
|
||||||
};
|
};
|
||||||
File.WriteAllText("config.json", config.ToString(Formatting.Indented));
|
|
||||||
|
_configWatcher.Changed += OnConfigFileChanged;
|
||||||
|
_configWatcher.EnableRaisingEvents = true;
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine("[INFO] File watcher started for config.json");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void StopFileWatcher()
|
||||||
|
{
|
||||||
|
if (_configWatcher != null)
|
||||||
|
{
|
||||||
|
_configWatcher.EnableRaisingEvents = false;
|
||||||
|
_configWatcher.Changed -= OnConfigFileChanged;
|
||||||
|
_configWatcher.Dispose();
|
||||||
|
_configWatcher = null;
|
||||||
|
|
||||||
|
Console.ForegroundColor = ConsoleColor.Cyan;
|
||||||
|
Console.WriteLine("[INFO] File watcher stopped for config.json");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void OnConfigFileChanged(object sender, FileSystemEventArgs e)
|
||||||
|
{
|
||||||
|
Thread.Sleep(100);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
LoadConfig(true);
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[INFO] Configuration automatically reloaded due to file change.");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine($"[ERROR] Failed to reload configuration: {ex.Message}");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ namespace Spectrum
|
|||||||
public int X;
|
public int X;
|
||||||
public int Y;
|
public int Y;
|
||||||
}
|
}
|
||||||
// AIMMY V2 CODE - https://github.com/babyhamsta/Aimmy/blob/Aimmy-V2/Aimmy2/InputLogic/MouseManager.cs Line 34 - 50
|
// AIMMY V2 CODE - https://github.com/Babyhamsta/Aimmy/blob/2e906552673e359ded90383c5e97d79c8f38a2f2/Aimmy2/InputLogic/MouseManager.cs#L34-L50
|
||||||
private static Point CubicBezier(Point start, Point end, Point control1, Point control2, double t)
|
private static Point CubicBezier(Point start, Point end, Point control1, Point control2, double t)
|
||||||
{
|
{
|
||||||
double u = 1 - t;
|
double u = 1 - t;
|
||||||
@@ -28,6 +28,47 @@ namespace Spectrum
|
|||||||
|
|
||||||
return new Point((int)x, (int)y);
|
return new Point((int)x, (int)y);
|
||||||
}
|
}
|
||||||
|
private static Point CubicBezierMovement(Point start, Point end, double t)
|
||||||
|
{
|
||||||
|
Point control1 = new Point(start.X + (end.X - start.X) / 3, start.Y + (end.Y - start.Y) / 3);
|
||||||
|
Point control2 = new Point(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (end.Y - start.Y) / 3);
|
||||||
|
return CubicBezier(start, end, control1, control2, t);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point LinearInterpolation(Point start, Point end, double t)
|
||||||
|
{
|
||||||
|
int x = (int)(start.X + t * (end.X - start.X));
|
||||||
|
int y = (int)(start.Y + t * (end.Y - start.Y));
|
||||||
|
return new Point(x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point CurvedMovement(Point start, Point end, double t)
|
||||||
|
{
|
||||||
|
Point control = new Point((start.X + end.X) / 2, (start.Y + end.Y) / 2 - 200);
|
||||||
|
return QuadraticBezier(start, end, control, t);
|
||||||
|
}
|
||||||
|
private static Point QuadraticBezier(Point start, Point end, Point control, double t)
|
||||||
|
{
|
||||||
|
double u = 1 - t;
|
||||||
|
double tt = t * t;
|
||||||
|
double uu = u * u;
|
||||||
|
double x = uu * start.X + 2 * u * t * control.X + tt * end.X;
|
||||||
|
double y = uu * start.Y + 2 * u * t * control.Y + tt * end.Y;
|
||||||
|
return new Point((int)x, (int)y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static Point AdaptiveMovement(Point start, Point end, double sensitivity)
|
||||||
|
{
|
||||||
|
double distance = Math.Sqrt(Math.Pow(end.X - start.X, 2) + Math.Pow(end.Y - start.Y, 2));
|
||||||
|
double stepSize = distance * sensitivity;
|
||||||
|
|
||||||
|
double directionX = (end.X - start.X) / distance;
|
||||||
|
double directionY = (end.Y - start.Y) / distance;
|
||||||
|
|
||||||
|
int newX = (int)(start.X + directionX * stepSize);
|
||||||
|
int newY = (int)(start.Y + directionY * stepSize);
|
||||||
|
return new Point(newX, newY);
|
||||||
|
}
|
||||||
|
|
||||||
public static void MoveMouse(Point target)
|
public static void MoveMouse(Point target)
|
||||||
{
|
{
|
||||||
@@ -47,9 +88,14 @@ namespace Spectrum
|
|||||||
|
|
||||||
Point start = new Point(reference.X, reference.Y);
|
Point start = new Point(reference.X, reference.Y);
|
||||||
Point end = new Point(target.X, target.Y);
|
Point end = new Point(target.X, target.Y);
|
||||||
Point control1 = new(start.X + (end.X - start.X) / 3, start.Y + (end.Y - start.Y) / 3);
|
Point newPosition = Config.AimMovementType switch
|
||||||
Point control2 = new(start.X + 2 * (end.X - start.X) / 3, start.Y + 2 * (end.Y - start.Y) / 3);
|
{
|
||||||
Point newPosition = CubicBezier(start, end, control1, control2, Config.Sensitivity);
|
Config.MovementType.CubicBezier => CubicBezierMovement(start, end, Config.Sensitivity),
|
||||||
|
Config.MovementType.Linear => LinearInterpolation(start, end, Config.Sensitivity),
|
||||||
|
Config.MovementType.Adaptive => AdaptiveMovement(start, end, Config.Sensitivity),
|
||||||
|
Config.MovementType.QuadraticBezier => CurvedMovement(start, end, Config.Sensitivity),
|
||||||
|
_ => end
|
||||||
|
};
|
||||||
|
|
||||||
int deltaX = newPosition.X - reference.X;
|
int deltaX = newPosition.X - reference.X;
|
||||||
int deltaY = newPosition.Y - reference.Y;
|
int deltaY = newPosition.Y - reference.Y;
|
||||||
|
|||||||
+124
-5
@@ -12,6 +12,9 @@ namespace Spectrum
|
|||||||
static void Main()
|
static void Main()
|
||||||
{
|
{
|
||||||
Config.LoadConfig();
|
Config.LoadConfig();
|
||||||
|
Config.StartFileWatcher();
|
||||||
|
|
||||||
|
|
||||||
var screenSize = SystemHelper.GetPrimaryScreenSize();
|
var screenSize = SystemHelper.GetPrimaryScreenSize();
|
||||||
bounds = new Rectangle(
|
bounds = new Rectangle(
|
||||||
(screenSize.Width - Config.ImageWidth) / 2,
|
(screenSize.Width - Config.ImageWidth) / 2,
|
||||||
@@ -45,12 +48,125 @@ namespace Spectrum
|
|||||||
{
|
{
|
||||||
Cv2.DestroyAllWindows();
|
Cv2.DestroyAllWindows();
|
||||||
}
|
}
|
||||||
|
Config.StopFileWatcher();
|
||||||
|
Environment.Exit(0);
|
||||||
}
|
}
|
||||||
else if (key == ConsoleKey.F5 || key == ConsoleKey.R)
|
else if (key == ConsoleKey.O)
|
||||||
{
|
{
|
||||||
Config.LoadConfig(true);
|
try
|
||||||
Console.ForegroundColor = ConsoleColor.Green;
|
{
|
||||||
Console.WriteLine("[INFO] Configuration reloaded.");
|
string configFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "config.json");
|
||||||
|
System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo
|
||||||
|
{
|
||||||
|
FileName = configFilePath,
|
||||||
|
UseShellExecute = true,
|
||||||
|
CreateNoWindow = true
|
||||||
|
});
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[INFO] Opened config file in default application.");
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Console.WriteLine($"Failed to open config file: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (key == ConsoleKey.F1)
|
||||||
|
{
|
||||||
|
Config.ShowDetectionWindow = !Config.ShowDetectionWindow;
|
||||||
|
if (Config.ShowDetectionWindow)
|
||||||
|
{
|
||||||
|
Cv2.NamedWindow("Spectrum Detection", WindowFlags.AutoSize);
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[INFO] Enabled detection window.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Cv2.DestroyAllWindows();
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[INFO] Disabled detection window.");
|
||||||
|
}
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else if (key == ConsoleKey.F2)
|
||||||
|
{
|
||||||
|
Config.AutoLabel = !Config.AutoLabel;
|
||||||
|
if (Config.AutoLabel)
|
||||||
|
{
|
||||||
|
Config.CollectData = true;
|
||||||
|
AutoLabeling.StartLabeling();
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[INFO] Enabled auto-labeling.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
AutoLabeling.StopLabeling();
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[INFO] Disabled auto-labeling.");
|
||||||
|
}
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else if (key == ConsoleKey.F3)
|
||||||
|
{
|
||||||
|
Config.CollectData = !Config.CollectData;
|
||||||
|
if (Config.CollectData)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[INFO] Enabled data collection.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[INFO] Disabled data collection.");
|
||||||
|
}
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else if (key == ConsoleKey.F4)
|
||||||
|
{
|
||||||
|
Config.EnableAim = !Config.EnableAim;
|
||||||
|
if (Config.EnableAim)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[INFO] Enabled aiming.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[INFO] Disabled aiming.");
|
||||||
|
}
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else if (key == ConsoleKey.F5)
|
||||||
|
{
|
||||||
|
Config.ClosestToMouse = !Config.ClosestToMouse;
|
||||||
|
if (Config.ClosestToMouse)
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Green;
|
||||||
|
Console.WriteLine("[INFO] Enabled closest to mouse aiming.");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Red;
|
||||||
|
Console.WriteLine("[INFO] Disabled closest to mouse aiming.");
|
||||||
|
}
|
||||||
|
Console.ResetColor();
|
||||||
|
}
|
||||||
|
else if (key == ConsoleKey.H || key == ConsoleKey.Help)
|
||||||
|
{
|
||||||
|
Console.WriteLine("Spectrum Keybinds:");
|
||||||
|
Console.WriteLine("F1: Toggle detection window");
|
||||||
|
Console.WriteLine("F2: Toggle auto-labeling");
|
||||||
|
Console.WriteLine("F3: Toggle data collection");
|
||||||
|
Console.WriteLine("F4: Toggle aiming");
|
||||||
|
Console.WriteLine("F5: Toggle closest to mouse aiming");
|
||||||
|
Console.WriteLine("O: Open config file in default application");
|
||||||
|
Console.WriteLine("ESC: Exit the application");
|
||||||
|
Console.WriteLine("H: Show this help message");
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Console.ForegroundColor = ConsoleColor.Yellow;
|
||||||
|
Console.WriteLine("[WARNING] Unrecognized key pressed. Press H for help.");
|
||||||
Console.ResetColor();
|
Console.ResetColor();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -117,6 +233,10 @@ namespace Spectrum
|
|||||||
AutoLabeling.AddToQueue(drawing, bounds, filteredContours);
|
AutoLabeling.AddToQueue(drawing, bounds, filteredContours);
|
||||||
AutoLabeling.AddBackgroundImage(drawing, true);
|
AutoLabeling.AddBackgroundImage(drawing, true);
|
||||||
}
|
}
|
||||||
|
if (!Config.AutoLabel && Config.CollectData)
|
||||||
|
{
|
||||||
|
AutoLabeling.AddBackgroundImage(drawing, false);
|
||||||
|
}
|
||||||
|
|
||||||
if (Config.EnableAim)
|
if (Config.EnableAim)
|
||||||
{
|
{
|
||||||
@@ -125,7 +245,6 @@ namespace Spectrum
|
|||||||
|
|
||||||
if (Config.ShowDetectionWindow)
|
if (Config.ShowDetectionWindow)
|
||||||
{
|
{
|
||||||
Cv2.DrawContours(drawing, filteredContours, -1, Scalar.Red, 2);
|
|
||||||
Cv2.Rectangle(drawing, new OpenCvSharp.Point(bestMinX, bestMinY), new OpenCvSharp.Point(bestMaxX, bestMaxY), Scalar.Blue, 2);
|
Cv2.Rectangle(drawing, new OpenCvSharp.Point(bestMinX, bestMinY), new OpenCvSharp.Point(bestMaxX, bestMaxY), Scalar.Blue, 2);
|
||||||
Cv2.ImShow("Spectrum Detection", drawing);
|
Cv2.ImShow("Spectrum Detection", drawing);
|
||||||
Cv2.WaitKey(1);
|
Cv2.WaitKey(1);
|
||||||
|
|||||||
@@ -0,0 +1,24 @@
|
|||||||
|
Microsoft Visual Studio Solution File, Format Version 12.00
|
||||||
|
# Visual Studio Version 17
|
||||||
|
VisualStudioVersion = 17.5.2.0
|
||||||
|
MinimumVisualStudioVersion = 10.0.40219.1
|
||||||
|
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectrum", "Spectrum.csproj", "{C33459B7-8D67-9FB2-0CDB-25002B06AE60}"
|
||||||
|
EndProject
|
||||||
|
Global
|
||||||
|
GlobalSection(SolutionConfigurationPlatforms) = preSolution
|
||||||
|
Debug|Any CPU = Debug|Any CPU
|
||||||
|
Release|Any CPU = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ProjectConfigurationPlatforms) = postSolution
|
||||||
|
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||||
|
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||||
|
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||||
|
{C33459B7-8D67-9FB2-0CDB-25002B06AE60}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(SolutionProperties) = preSolution
|
||||||
|
HideSolutionNode = FALSE
|
||||||
|
EndGlobalSection
|
||||||
|
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||||
|
SolutionGuid = {44E9592E-6BC3-403A-9503-398EC3EFC57C}
|
||||||
|
EndGlobalSection
|
||||||
|
EndGlobal
|
||||||
Reference in New Issue
Block a user