From 2adfa5d8f84ab35754cff42a8f7f9b7cb4c122c8 Mon Sep 17 00:00:00 2001 From: whoswhip Date: Mon, 16 Jun 2025 19:16:45 -0400 Subject: [PATCH] Add readme, change folder name --- README.md | 164 ++++++++++++++++++++++ Spectrum.sln | 2 +- {ConsoleApp1 => Spectrum}/AutoLabeling.cs | 0 {ConsoleApp1 => Spectrum}/Config.cs | 0 {ConsoleApp1 => Spectrum}/InputManager.cs | 0 {ConsoleApp1 => Spectrum}/Program.cs | 0 {ConsoleApp1 => Spectrum}/Spectrum.csproj | 0 7 files changed, 165 insertions(+), 1 deletion(-) create mode 100644 README.md rename {ConsoleApp1 => Spectrum}/AutoLabeling.cs (100%) rename {ConsoleApp1 => Spectrum}/Config.cs (100%) rename {ConsoleApp1 => Spectrum}/InputManager.cs (100%) rename {ConsoleApp1 => Spectrum}/Program.cs (100%) rename {ConsoleApp1 => Spectrum}/Spectrum.csproj (100%) diff --git a/README.md b/README.md new file mode 100644 index 0000000..1449a28 --- /dev/null +++ b/README.md @@ -0,0 +1,164 @@ +# Spectrum + +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 + +- **Real-time Screen Capture**: Captures specific screen regions for processing +- **HSV Color-based Detection**: Uses HSV color space filtering to detect objects +- **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 + +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: + +### Display Settings +- `ImageWidth`: Width of the capture region (default: 640) +- `ImageHeight`: Height of the capture region (default: 640) +- `ShowDetectionWindow`: Show real-time detection window (default: true) + +### Detection Settings +- `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 +- `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 +- `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 + +```json +{ + "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 + +1. **Start the application**: Run the executable or use `dotnet run` +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 + +- **Escape**: Exit the application +- **F5/R**: Reload configuration from file +- **Configured Keybind**: Activate detection and targeting + +## Dataset Collection + +When `CollectData` and `AutoLabel` are enabled, Spectrum automatically generates: + +- **Images**: Captured screenshots saved to `dataset/images/` +- **Labels**: YOLO format annotation files saved to `dataset/labels/` +- **Background Images**: Non-detection samples for training balance + +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 + +See LICENSE.txt for license information. + +## Disclaimer + +This software is intended for educational and research purposes. Users are responsible for ensuring compliance with applicable laws and terms of service when using this software. The developers assume no responsibility for misuse of this application. + +## Support + +For issues, questions, or feature requests, please open an issue on the project repository. diff --git a/Spectrum.sln b/Spectrum.sln index 213279b..c83e948 100644 --- a/Spectrum.sln +++ b/Spectrum.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio Version 17 VisualStudioVersion = 17.14.36203.30 d17.14 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectrum", "ConsoleApp1\Spectrum.csproj", "{96A01B58-894F-4DFB-97D9-49563FD4BB75}" +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Spectrum", "Spectrum\Spectrum.csproj", "{96A01B58-894F-4DFB-97D9-49563FD4BB75}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/ConsoleApp1/AutoLabeling.cs b/Spectrum/AutoLabeling.cs similarity index 100% rename from ConsoleApp1/AutoLabeling.cs rename to Spectrum/AutoLabeling.cs diff --git a/ConsoleApp1/Config.cs b/Spectrum/Config.cs similarity index 100% rename from ConsoleApp1/Config.cs rename to Spectrum/Config.cs diff --git a/ConsoleApp1/InputManager.cs b/Spectrum/InputManager.cs similarity index 100% rename from ConsoleApp1/InputManager.cs rename to Spectrum/InputManager.cs diff --git a/ConsoleApp1/Program.cs b/Spectrum/Program.cs similarity index 100% rename from ConsoleApp1/Program.cs rename to Spectrum/Program.cs diff --git a/ConsoleApp1/Spectrum.csproj b/Spectrum/Spectrum.csproj similarity index 100% rename from ConsoleApp1/Spectrum.csproj rename to Spectrum/Spectrum.csproj