From 2953c781ae74bb271766aad2e82822eb2f5a0c07 Mon Sep 17 00:00:00 2001 From: tanglong <842690096@qq.com> Date: Sat, 11 Oct 2025 13:03:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A4=9A=E4=BA=BA=E8=B7=B3=E7=BB=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Wpf_AiSportsMicrospace/MainWindow.xaml.cs | 105 +++++++++++++++++- .../Views/JumpRope/GroupJumpRope.xaml.cs | 30 ++--- 2 files changed, 110 insertions(+), 25 deletions(-) diff --git a/Wpf_AiSportsMicrospace/MainWindow.xaml.cs b/Wpf_AiSportsMicrospace/MainWindow.xaml.cs index f9cd20c..dd0a409 100644 --- a/Wpf_AiSportsMicrospace/MainWindow.xaml.cs +++ b/Wpf_AiSportsMicrospace/MainWindow.xaml.cs @@ -66,12 +66,12 @@ public partial class MainWindow : Window { Application.Current.Dispatcher.InvokeAsync(() => { - DrawJumpRope3DPointsWithGlow(); + DrawCirclesWithText(); }, DispatcherPriority.Loaded); videoImage.SizeChanged += (s, ev) => { - DrawJumpRope3DPointsWithGlow(); + DrawCirclesWithText(); }; } @@ -395,4 +395,105 @@ public partial class MainWindow : Window var distance = Math.Sqrt(dx * dx + dy * dy); return distance <= p.Radius; } + + + private void DrawCirclesWithText() + { + overlayCanvas.Children.Clear(); + //sports.Clear(); + //circleTexts.Clear(); + + double imgWidth = overlayCanvas.ActualWidth; + double imgHeight = overlayCanvas.ActualHeight; + double radius = 100; + + double yOffset = -0.10; // 向上移动 10% 屏幕高度 + + // 每个圆的位置:X 和 Y 都归一化 0~1 + var circlePositions = new List<(double XNorm, double YNorm)> + { + (0.10, 0.98 + yOffset), + (0.24, 0.78 + yOffset), + (0.35, 0.98 + yOffset), + (0.48, 0.78 + yOffset), + (0.60, 0.98 + yOffset), + (0.72, 0.78 + yOffset), + (0.88, 0.98 + yOffset) + }; + + foreach (var pos in circlePositions) + { + double x = pos.XNorm * imgWidth; + double y = pos.YNorm * imgHeight; + + // 绘制发光圆 + AddGlowEllipse(x, y, overlayCanvas); + + // 创建文本控件 + var text = new TextBlock + { + Text = "0", + Foreground = Brushes.Red, + FontWeight = FontWeights.Bold, + FontSize = 50, + TextAlignment = TextAlignment.Center, + Width = radius * 2 + }; + Canvas.SetLeft(text, x - radius); + Canvas.SetTop(text, y - radius - 25); + overlayCanvas.Children.Add(text); + //circleTexts.Add(text); + + //// 绑定运动对象 + //var sport = SportBase.Create("rope-skipping"); + //int index = circleTexts.Count - 1; + //sport.OnTicked += (count, times) => + //{ + // Application.Current.Dispatcher.Invoke(() => + // { + // circleTexts[index].Text = count.ToString(); + // }); + //}; + //sport.Start(); + //sports.Add(sport); + } + } + + + + /// + /// 添加带渐变光的圆圈(中心红色,边缘蓝色) + /// + private void AddGlowEllipse(double centerX, double centerY, Canvas canvas) + { + double radius = 70; // 统一半径 + double flattenFactor = 0.5; // 统一扁平化比例 + double opacity = 0.8; // 统一透明度 + + var ellipse = new Ellipse + { + Width = radius * 2, + Height = radius * flattenFactor, + Opacity = opacity, + Fill = new RadialGradientBrush + { + GradientOrigin = new Point(0.5, 0.5), + Center = new Point(0.5, 0.5), + RadiusX = 0.5, + RadiusY = 0.5, + GradientStops = new GradientStopCollection + { + new GradientStop(Color.FromArgb(220, 255, 255, 0), 0.0), // 中心黄 + new GradientStop(Color.FromArgb(180, 255, 255, 0), 0.4), // 中间黄 + new GradientStop(Color.FromArgb(180, 0, 0, 255), 0.7), // 边缘蓝 + new GradientStop(Color.FromArgb(0, 0, 0, 255), 1.0) // 外部透明 + } + } + }; + + // 定位到中心 + Canvas.SetLeft(ellipse, centerX - radius); + Canvas.SetTop(ellipse, centerY - (radius * flattenFactor) / 2); + canvas.Children.Add(ellipse); + } } \ No newline at end of file diff --git a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs index b998f0c..780dc2a 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpRope/GroupJumpRope.xaml.cs @@ -99,7 +99,6 @@ namespace Wpf_AiSportsMicrospace.Views }, _cts.Token); } - private void ProcessFrame(VideoFrame frame) { try @@ -154,13 +153,13 @@ namespace Wpf_AiSportsMicrospace.Views // 每个圆的位置:X 和 Y 都归一化 0~1 var circlePositions = new List<(double XNorm, double YNorm)> { - (0.10, 0.88 + yOffset), // 后排 - (0.24, 0.60 + yOffset), // 前排 - (0.35, 0.88 + yOffset), - (0.48, 0.60 + yOffset), - (0.60, 0.88 + yOffset), - (0.72, 0.60 + yOffset), - (0.88, 0.88 + yOffset) + (0.10, 0.98 + yOffset), + (0.24, 0.78 + yOffset), + (0.35, 0.98 + yOffset), + (0.48, 0.78 + yOffset), + (0.60, 0.98 + yOffset), + (0.72, 0.78 + yOffset), + (0.88, 0.98 + yOffset) }; foreach (var pos in circlePositions) @@ -215,21 +214,6 @@ namespace Wpf_AiSportsMicrospace.Views if (human != null) { sports[i].Pushing(human); - - //Application.Current.Dispatcher.Invoke(() => - //{ - // circleTexts[i].Text = human.Score.ToString(); - //}); - - //sports[i].OnTicked = (count, times) => - //{ - // // 在 UI 线程更新文本 - // //Application.Current.Dispatcher.Invoke(() => - // //{ - // // circleTexts[i].Text = count.ToString(); - // //}); - //}; - } } }