将帧检查结果和概率叠加到视频播放窗口
This commit is contained in:
parent
308941c0be
commit
d5165ac76d
@ -13,6 +13,13 @@ public sealed partial class CameraViewModel
|
||||
private string _flowTestStatus = "", _flowTestDetails = "";
|
||||
private BitmapSource? _flowTestDecisionImage;
|
||||
private string _flowTestDecisionLabel = "";
|
||||
private string _flowTestVideoResult = "";
|
||||
public string FlowTestVideoResult
|
||||
{
|
||||
get => _flowTestVideoResult;
|
||||
private set { SetProperty(ref _flowTestVideoResult, value); RaisePropertyChanged(nameof(HasFlowTestVideoResult)); }
|
||||
}
|
||||
public bool HasFlowTestVideoResult => !string.IsNullOrEmpty(FlowTestVideoResult);
|
||||
private IReadOnlyDictionary<string, RegionDef>? _flowTestRegions;
|
||||
public IReadOnlyDictionary<string, RegionDef>? FlowTestRegions
|
||||
{
|
||||
@ -49,6 +56,7 @@ public sealed partial class CameraViewModel
|
||||
FlowTestDetails = "";
|
||||
FlowTestDecisionImage = null;
|
||||
FlowTestDecisionLabel = "";
|
||||
FlowTestVideoResult = "";
|
||||
FlowTestStatus = "正在准备流程测试…";
|
||||
try
|
||||
{
|
||||
@ -69,7 +77,7 @@ public sealed partial class CameraViewModel
|
||||
test.DecisionSubmitted += request => _dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
if (!ReferenceEquals(_flowTest, test) || _closing) return;
|
||||
ShowFlowTestDecision(request, "检查中");
|
||||
ShowFlowTestDecision(request);
|
||||
});
|
||||
test.DecisionEvaluated += (request, result, accepted) => _dispatcher.BeginInvoke(() =>
|
||||
{
|
||||
@ -77,7 +85,7 @@ public sealed partial class CameraViewModel
|
||||
var probability = result.EffectiveStatus is (VisionDecisionStatus.Completed or VisionDecisionStatus.NotCompleted)
|
||||
&& double.IsFinite(result.Confidence) && result.Confidence is >= 0 and <= 1
|
||||
? $"完成概率 {result.Confidence:P1}" : "概率不可用";
|
||||
ShowFlowTestDecision(request, $"检查{(accepted ? "通过" : "未通过")} · {probability} · {result.Reason}");
|
||||
FlowTestVideoResult = $"步骤 {request.StepId} · 送检帧 {request.FrameId}\n检查{(accepted ? "通过" : "未通过")} · {probability}";
|
||||
});
|
||||
await Task.Run(test.LoadModels);
|
||||
test.Start();
|
||||
@ -96,13 +104,13 @@ public sealed partial class CameraViewModel
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowFlowTestDecision(VisionDecisionRequest request, string status)
|
||||
private void ShowFlowTestDecision(VisionDecisionRequest request)
|
||||
{
|
||||
using var image = Cv2.ImDecode(request.Jpeg, ImreadModes.Color);
|
||||
var stride = checked((int)image.Step());
|
||||
FlowTestDecisionImage = BitmapSource.Create(image.Width, image.Height, 96, 96, PixelFormats.Bgr24,
|
||||
null, image.Data, checked(stride * image.Height), stride);
|
||||
FlowTestDecisionLabel = $"AI 实际送检图 · 视频帧 {request.FrameId} · {status}";
|
||||
FlowTestDecisionLabel = $"AI 实际送检图 · 视频帧 {request.FrameId}";
|
||||
}
|
||||
|
||||
// 仅在解码任务结束后调用,避免释放正在推理的模型。
|
||||
|
||||
@ -108,7 +108,10 @@ public sealed partial class CameraViewModel : BindableBase
|
||||
if (e.PropertyName is nameof(Playback.IsPlaying) or nameof(Playback.IsLoaded) or nameof(Playback.IsAtEnd))
|
||||
{ RaisePropertyChanged(nameof(PlayVideoButtonText)); UpdateCommands(); }
|
||||
if (e.PropertyName == nameof(Playback.IsLoaded))
|
||||
{ RaisePropertyChanged(nameof(CanSeekVideo)); RaisePropertyChanged(nameof(ShowFlowTestOverlay)); }
|
||||
{
|
||||
RaisePropertyChanged(nameof(CanSeekVideo)); RaisePropertyChanged(nameof(ShowFlowTestOverlay));
|
||||
if (!Playback.IsLoaded) FlowTestVideoResult = "";
|
||||
}
|
||||
if (e.PropertyName == nameof(Playback.IsAtEnd) && Playback.IsAtEnd)
|
||||
{
|
||||
if (IsTestingFlow) _ = CompleteFlowTestAsync();
|
||||
|
||||
@ -465,6 +465,7 @@
|
||||
<Grid Grid.Row="1" DataContext="{Binding SopRecording}" IsVisible="{Binding DataContext.HasSopRecording, RelativeSource={RelativeSource AncestorType=UserControl}}" RowDefinitions="Auto,*,Auto,Auto,Auto">
|
||||
<TextBlock Text="{Binding SelectedCameraName}" TextWrapping="Wrap" Margin="0,0,0,10" />
|
||||
<Border Grid.Row="1" Background="#080E14" CornerRadius="6" MinHeight="180">
|
||||
<Grid>
|
||||
<Viewbox Stretch="Uniform">
|
||||
<Grid Width="{Binding DisplayImage.PixelWidth, FallbackValue=1}" Height="{Binding DisplayImage.PixelHeight, FallbackValue=1}">
|
||||
<Image Source="{Binding DisplayImage}" Stretch="Fill" />
|
||||
@ -472,6 +473,12 @@
|
||||
<sop:HandOverlay x:Name="FlowTestHandsOverlay" Result="{Binding Playback.Analysis}" ShowBounds="True" IsVisible="{Binding ShowFlowTestOverlay}" IsHitTestVisible="False" />
|
||||
</Grid>
|
||||
</Viewbox>
|
||||
<Border x:Name="FlowTestVideoResultOverlay" IsVisible="{Binding HasFlowTestVideoResult}"
|
||||
HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10" Padding="10,6"
|
||||
Background="#CC080E14" CornerRadius="4" IsHitTestVisible="False">
|
||||
<TextBlock Text="{Binding FlowTestVideoResult}" Foreground="White" FontSize="16" FontWeight="SemiBold" TextWrapping="Wrap" />
|
||||
</Border>
|
||||
</Grid>
|
||||
</Border>
|
||||
<StackPanel Grid.Row="2" Spacing="8" Margin="0,12,0,8">
|
||||
<WrapPanel Orientation="Horizontal">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user