From d7948fd4a7a01f3a10fbd79843a6139b5a40f9fd Mon Sep 17 00:00:00 2001 From: Boki Date: Sun, 15 Feb 2026 10:51:15 -0500 Subject: [PATCH] fixed minimap mode switching --- src/Poe2Trade.Navigation/MinimapCapture.cs | 8 ++++++- src/Poe2Trade.Navigation/WorldMap.cs | 28 +++++++++++++++++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/Poe2Trade.Navigation/MinimapCapture.cs b/src/Poe2Trade.Navigation/MinimapCapture.cs index da5630f..82c216c 100644 --- a/src/Poe2Trade.Navigation/MinimapCapture.cs +++ b/src/Poe2Trade.Navigation/MinimapCapture.cs @@ -37,8 +37,9 @@ public class MinimapCapture : IFrameConsumer, IDisposable var detected = DetectMinimapMode(screen); if (detected != _detectedMode) { + var oldMode = _detectedMode; _detectedMode = detected; - Log.Information("Minimap mode switched to {Mode}", _detectedMode); + Log.Information("MODE SWITCH: {Old} → {New}", oldMode, _detectedMode); ResetAdaptation(); ModeChanged?.Invoke(_detectedMode); } @@ -55,6 +56,11 @@ public class MinimapCapture : IFrameConsumer, IDisposable var frame = ProcessBgr(bgr); if (frame == null) return; + Log.Debug("Process: mode={Mode} cropSize={W}x{H} classifiedSize={CW}x{CH} wallSize={WW}x{WH}", + _detectedMode, bgr.Width, bgr.Height, + frame.ClassifiedMat.Width, frame.ClassifiedMat.Height, + frame.WallMask.Width, frame.WallMask.Height); + var old = Interlocked.Exchange(ref _lastFrame, frame); old?.Dispose(); } diff --git a/src/Poe2Trade.Navigation/WorldMap.cs b/src/Poe2Trade.Navigation/WorldMap.cs index e376aaf..5d21465 100644 --- a/src/Poe2Trade.Navigation/WorldMap.cs +++ b/src/Poe2Trade.Navigation/WorldMap.cs @@ -38,6 +38,10 @@ public class WorldMap : IDisposable var warmupFrames = isCorner ? 2 : _config.WarmupFrames; var needsBootstrap = _frameCount <= warmupFrames || _consecutiveMatchFails >= 30; + Log.Debug("MatchAndStitch: frame#{N} mode={Mode} frameSize={W}x{H} pos=({X:F1},{Y:F1}) bootstrap={Boot} prevWallMask={HasPrev}", + _frameCount, mode, wallMask.Width, wallMask.Height, + _position.X, _position.Y, needsBootstrap, _prevWallMask != null); + // Block-based noise filter: only needed for overlay (game effects bleed through) if (!isCorner) { @@ -147,10 +151,17 @@ public class WorldMap : IDisposable // Check if canvas has enough walls to match against var canvasWallCount = Cv2.CountNonZero(canvasWalls); var frameWallCount = Cv2.CountNonZero(wallMask); + if (frameWallCount < 50) + { + Log.Information("Match fail: too few frame walls ({FrameWalls}) frameSize={FS}", + frameWallCount, frameSize); + return null; + } + if (canvasWallCount < 50) { - Log.Information("Match fail: too few canvas walls ({CanvasWalls}) frame walls={FrameWalls}", - canvasWallCount, frameWallCount); + Log.Information("Match fail: too few canvas walls ({CanvasWalls}) frame walls={FrameWalls} frameSize={FS} searchROI={SW}x{SH}", + canvasWallCount, frameWallCount, frameSize, sw, sh); return null; } @@ -161,8 +172,8 @@ public class WorldMap : IDisposable if (maxVal < _config.MatchConfidence) { - Log.Information("Match fail: low confidence {Conf:F3} (need {Min:F2}) canvas={CanvasWalls} frame={FrameWalls}", - maxVal, _config.MatchConfidence, canvasWallCount, frameWallCount); + Log.Information("Match fail: low confidence {Conf:F3} (need {Min:F2}) frameSize={FS} searchROI={SW}x{SH} canvas={CanvasWalls} frame={FrameWalls}", + maxVal, _config.MatchConfidence, frameSize, sw, sh, canvasWallCount, frameWallCount); return null; } @@ -171,8 +182,10 @@ public class WorldMap : IDisposable var matchX = sx0 + maxLoc.X + frameSize / 2.0; var matchY = sy0 + maxLoc.Y + frameSize / 2.0; - Log.Information("Match OK: conf={Conf:F3} pos=({X:F1},{Y:F1}) canvas={CanvasWalls} frame={FrameWalls}", - maxVal, matchX, matchY, canvasWallCount, frameWallCount); + var deltaX = matchX - estimate.X; + var deltaY = matchY - estimate.Y; + Log.Information("Match OK: conf={Conf:F3} pos=({X:F1},{Y:F1}) delta=({Dx:F1},{Dy:F1}) frameSize={FS} searchROI={SW}x{SH} canvas={CanvasWalls} frame={FrameWalls}", + maxVal, matchX, matchY, deltaX, deltaY, frameSize, sw, sh, canvasWallCount, frameWallCount); return new MapPosition(matchX, matchY); } @@ -511,6 +524,9 @@ public class WorldMap : IDisposable /// public void Rebootstrap() { + Log.Information("Rebootstrap: frameCount={N} pos=({X:F1},{Y:F1}) matchFails={Fails} prevWallMask={Size}", + _frameCount, _position.X, _position.Y, _consecutiveMatchFails, + _prevWallMask != null ? $"{_prevWallMask.Width}x{_prevWallMask.Height}" : "null"); _prevWallMask?.Dispose(); _prevWallMask = null; // Don't reset _frameCount or _consecutiveMatchFails —