diff --git a/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml b/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml
index 7f4e091..c93dfea 100644
--- a/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml
+++ b/src/SopHelper.App/VVMs/RecipeEditor/RecipeEditor.xaml
@@ -337,12 +337,20 @@
-
+
+
+
+
-
+
+
+
+
diff --git a/src/SopHelper.App/VVMs/SopPage/DetectionOverlay.cs b/src/SopHelper.App/VVMs/SopPage/DetectionOverlay.cs
new file mode 100644
index 0000000..d296b09
--- /dev/null
+++ b/src/SopHelper.App/VVMs/SopPage/DetectionOverlay.cs
@@ -0,0 +1,65 @@
+using System.Globalization;
+using System.Windows;
+using System.Windows.Media;
+using SopHelper.Engine.Common;
+
+namespace SopHelper.VVMs.SopPage;
+
+/// 按原图像素绘制目标框与标签,与视频一起缩放。
+public sealed class DetectionOverlay : FrameworkElement
+{
+ public static readonly DependencyProperty ResultProperty = DependencyProperty.Register(
+ nameof(Result), typeof(FrameResult), typeof(DetectionOverlay),
+ new FrameworkPropertyMetadata(null, FrameworkPropertyMetadataOptions.AffectsRender));
+
+ public FrameResult? Result
+ {
+ get => (FrameResult?)GetValue(ResultProperty);
+ set => SetValue(ResultProperty, value);
+ }
+
+ protected override void OnRender(DrawingContext drawing)
+ {
+ base.OnRender(drawing);
+ var result = Result;
+ if (result is null || result.Size.W <= 0 || result.Size.H <= 0 ||
+ ActualWidth <= 0 || ActualHeight <= 0) return;
+
+ drawing.PushClip(new RectangleGeometry(new Rect(RenderSize)));
+ drawing.PushTransform(new ScaleTransform(ActualWidth / result.Size.W, ActualHeight / result.Size.H));
+ var imageBounds = new Rect(0, 0, result.Size.W, result.Size.H);
+ var unit = Math.Max(result.Size.W, result.Size.H) / 700.0;
+ var pen = new Pen(Brushes.Orange, 2 * unit);
+ var background = new SolidColorBrush(Color.FromArgb(220, 12, 18, 24));
+ var typeface = new Typeface("Microsoft YaHei");
+ var padding = 3 * unit;
+
+ foreach (var detection in result.Detections)
+ {
+ var box = detection.Rect;
+ if (!float.IsFinite(box.X) || !float.IsFinite(box.Y) ||
+ !float.IsFinite(box.Right) || !float.IsFinite(box.Bottom) ||
+ !float.IsFinite(detection.Confidence) || box.W <= 0 || box.H <= 0) continue;
+ var bounds = Rect.Intersect(imageBounds, new Rect(box.X, box.Y, box.W, box.H));
+ if (bounds.IsEmpty || bounds.Width <= 0 || bounds.Height <= 0) continue;
+ drawing.DrawRectangle(null, pen, bounds);
+
+ var label = new FormattedText($"{detection.Label} {detection.Confidence:P0}",
+ CultureInfo.CurrentCulture, FlowDirection.LeftToRight, typeface,
+ 12 * unit, Brushes.White, VisualTreeHelper.GetDpi(this).PixelsPerDip)
+ {
+ MaxTextWidth = Math.Max(1, imageBounds.Width - 2 * padding),
+ MaxLineCount = 1,
+ Trimming = TextTrimming.CharacterEllipsis,
+ };
+ var labelSize = new Size(label.Width + 2 * padding, label.Height + 2 * padding);
+ var left = Math.Clamp(bounds.Left, 0, Math.Max(0, imageBounds.Width - labelSize.Width));
+ var top = bounds.Top >= labelSize.Height ? bounds.Top - labelSize.Height : bounds.Top;
+ top = Math.Clamp(top, 0, Math.Max(0, imageBounds.Height - labelSize.Height));
+ drawing.DrawRectangle(background, null, new Rect(new Point(left, top), labelSize));
+ drawing.DrawText(label, new Point(left + padding, top + padding));
+ }
+ drawing.Pop();
+ drawing.Pop();
+ }
+}
diff --git a/src/SopHelper.App/VVMs/SopPage/SopPage.xaml b/src/SopHelper.App/VVMs/SopPage/SopPage.xaml
index 710d98a..83a34b1 100644
--- a/src/SopHelper.App/VVMs/SopPage/SopPage.xaml
+++ b/src/SopHelper.App/VVMs/SopPage/SopPage.xaml
@@ -47,6 +47,7 @@
+
diff --git a/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs b/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs
index 53e4b9e..72ce17f 100644
--- a/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs
+++ b/src/SopHelper.App/VVMs/SopPage/SopPageViewModel.cs
@@ -163,7 +163,7 @@ public class SopPageViewModel : ViewModelBase
set { SetProperty(ref _frame, value); }
}
- /// 最近一次手部检测结果,交给图像上方的绘制层。
+ /// 最近一次推理结果,供图像上的手部与目标检测绘制层使用。
public FrameResult? HandResult
{
get => _handResult;
@@ -597,7 +597,7 @@ public class SopPageViewModel : ViewModelBase
_engine.ProcessFrame(result);
- // 无手结果也要更新,立即清除上一帧手部标记。
+ // 每帧均更新,无检测结果时清除上一帧的手部标记和目标框。
HandResult = result;
InferenceText = $"{result.InferenceMs:F1} ms";
diff --git a/tests/RegionEditorSmoke/Program.cs b/tests/RegionEditorSmoke/Program.cs
index f7a9477..ab23ab6 100644
--- a/tests/RegionEditorSmoke/Program.cs
+++ b/tests/RegionEditorSmoke/Program.cs
@@ -127,6 +127,32 @@ internal static class Program
if (SopConfigLoader.Load(savePath).Sop.Steps.Single().ViolationRules.Count != 0)
throw new Exception("删除违规规则未正确保存");
Console.WriteLine("PASS: 界面新增违规规则、编辑字段、保存回读和删除");
+ foreach (var requiredAtEnd in new[] { true, false })
+ {
+ var buttonText = requiredAtEnd ? "加完成必需物品" : "加必留物品";
+ var addItem = Descendants(stepView).OfType