多人跳绳

This commit is contained in:
tanglong 2025-10-11 13:03:01 +08:00
parent 559338b95f
commit 2953c781ae
2 changed files with 110 additions and 25 deletions

View File

@ -66,12 +66,12 @@ public partial class MainWindow : Window
{ {
Application.Current.Dispatcher.InvokeAsync(() => Application.Current.Dispatcher.InvokeAsync(() =>
{ {
DrawJumpRope3DPointsWithGlow(); DrawCirclesWithText();
}, DispatcherPriority.Loaded); }, DispatcherPriority.Loaded);
videoImage.SizeChanged += (s, ev) => videoImage.SizeChanged += (s, ev) =>
{ {
DrawJumpRope3DPointsWithGlow(); DrawCirclesWithText();
}; };
} }
@ -395,4 +395,105 @@ public partial class MainWindow : Window
var distance = Math.Sqrt(dx * dx + dy * dy); var distance = Math.Sqrt(dx * dx + dy * dy);
return distance <= p.Radius; 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);
}
}
/// <summary>
/// 添加带渐变光的圆圈(中心红色,边缘蓝色)
/// </summary>
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);
}
} }

View File

@ -99,7 +99,6 @@ namespace Wpf_AiSportsMicrospace.Views
}, _cts.Token); }, _cts.Token);
} }
private void ProcessFrame(VideoFrame frame) private void ProcessFrame(VideoFrame frame)
{ {
try try
@ -154,13 +153,13 @@ namespace Wpf_AiSportsMicrospace.Views
// 每个圆的位置X 和 Y 都归一化 0~1 // 每个圆的位置X 和 Y 都归一化 0~1
var circlePositions = new List<(double XNorm, double YNorm)> var circlePositions = new List<(double XNorm, double YNorm)>
{ {
(0.10, 0.88 + yOffset), // 后排 (0.10, 0.98 + yOffset),
(0.24, 0.60 + yOffset), // 前排 (0.24, 0.78 + yOffset),
(0.35, 0.88 + yOffset), (0.35, 0.98 + yOffset),
(0.48, 0.60 + yOffset), (0.48, 0.78 + yOffset),
(0.60, 0.88 + yOffset), (0.60, 0.98 + yOffset),
(0.72, 0.60 + yOffset), (0.72, 0.78 + yOffset),
(0.88, 0.88 + yOffset) (0.88, 0.98 + yOffset)
}; };
foreach (var pos in circlePositions) foreach (var pos in circlePositions)
@ -215,21 +214,6 @@ namespace Wpf_AiSportsMicrospace.Views
if (human != null) if (human != null)
{ {
sports[i].Pushing(human); 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();
// //});
//};
} }
} }
} }