work on color tracker

This commit is contained in:
Boki 2026-02-13 15:01:47 -05:00
parent 03d3fbd1dc
commit 86c7a31231
4 changed files with 176 additions and 6 deletions

View file

@ -9,10 +9,12 @@ public class MinimapCapture : IDisposable
{
private readonly MinimapConfig _config;
private readonly IScreenCapture _backend;
private readonly WallColorTracker _colorTracker;
public MinimapCapture(MinimapConfig config)
{
_config = config;
_colorTracker = new WallColorTracker(config.WallLoHSV, config.WallHiHSV);
_backend = CreateBackend();
}
@ -61,8 +63,8 @@ public class MinimapCapture : IDisposable
Cv2.InRange(hsv, _config.PlayerLoHSV, _config.PlayerHiHSV, playerMask);
var playerOffset = FindCentroid(playerMask);
// Wall mask: target #A2AEE5 blue-lavender structure lines
var wallMask = BuildWallMask(hsv, playerMask);
// Wall mask: target #A2AEE5 blue-lavender structure lines (range adapts per-map)
var wallMask = BuildWallMask(hsv, playerMask, sample: true);
// Build classified mat (walls only — for stitching)
var classified = new Mat(_config.CaptureSize, _config.CaptureSize, MatType.CV_8UC1, Scalar.Black);
@ -82,18 +84,24 @@ public class MinimapCapture : IDisposable
);
}
private Mat BuildWallMask(Mat hsv, Mat playerMask)
private Mat BuildWallMask(Mat hsv, Mat playerMask, bool sample = false)
{
// Target wall color #A2AEE5 — HSV(115, 75, 229)
// This is map-independent: walls are always blue-lavender, fog is higher-saturation blue
// Use adapted range if available (narrows per-map), otherwise broad default
var lo = _colorTracker.AdaptedLo ?? _config.WallLoHSV;
var hi = _colorTracker.AdaptedHi ?? _config.WallHiHSV;
var wallMask = new Mat();
Cv2.InRange(hsv, _config.WallLoHSV, _config.WallHiHSV, wallMask);
Cv2.InRange(hsv, lo, hi, wallMask);
// Subtract player marker (orange overlaps blue range slightly on some maps)
using var notPlayer = new Mat();
Cv2.BitwiseNot(playerMask, notPlayer);
Cv2.BitwiseAnd(wallMask, notPlayer, wallMask);
// Sample from pure color-selected pixels BEFORE morphological ops
if (sample)
_colorTracker.SampleFrame(hsv, wallMask);
// Dilate to connect thin wall line fragments
using var kernel = Cv2.GetStructuringElement(MorphShapes.Ellipse, new Size(3, 3));
Cv2.Dilate(wallMask, wallMask, kernel);
@ -218,6 +226,12 @@ public class MinimapCapture : IDisposable
return new Point2d(cx, cy);
}
/// <summary>Commit pending wall color samples (call after successful template match).</summary>
public void CommitWallColors() => _colorTracker.Commit();
/// <summary>Reset adaptive color tracking (call on area change).</summary>
public void ResetAdaptation() => _colorTracker.Reset();
public void Dispose()
{
_backend.Dispose();