Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Enhance grid capture with auto-cropping, resizing, and detection - #3

Open
codingnooob wants to merge 31 commits into
KroSheChKa:mainfrom
codingnooob:main
Open

codingnooob wants to merge 31 commits into
KroSheChKa:mainfrom
codingnooob:main

Conversation

@codingnooob

Copy link
Copy Markdown

No description provided.

Introduces helper functions to isolate the Graphwar playing field by detecting the largest white rectangular region. Includes isotropic resizing logic to ensure the captured field aligns perfectly with the 1000x600 UI grid without distortion.
Verifies the correctness of the cropping, resizing, and configuration loading functions with synthetic test cases.
Updates the main `capture_game_field` function to apply auto-cropping and resizing. This ensures that every capture is normalized to the target dimensions expected by the approximator UI.
The game field capture now includes an image processing pipeline to standardize the captured screenshot.

It automatically crops the initial client field to the largest near-white rectangular region, isolating the playing grid by removing peripheral UI elements and background noise. The cropped grid is then isotropically resized and centered on a 1000x600 canvas, padding with white, to ensure it precisely matches the approximator UI's dimensions and grid alignment. This prevents distortion and maintains the correct game origin.

Parameters for grid detection and scaling, such as white threshold, morphological operation kernel size, and minimum component area, are now configurable via `config/capture_config.json`.
Introduces functions to automatically detect, crop, and resize the game playing field from raw captures.

`auto_crop_white_grid` identifies the largest near-white region, removing peripheral UI elements and background noise.

`resize_to_grid` isotropically scales the cropped grid to a predefined target resolution (1000x600) and pads it with white to ensure exact alignment with the approximator UI grid, preserving cell dimensions and origin.

Updates default grid capture parameters to include target dimensions and fine-tuned thresholds for white detection and component size.
- Add GRID_CAPTURE_CONFIG_PATH constant for external config file
- Define TARGET_WIDTH/TARGET_HEIGHT for 5:3 aspect ratio (1000x600)
- Add DEFAULT_GRID_CAPTURE_PARAMS with white threshold and kernel size
- Implement load_grid_capture_params() to read config from JSON
- Implement auto_crop_white_grid() to crop to playing field using white mask
- Implement resize_to_grid() to resize isotropically with white padding
- Update game capture logic to use new grid configuration
Update `auto_crop_white_grid` to use morphological dilation and
connected component analysis. This allows the algorithm to bridge
gaps in the white graph caused by black obstacle circles, ensuring
the entire playing field is captured as a single component while
effectively ignoring peripheral UI elements and noise.
Update `resize_to_grid` to use a "fill and crop" strategy instead of
"fit and pad". This ensures the target canvas is always fully covered
by the grid, preventing white borders by symmetrically cropping
overflowing pixels. This maintains the central origin alignment while
ensuring the grid fills the entire viewport.
Aligns the UI canvas dimensions with the natural size of the captured game graph.

The backend now transmits the auto-cropped graph at its native resolution, applying adaptive size caps for pathological dimensions to prevent extreme layouts. The UI dynamically resizes its canvas to precisely match these dimensions, ensuring the graph fills the display without scaling, stretching, or truncation.

Introduces responsive CSS to prevent canvas overflow with large images and optimizes layout for smaller screens by stacking controls. Removes the previous fixed 1000x600 canvas sizing, improving visual fidelity and accuracy.

Includes unit tests for the new size capping logic. A detailed plan outlines the implementation strategy and considerations for this feature.
Integrates automatic detection of enemy players from captured game fields.

The backend now identifies enemy player positions, converts them to game coordinates, sorts them left-to-right, and exposes them in the capture response. Detection failures are handled gracefully, yielding an empty list.

The frontend introduces a new UI toggle (`autoDetectEnemies`) to automatically seed these detected enemies as targets in Dot and Click modes. A dedicated button is also added to manually re-add detected enemies. This enhances usability by streamlining target placement.

Includes new unit tests to validate the enemy detection and sorting logic, and a plan document detailing the feature's design.
Introduces functionality to generate and copy Desmos-compatible formulas for the first and second derivatives (y' and y'').

*   Extends network models (`Sigmoid`, `Taylor`, `Fourier`) and spline models (`CubicSpline`, `B-spline`) with methods to generate Desmos text for their 1st and 2nd derivatives.
*   Implements symbolic Desmos derivative expressions for various MLP activation functions.
*   Adds utility functions for calculating polynomial derivatives and Fourier series derivatives.
*   Prepares UI elements and clipboard copy actions for these new derivative formulas.

This enhances the tool's analysis capabilities, allowing users to inspect slope and concavity in Desmos.
Introduces the ability to copy the 1st and 2nd order derivative formulas of the approximated function to the clipboard in Desmos format.

This enhancement covers various approximation methods:
- Sigmoid networks
- Taylor and Fourier networks (linear cases)
- Piecewise linear approximations (click and dot modes)
- Cubic and B-spline models

New UI buttons for "Copy y'", and "Copy y''" have been added to facilitate easy access to these formulas for analysis or visualization in Desmos.
- Introduces a new "Trajectory Search" (dot mode) with an evolutionary algorithm for pathfinding. Includes dedicated UI controls, visual feedback for population, champion paths, and forbidden zones.
- Refactors SigmoidNetwork and FeatureMlpNetwork training by inlining the trainEpoch logic into the train method, simplifying the training loop and error handling.
- Improves Desmos formula generation for sigmoid and MLP networks, consolidating derivative logic and enhancing spline formula exports (including B-splines).
- Generalizes UI controls and adds interactive help popups for improved user experience.
- Updates the status panel to provide comprehensive, mode-specific information.
Renames calls to `trainEpoch` to `train` within the `createAnimatedNetwork` function. This standardizes the method name used for training across different network approximation methods.
Improves performance and responsiveness of derivative formula generation by implementing direct analytic derivatives for several approximation methods, including Sigmoid, Taylor, Fourier, piecewise linear (Click/Linear), and Spline models.

This significantly reduces reliance on `math.js` for symbolic differentiation, which can be slow for complex expressions.

Also introduces a memoization cache for derivative formulas to prevent redundant calculations, further enhancing user experience. Ensures correct `y'` and `y''` prefixes are used in Desmos formula output.
Add various scripts and text files used for performance benchmarking,
including derivative benchmarking, analysis notebooks, and execution
logs.
Deletes the JavaScript derivative benchmark script, its associated output files, and the Python orchestrator script used for performance profiling and resource monitoring. This infrastructure was part of a temporary performance evaluation setup and is no longer required.
Introduces a new `/api/derive` endpoint to the server, enabling symbolic differentiation of mathematical expressions.

The API leverages Flask to handle requests and uses `symengine` for efficient computation, with `sympy` as a fallback if `symengine` is not available or encounters an error. It accepts an expression and an order of differentiation, returning the computed derivative in a format suitable for JavaScript.
…engines

Implement graceful degradation for sympy and symengine dependencies in
the backend and server. This allows the tools to function even when
symbolic computation libraries are not installed.

- Add conditional import logic to `tools/approximator_server.py`
- Update existing backend tests to skip execution if symbolic engines
  are missing
- Add new test suites for the derivation server and dot mode logic
Refine the visual presentation and drawing logic for the universal
approximator visualization within the p5.js environment.
Restructure the p5.js drawing logic and styling within the universal
approximator module to improve code maintainability and visual
consistency.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant