修复视频流程测试抽帧时手骨架闪烁
This commit is contained in:
parent
8e81d25fed
commit
12fcf7a2fa
@ -42,9 +42,10 @@ public sealed class RecordedVideoPlayback : BindableBase
|
||||
public event Action<string>? Failed;
|
||||
/// <summary>在解码线程处理即将显示的原始帧;Mat 仅在回调期间有效。</summary>
|
||||
public Action<Mat, long, double>? FrameProcessor { get; set; }
|
||||
/// <summary>返回 null 表示本帧跳过检测;无手时应返回 Hands 为空的检测结果。</summary>
|
||||
public Func<Mat, long, double, FrameResult?>? FrameAnalyzer { get; set; }
|
||||
private FrameResult? _analysis;
|
||||
/// <summary>与当前显示画面一起发布的检测结果,不能跨帧沿用。</summary>
|
||||
/// <summary>最近一次检测结果;抽帧期间保留,新的无手结果会清除骨架。</summary>
|
||||
public FrameResult? Analysis { get => _analysis; private set => SetProperty(ref _analysis, value); }
|
||||
|
||||
public RecordedVideoPlayback()
|
||||
@ -208,7 +209,10 @@ public sealed class RecordedVideoPlayback : BindableBase
|
||||
}
|
||||
Frame = decoded.Image;
|
||||
DisplayedSeconds = decoded.Seconds;
|
||||
Analysis = decoded.Analysis;
|
||||
// 抽帧不等于未检出手,与现场运行一样等待下一次有效检测更新骨架。
|
||||
// 停止分析或画面尺寸变化时,不沿用旧坐标。
|
||||
Analysis = decoded.Analysis ?? (FrameAnalyzer is not null
|
||||
&& Analysis?.Size == (decoded.Image.PixelWidth, decoded.Image.PixelHeight) ? Analysis : null);
|
||||
_position = decoded.Seconds; NotifyTime();
|
||||
}
|
||||
catch (Exception error)
|
||||
|
||||
@ -161,7 +161,7 @@ internal static class Program
|
||||
var runtime = runtimeStore.Read() ?? new();
|
||||
var originalTimeout = runtime.DjevTimeoutMs;
|
||||
runtime.DjevTimeoutMs = 1000; runtimeStore.Save(runtime);
|
||||
try { CheckRealtimePlayback(model.StandardVideoPath); CheckContinuousPlayback(model.StandardVideoPath); }
|
||||
try { CheckStridedHandPlayback(model.StandardVideoPath); CheckRealtimePlayback(model.StandardVideoPath); CheckContinuousPlayback(model.StandardVideoPath); }
|
||||
finally { runtime.DjevTimeoutMs = originalTimeout; runtimeStore.Save(runtime); }
|
||||
vm.Recipe.AddStepCommand.Execute();
|
||||
var selected = vm.Recipe.SelectedStep!;
|
||||
@ -339,6 +339,61 @@ internal static class Program
|
||||
window.Close(); Until(() => !window.IsVisible); vm.OnDialogClosed();
|
||||
}
|
||||
|
||||
private static void CheckStridedHandPlayback(string path)
|
||||
{
|
||||
var store = SopHelper.Models.RuntimeSettingsStore.Current;
|
||||
var options = store.Read()!;
|
||||
var originalStride = options.FrameStride;
|
||||
var playback = new RecordedVideoPlayback();
|
||||
try
|
||||
{
|
||||
options.FrameStride = 3; store.Save(options);
|
||||
var config = new SopConfig();
|
||||
config.Sop.Steps = [new StepDef { Id = 1, Detection = new() { Method = "unsupported" } }];
|
||||
using var test = new SopVideoFlowTest(config); test.Start();
|
||||
FrameResult? expected = null;
|
||||
var detections = 0;
|
||||
var skippedWithHands = 0;
|
||||
var skippedWithoutHands = 0;
|
||||
var samples = new List<(FrameResult? Actual, FrameResult? Expected)>();
|
||||
playback.FrameAnalyzer = (image, id, seconds) =>
|
||||
{
|
||||
var result = test.AnalyzeFrame(image, id, seconds);
|
||||
if (result is not null)
|
||||
{
|
||||
// 无需模型,模拟第一次检出手,后续检测确认手已离开。
|
||||
if (++detections == 1) result.Hands = [new Hand { Rect = new(20, 10, 20, 25) }];
|
||||
expected = result;
|
||||
}
|
||||
else if (expected?.Hands.Count > 0) skippedWithHands++;
|
||||
else if (expected is not null) skippedWithoutHands++;
|
||||
return result;
|
||||
};
|
||||
playback.PropertyChanged += (_, e) =>
|
||||
{
|
||||
if (e.PropertyName == nameof(RecordedVideoPlayback.Progress) && playback.IsPlaying)
|
||||
samples.Add((playback.Analysis, expected));
|
||||
};
|
||||
Pump(playback.PlayAsync(path));
|
||||
Until(() => playback.IsAtEnd);
|
||||
Check(detections >= 2 && skippedWithHands > 0 && skippedWithoutHands > 0,
|
||||
"抽帧回放覆盖初始未检测、有手后的跳帧及无手后的跳帧");
|
||||
Check(samples.All(s => ReferenceEquals(s.Actual, s.Expected)),
|
||||
"跳帧保留最近骨架,实际无手结果立即清除骨架且后续跳帧不恢复旧手");
|
||||
Pump(playback.StopAsync());
|
||||
Check(playback.Analysis is null, "停止抽帧测试清空旧骨架");
|
||||
playback.FrameAnalyzer = null;
|
||||
Pump(playback.PlayAsync(path));
|
||||
Check(playback.Analysis is null, "重新普通播放不会沿用上轮测试骨架");
|
||||
Console.WriteLine("PASS: 视频测试抽帧骨架连续显示与无手清除");
|
||||
}
|
||||
finally
|
||||
{
|
||||
Pump(playback.StopAsync());
|
||||
options.FrameStride = originalStride; store.Save(options);
|
||||
}
|
||||
}
|
||||
|
||||
private static void CheckRealtimePlayback(string path)
|
||||
{
|
||||
var playback = new RecordedVideoPlayback();
|
||||
|
||||
Loading…
Reference in New Issue
Block a user