Analyze frames for LED spline sweep quality
This commit is contained in:
parent
ae5cebf20a
commit
62df36c85c
6 changed files with 303 additions and 4 deletions
|
|
@ -399,6 +399,11 @@ a named invariant that the native runtime cannot protect yet.
|
|||
fitness, and saturation penalty. `--led-spline-quality-sweep-smoke` proves
|
||||
the selector chooses the balanced setting over both underexposed missing-LED
|
||||
detections and overexposed saturated halos.
|
||||
`MimirLedSplineFrameAnalyzer` is the frame-level bridge for physical sweeps:
|
||||
it reads luma frames, extracts bright connected components as LED candidates,
|
||||
solves the per-sensor curve, and emits the same spline quality report.
|
||||
`--led-spline-frame-analysis-smoke` proves clipped blobs can still be
|
||||
detected while scoring as unusable calibration evidence.
|
||||
Phase 6 program-output receipts are also structurally complete: Fensalir
|
||||
publishes the final program surface through named shared D3D12 texture/fence
|
||||
resources, the OBS plugin consumes that surface with an explicit D3D12-to-
|
||||
|
|
|
|||
|
|
@ -624,9 +624,12 @@ sweeps are scored by the recovered spline, not raw brightness:
|
|||
`MimirLedSplineQualityScorer` combines detected LED count, curve coverage,
|
||||
spacing coherence, smoothness, exposure fitness, and saturation penalty, and
|
||||
`MimirLedSplineSweepSelector` picks the best calibration-usable setting. Once
|
||||
the frustum fit is coherent, detected surface candidates can be sampled across
|
||||
every synchronized view before Fensalir resolves them into 4D Gaussian/surface
|
||||
splat claims.
|
||||
`MimirLedSplineFrameAnalyzer` connects physical frames to that score by
|
||||
extracting bright luma components, solving the sensor-local curve, and rejecting
|
||||
clipped blobs as unusable calibration evidence even when they are easy to
|
||||
detect. Once the frustum fit is coherent, detected surface candidates can be
|
||||
sampled across every synchronized view before Fensalir resolves them into 4D
|
||||
Gaussian/surface splat claims.
|
||||
|
||||
The current teardown/migration map is
|
||||
`docs/fensalir-rendering-rebuild-migration.md`, paired with Fensalir's
|
||||
|
|
|
|||
|
|
@ -150,6 +150,11 @@ if (args.Any(arg => string.Equals(arg, "--led-spline-quality-sweep-smoke", Strin
|
|||
return RunLedSplineQualitySweepSmoke();
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--led-spline-frame-analysis-smoke", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return RunLedSplineFrameAnalysisSmoke();
|
||||
}
|
||||
|
||||
if (args.Any(arg => string.Equals(arg, "--fensalir-texture-lease-smoke", StringComparison.OrdinalIgnoreCase)))
|
||||
{
|
||||
return RunFensalirTextureLeaseSmoke();
|
||||
|
|
@ -962,6 +967,59 @@ static int RunLedSplineQualitySweepSmoke()
|
|||
: 1;
|
||||
}
|
||||
|
||||
static int RunLedSplineFrameAnalysisSmoke()
|
||||
{
|
||||
const int width = 160;
|
||||
const int height = 120;
|
||||
var balanced = new byte[width * height];
|
||||
var blown = new byte[width * height];
|
||||
var points = new (int X, int Y)[]
|
||||
{
|
||||
(36, 22),
|
||||
(51, 36),
|
||||
(66, 55),
|
||||
(86, 74),
|
||||
(111, 94),
|
||||
};
|
||||
|
||||
foreach (var (x, y) in points)
|
||||
{
|
||||
StampBlob(balanced, width, height, x, y, radius: 2, peak: 220);
|
||||
StampBlob(blown, width, height, x, y, radius: 8, peak: 255);
|
||||
}
|
||||
|
||||
var analyzer = new MimirLedSplineFrameAnalyzer(new MimirLedSplineFrameAnalyzerOptions(
|
||||
ExpectedLedCount: points.Length,
|
||||
MinimumNormalizedLuma: 0.55,
|
||||
MinimumComponentPixels: 3,
|
||||
MaximumComponentPixels: 512));
|
||||
var balancedAnalysis = analyzer.AnalyzeLumaFrame(
|
||||
"synthetic-eye",
|
||||
"synthetic-eye:balanced",
|
||||
width,
|
||||
height,
|
||||
balanced,
|
||||
1_000_000_000L);
|
||||
var blownAnalysis = analyzer.AnalyzeLumaFrame(
|
||||
"synthetic-eye",
|
||||
"synthetic-eye:blown",
|
||||
width,
|
||||
height,
|
||||
blown,
|
||||
1_000_000_001L);
|
||||
|
||||
Console.WriteLine(
|
||||
$"led-spline-frame-analysis balancedComponents={balancedAnalysis.CandidateComponentCount} balancedScore={balancedAnalysis.Quality.Score:0.000} balancedSaturated={balancedAnalysis.SaturatedFraction:0.000} blownComponents={blownAnalysis.CandidateComponentCount} blownScore={blownAnalysis.Quality.Score:0.000} blownSaturated={blownAnalysis.SaturatedFraction:0.000}");
|
||||
|
||||
return balancedAnalysis.Quality.UsableForCalibration &&
|
||||
balancedAnalysis.Quality.DetectedLedCount == points.Length &&
|
||||
balancedAnalysis.Quality.Score > 0.70 &&
|
||||
blownAnalysis.SaturatedFraction > 0.90 &&
|
||||
blownAnalysis.Quality.Score < balancedAnalysis.Quality.Score
|
||||
? 0
|
||||
: 1;
|
||||
}
|
||||
|
||||
static IReadOnlyList<MimirLedPixelDetection> ProjectLedDetections(
|
||||
IReadOnlyList<MimirLedSplineScenePoint> scenePoints,
|
||||
MimirCameraPoseEstimate pose,
|
||||
|
|
@ -1036,6 +1094,40 @@ static IReadOnlyList<MimirLedPixelDetection> SyntheticSweepDetections(
|
|||
};
|
||||
}
|
||||
|
||||
static void StampBlob(byte[] luma, int width, int height, int centerX, int centerY, int radius, byte peak)
|
||||
{
|
||||
for (var y = centerY - radius; y <= centerY + radius; y++)
|
||||
{
|
||||
if (y < 0 || y >= height)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
for (var x = centerX - radius; x <= centerX + radius; x++)
|
||||
{
|
||||
if (x < 0 || x >= width)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var dx = x - centerX;
|
||||
var dy = y - centerY;
|
||||
var distance = Math.Sqrt(dx * dx + dy * dy);
|
||||
if (distance > radius)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var falloff = peak == 255 && radius >= 8
|
||||
? 1.0
|
||||
: 1.0 - distance / Math.Max(1, radius + 1);
|
||||
var value = (byte)Math.Clamp((int)Math.Round(peak * falloff), 0, 255);
|
||||
var offset = y * width + x;
|
||||
luma[offset] = Math.Max(luma[offset], value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int RunFensalirTextureLeaseSmoke()
|
||||
{
|
||||
var broker = new FakeFieldResourceBroker();
|
||||
|
|
|
|||
196
src/Mimir.Runtime/Synchronization/MimirLedSplineFrameAnalyzer.cs
Normal file
196
src/Mimir.Runtime/Synchronization/MimirLedSplineFrameAnalyzer.cs
Normal file
|
|
@ -0,0 +1,196 @@
|
|||
namespace Mimir.Runtime.Synchronization;
|
||||
|
||||
public sealed record MimirLedSplineFrameAnalyzerOptions(
|
||||
int ExpectedLedCount,
|
||||
double MinimumNormalizedLuma = 0.70,
|
||||
int MinimumComponentPixels = 2,
|
||||
int MaximumComponentPixels = 4096,
|
||||
int MaximumDetections = 96);
|
||||
|
||||
public sealed record MimirLedSplineFrameAnalysis(
|
||||
MimirLedSplineCurveFit Curve,
|
||||
MimirLedSplineQualityReport Quality,
|
||||
int CandidateComponentCount,
|
||||
double SaturatedFraction);
|
||||
|
||||
public sealed class MimirLedSplineFrameAnalyzer(MimirLedSplineFrameAnalyzerOptions options)
|
||||
{
|
||||
public MimirLedSplineFrameAnalysis AnalyzeLumaFrame(
|
||||
string sourceId,
|
||||
string observationKey,
|
||||
int width,
|
||||
int height,
|
||||
ReadOnlySpan<byte> luma,
|
||||
long observedTimeNs)
|
||||
{
|
||||
if (width <= 0 || height <= 0 || luma.Length < width * height)
|
||||
{
|
||||
var empty = new MimirLedSplineCurveFit(sourceId, observationKey, [], 0.0, 0.0);
|
||||
return new MimirLedSplineFrameAnalysis(
|
||||
empty,
|
||||
new MimirLedSplineQualityScorer().Score(empty, options.ExpectedLedCount),
|
||||
0,
|
||||
0.0);
|
||||
}
|
||||
|
||||
var threshold = (byte)Math.Clamp((int)Math.Round(options.MinimumNormalizedLuma * 255.0), 0, 255);
|
||||
var visited = new bool[width * height];
|
||||
var detections = new List<MimirLedPixelDetection>();
|
||||
var saturatedComponents = 0;
|
||||
var queue = new int[Math.Min(width * height, Math.Max(options.MaximumComponentPixels + 1, 64))];
|
||||
for (var y = 0; y < height; y++)
|
||||
{
|
||||
for (var x = 0; x < width; x++)
|
||||
{
|
||||
var offset = y * width + x;
|
||||
if (visited[offset] || luma[offset] < threshold)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (TryReadComponent(width, height, luma, threshold, visited, x, y, queue, out var detection, out var saturated))
|
||||
{
|
||||
detections.Add(detection);
|
||||
saturatedComponents += saturated ? 1 : 0;
|
||||
if (detections.Count >= options.MaximumDetections)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (detections.Count >= options.MaximumDetections)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
var strongest = detections
|
||||
.OrderByDescending(static detection => detection.Confidence)
|
||||
.Take(options.MaximumDetections)
|
||||
.ToArray();
|
||||
var curve = new MimirLedSplineCurveSolver().SolveCameraCurve(
|
||||
sourceId,
|
||||
observationKey,
|
||||
width,
|
||||
height,
|
||||
observedTimeNs,
|
||||
strongest);
|
||||
var saturatedFraction = detections.Count == 0 ? 0.0 : saturatedComponents / (double)detections.Count;
|
||||
var exposureFitness = strongest.Length == 0
|
||||
? 0.0
|
||||
: strongest.Average(static detection =>
|
||||
{
|
||||
var peak = Math.Clamp(detection.PeakLuma, 0.0, 1.0);
|
||||
return peak < 0.18 ? peak / 0.18 : peak > 0.92 ? Math.Max(0.0, 1.0 - (peak - 0.92) / 0.08) : 1.0;
|
||||
});
|
||||
return new MimirLedSplineFrameAnalysis(
|
||||
curve,
|
||||
new MimirLedSplineQualityScorer().Score(curve, options.ExpectedLedCount, saturatedFraction, exposureFitness),
|
||||
detections.Count,
|
||||
saturatedFraction);
|
||||
}
|
||||
|
||||
private bool TryReadComponent(
|
||||
int width,
|
||||
int height,
|
||||
ReadOnlySpan<byte> luma,
|
||||
byte threshold,
|
||||
bool[] visited,
|
||||
int startX,
|
||||
int startY,
|
||||
int[] queue,
|
||||
out MimirLedPixelDetection detection,
|
||||
out bool saturated)
|
||||
{
|
||||
var head = 0;
|
||||
var tail = 0;
|
||||
var overflow = false;
|
||||
var startOffset = startY * width + startX;
|
||||
visited[startOffset] = true;
|
||||
queue[tail++] = startOffset;
|
||||
var count = 0;
|
||||
var sumX = 0.0;
|
||||
var sumY = 0.0;
|
||||
var sumWeight = 0.0;
|
||||
var maxLuma = 0;
|
||||
var saturatedPixels = 0;
|
||||
|
||||
while (head < tail)
|
||||
{
|
||||
var offset = queue[head++];
|
||||
var x = offset % width;
|
||||
var y = offset / width;
|
||||
var value = luma[offset];
|
||||
var weight = Math.Max(1, value - threshold + 1);
|
||||
count++;
|
||||
sumX += x * weight;
|
||||
sumY += y * weight;
|
||||
sumWeight += weight;
|
||||
maxLuma = Math.Max(maxLuma, value);
|
||||
saturatedPixels += value >= 252 ? 1 : 0;
|
||||
|
||||
for (var neighbor = 0; neighbor < 4; neighbor++)
|
||||
{
|
||||
var nextX = neighbor switch
|
||||
{
|
||||
0 => x - 1,
|
||||
1 => x + 1,
|
||||
_ => x,
|
||||
};
|
||||
var nextY = neighbor switch
|
||||
{
|
||||
2 => y - 1,
|
||||
3 => y + 1,
|
||||
_ => y,
|
||||
};
|
||||
if (nextX < 0 || nextX >= width || nextY < 0 || nextY >= height || overflow)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
var next = nextY * width + nextX;
|
||||
if (visited[next] || luma[next] < threshold)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
visited[next] = true;
|
||||
if (tail >= queue.Length)
|
||||
{
|
||||
overflow = true;
|
||||
continue;
|
||||
}
|
||||
|
||||
queue[tail++] = next;
|
||||
}
|
||||
}
|
||||
|
||||
if (overflow ||
|
||||
count < options.MinimumComponentPixels ||
|
||||
count > options.MaximumComponentPixels ||
|
||||
sumWeight <= 0.0)
|
||||
{
|
||||
detection = default;
|
||||
saturated = saturatedPixels > 0;
|
||||
return false;
|
||||
}
|
||||
|
||||
var centroidX = sumX / sumWeight;
|
||||
var centroidY = sumY / sumWeight;
|
||||
var radius = Math.Sqrt(count / Math.PI);
|
||||
var peak = maxLuma / 255.0;
|
||||
saturated = saturatedPixels > Math.Max(1, count / 4);
|
||||
var confidence = Math.Clamp(peak, 0.0, 1.0) * (saturated ? 0.55 : 1.0);
|
||||
detection = new MimirLedPixelDetection(
|
||||
LedIndex: -1,
|
||||
ImageX: centroidX,
|
||||
ImageY: centroidY,
|
||||
RadiusPixels: radius,
|
||||
Confidence: confidence,
|
||||
PeakLuma: peak,
|
||||
LocalContrast: Math.Clamp((maxLuma - threshold) / Math.Max(1.0, 255.0 - threshold), 0.0, 1.0),
|
||||
IsSaturated: saturated);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
@ -254,3 +254,4 @@
|
|||
{"ts": "2026-05-31T01:34:32+01:00", "type": "verification", "status": "ok", "note": "Eve dashboard broker gained native VoidBot provider voidbot.swarm. It reads VoidBot's existing .voidbot/status/swarm-state.json projection, exposes a provider manifest with CTB/agent-status/state-tree capabilities, renders upcoming turns as CTB cards, agent status cards, and selected Face state/detail nodes. Smoke verified /eve/deck/providers includes voidbot.swarm and open-provider switched to a VoidBot snapshot with paused swarm state, CTB cards, and agent detail."}
|
||||
{"ts": "2026-05-31T02:05:12+01:00", "type": "implementation", "status": "ok", "note": "Added the first LED-strip calibration machine: MimirLedSplineCurveSolver orders bright detections into per-sensor image/clipspace curves, and MimirCameraRigCalibrationSolver consumes stable LED indices plus a scene-space LED curve anchor to emit bounded camera translation updates by minimizing ray-to-curve distance. Rotation, focal length, and distortion remain explicit future calibration owners."}
|
||||
{"ts": "2026-05-31T02:12:01+01:00", "type": "decision", "status": "ok", "note": "LED exposure/gain sweeps must optimize recovered spline quality, not raw brightness/contrast. MimirLedSplineQualityScorer now scores detected LED count, curve coverage, spacing coherence, smoothness, exposure fitness, and saturation penalty; overexposed halos can see every LED and still lose because centroid/curve quality is bad."}
|
||||
{"ts": "2026-05-31T02:16:04+01:00", "type": "implementation", "status": "ok", "note": "Added MimirLedSplineFrameAnalyzer as the frame-level bridge for physical camera sweeps: it extracts bright luma components, solves a per-sensor LED curve, and feeds MimirLedSplineQualityScorer so saturated blobs can be detected but rejected as poor calibration evidence."}
|
||||
|
|
|
|||
|
|
@ -119,7 +119,9 @@ invariants:
|
|||
and gain sweeps must optimize `MimirLedSplineQualityScorer` output:
|
||||
recovered LED count, curve coverage, spacing coherence, smoothness,
|
||||
exposure fitness, and saturation penalty decide whether a setting is
|
||||
usable for calibration.
|
||||
usable for calibration. `MimirLedSplineFrameAnalyzer` now extracts bright
|
||||
luma components from real frames into the same score path, so clipped blobs
|
||||
can be detected while still rejected as bad spline evidence.
|
||||
- Fensalir packet payload handles are not authority. Live payload references
|
||||
must resolve through declared typed GPU/native resources with shape,
|
||||
residency, shader access, validity, version, and handle metadata before
|
||||
|
|
|
|||
Loading…
Reference in a new issue