added filter for text

This commit is contained in:
Boki 2026-02-13 13:27:46 -05:00
parent dab5735c80
commit 7fd80b1645
3 changed files with 36 additions and 8 deletions

View file

@ -11,6 +11,7 @@ public class WorldMap : IDisposable
private readonly Mat _confidence; // CV_16SC1: per-pixel wall confidence counter
private MapPosition _position;
private int _frameCount;
private int _consecutiveMatchFails;
private Mat? _prevWallMask; // for frame deduplication
public MapPosition Position => _position;
@ -68,11 +69,13 @@ public class WorldMap : IDisposable
if (matched == null)
{
Log.Information("MatchAndStitch: dedup={Dedup:F1}ms match={Match:F1}ms (FAILED) total={Total:F1}ms",
dedupMs, matchMs, sw.Elapsed.TotalMilliseconds);
return _position; // skip stitching entirely on failed match
_consecutiveMatchFails++;
Log.Information("MatchAndStitch: dedup={Dedup:F1}ms match={Match:F1}ms (FAILED x{Fails}) total={Total:F1}ms",
dedupMs, matchMs, _consecutiveMatchFails, sw.Elapsed.TotalMilliseconds);
return _position; // don't stitch — wrong position would corrupt the canvas
}
_consecutiveMatchFails = 0;
_position = matched;
var stitchStart = sw.Elapsed.TotalMilliseconds;
StitchWithConfidence(classifiedMat, _position, boosted: false);
@ -115,8 +118,13 @@ public class WorldMap : IDisposable
// Check if canvas has enough walls to match against
var canvasWallCount = Cv2.CountNonZero(canvasWalls);
var frameWallCount = Cv2.CountNonZero(wallMask);
if (canvasWallCount < 50)
{
Log.Information("Match fail: too few canvas walls ({CanvasWalls}) frame walls={FrameWalls}",
canvasWallCount, frameWallCount);
return null;
}
// Template match: find where frame's walls best align with canvas walls
using var result = new Mat();
@ -125,7 +133,8 @@ public class WorldMap : IDisposable
if (maxVal < _config.MatchConfidence)
{
Log.Debug("Map match low confidence: {Conf:F3}", maxVal);
Log.Information("Match fail: low confidence {Conf:F3} (need {Min:F2}) canvas={CanvasWalls} frame={FrameWalls}",
maxVal, _config.MatchConfidence, canvasWallCount, frameWallCount);
return null;
}
@ -134,8 +143,8 @@ public class WorldMap : IDisposable
var matchX = sx0 + maxLoc.X + frameSize / 2.0;
var matchY = sy0 + maxLoc.Y + frameSize / 2.0;
Log.Debug("Map match: ({X:F1}, {Y:F1}) conf={Conf:F3} walls={Walls}",
matchX, matchY, maxVal, canvasWallCount);
Log.Debug("Map match: ({X:F1}, {Y:F1}) conf={Conf:F3} canvas={CanvasWalls} frame={FrameWalls}",
matchX, matchY, maxVal, canvasWallCount, frameWallCount);
return new MapPosition(matchX, matchY);
}
@ -177,7 +186,7 @@ public class WorldMap : IDisposable
if (srcVal == (byte)MapCell.Wall)
{
if (boosted)
conf = confThreshold; // warmup: immediately at threshold
conf = confMax; // warmup: max confidence so walls survive initial movement
else
conf = Math.Min((short)(conf + confInc), confMax);
}
@ -312,6 +321,7 @@ public class WorldMap : IDisposable
_prevWallMask = null;
_position = new MapPosition(_config.CanvasSize / 2.0, _config.CanvasSize / 2.0);
_frameCount = 0;
_consecutiveMatchFails = 0;
}
public void Dispose()