diff --git a/Wpf_AiSportsMicrospace/App.xaml b/Wpf_AiSportsMicrospace/App.xaml index 517d202..89298c0 100644 --- a/Wpf_AiSportsMicrospace/App.xaml +++ b/Wpf_AiSportsMicrospace/App.xaml @@ -18,12 +18,10 @@ - pack://application:,,,/YourApp;component/Resources/Fonts/#MyFontFamily - diff --git a/Wpf_AiSportsMicrospace/App.xaml.cs b/Wpf_AiSportsMicrospace/App.xaml.cs index 285b1b7..34d90c6 100644 --- a/Wpf_AiSportsMicrospace/App.xaml.cs +++ b/Wpf_AiSportsMicrospace/App.xaml.cs @@ -1,16 +1,17 @@ using AiSportsMicrospaceDB.DBContext; +using Microsoft.Data.Sqlite; +using Microsoft.EntityFrameworkCore; using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using Microsoft.ML.Runtime; using System.Configuration; using System.Data; using System.IO; using System.Windows; +using Wpf_AiSportsMicrospace.Views; using Yztob.AiSports.Common; using Yztob.AiSports.Common.Implement; -using Microsoft.EntityFrameworkCore; -using Microsoft.Extensions.DependencyInjection; -using Wpf_AiSportsMicrospace.Views; namespace Wpf_AiSportsMicrospace; @@ -102,7 +103,6 @@ public partial class App : Application TopPoint2 = new AiSportsMicrospaceDB.Entities.Point { X = 1498, Y = 730 }, TopPoint3 = new AiSportsMicrospaceDB.Entities.Point { X = 1689, Y = 724 }, BottomPoint1 = new AiSportsMicrospaceDB.Entities.Point { X = 191, Y = 918 }, - BottomPoint2 = new AiSportsMicrospaceDB.Entities.Point { X = 1516, Y = 918 }, BottomPoint3 = new AiSportsMicrospaceDB.Entities.Point { X = 1722, Y = 909 }, }); db.SaveChanges(); @@ -129,9 +129,8 @@ public partial class App : Application try { // 使用原始SQL检查表是否存在 - var result = dbContext.Database.ExecuteSqlRaw(@" - SELECT count(*) FROM sqlite_master - WHERE type='table' AND name='JumpLongPoints'"); + var sql = "SELECT count(*) FROM sqlite_master WHERE type='table' AND name=@name"; + var result = dbContext.Database.ExecuteSqlRaw(sql, new SqliteParameter("@name", name)); return result > 0; } catch diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/bottom.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/bottom.png new file mode 100644 index 0000000..ecae47e Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/bottom.png differ diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/head_top.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/head_top.png new file mode 100644 index 0000000..bd197df Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/head_top.png differ diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/mat.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/mat.png new file mode 100644 index 0000000..0b03559 Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/mat.png differ diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/people.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/people.png new file mode 100644 index 0000000..f9496c4 Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/people.png differ diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/tip.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/tip.png new file mode 100644 index 0000000..924e428 Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/tip.png differ diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/title.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/title.png new file mode 100644 index 0000000..ad11b42 Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/title.png differ diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/top.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/top.png new file mode 100644 index 0000000..f326234 Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/top.png differ diff --git a/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/win_bg.png b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/win_bg.png new file mode 100644 index 0000000..6cdfbbe Binary files /dev/null and b/Wpf_AiSportsMicrospace/Resources/Img/test_img/jump_long/win_bg.png differ diff --git a/Wpf_AiSportsMicrospace/Views/Home.xaml b/Wpf_AiSportsMicrospace/Views/Home.xaml index 99cc5fa..9a09fd5 100644 --- a/Wpf_AiSportsMicrospace/Views/Home.xaml +++ b/Wpf_AiSportsMicrospace/Views/Home.xaml @@ -63,7 +63,7 @@ /> - + - - - - - - - - + + + + + + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs index 26944d1..7f09b0e 100644 --- a/Wpf_AiSportsMicrospace/Views/Home.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/Home.xaml.cs @@ -1,4 +1,8 @@ -using Microsoft.ML.Runtime; +using AiSportsMicrospaceDB.DBContext; +using AiSportsMicrospaceDB.Entities; +using Microsoft.EntityFrameworkCore; +using Microsoft.Extensions.DependencyInjection; +using Microsoft.ML.Runtime; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -7,6 +11,7 @@ using System.ComponentModel; using System.Diagnostics; using System.IO; using System.Linq; +using System.Net.NetworkInformation; using System.Text; using System.Threading.Tasks; using System.Windows; @@ -77,6 +82,7 @@ namespace Wpf_AiSportsMicrospace _mainWin.HumanFrameUpdated += OnHumanFrameUpdated; _mainWin.WebcamClient.StartExtract(); Utils.PreloadGifs(); + Load_Base(); } private void Home_Unloaded(object sender, RoutedEventArgs e) { @@ -203,8 +209,7 @@ namespace Wpf_AiSportsMicrospace // 密码正确,打开管理员页面(已有 AdminWindow 或按需改为导航) try { - var mainWin = Application.Current.MainWindow as Main; - mainWin.SwitchPageWithMaskAnimation(new LongSttting(), true); + SetDialogGrid.Visibility = Visibility.Visible; //var adminWin = new Views.AdminWindow(); //adminWin.Owner = Window.GetWindow(this); //adminWin.Show(); @@ -244,5 +249,92 @@ namespace Wpf_AiSportsMicrospace e.Handled = true; } } + + private void SetCancelButton_Click(object sender, RoutedEventArgs e) + { + SetDialogGrid.Visibility = Visibility.Collapsed; + } + + //加载配置 + private async void Load_Base() + { + var app = (App)Application.Current; + using var scope = App.AppHost.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + var baseData = await db.BasicConfig.FirstOrDefaultAsync(); + if (baseData == null) + { + baseData = new BasicConfig { Id = 1 , Host = host.Text , UserName = name.Text , Password = password.Text}; + db.BasicConfig.Add(baseData); + } + else + { + host.Text = baseData.Host; + name.Text = baseData.UserName; + password.Text = baseData.Password; + } + } + + //保存基本配置 + private async void SetOkButton_Click(object sender, RoutedEventArgs e) + { + var app = (App)Application.Current; + using var scope = App.AppHost.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + var baseData = await db.BasicConfig.FirstOrDefaultAsync(); + if (baseData == null) + { + baseData = new BasicConfig { Id = 1 }; + db.BasicConfig.Add(baseData); + } + baseData.Host = host.Text; + baseData.UserName = name.Text; + baseData.Password = password.Text; + db.SaveChanges(); + + HandyControl.Controls.MessageBox.Show("保存成功!", "提示"); + SetDialogGrid.Visibility = Visibility.Collapsed; + } + + //多人跳绳 + private void GoRopeSet(object sender, RoutedEventArgs e) + { + var app = (App)Application.Current; + using var scope = App.AppHost.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + var mainWindow = new MainWindow(db); + mainWindow.Show(); + } + + //跳远 + private void GoLongSet(object sender, RoutedEventArgs e) + { + var mainWin = Application.Current.MainWindow as Main; + mainWin.SwitchPageWithMaskAnimation(new LongSttting(), true); + } + + private void Ping_Click(object sender, RoutedEventArgs e) + { + //var config = _context.BasicConfig.FirstOrDefault(); + + //if (config != null) + //{ + // //var ip = config.Ip; + //} + + var host = this.host.Text.Trim(); + if (string.IsNullOrWhiteSpace(host)) + { + this.ShowError("相机主机地址/IP不能为空。"); + return; + } + + var pinger = new Ping(); + var reply = pinger.Send(host, 10); + if (reply.Status == IPStatus.Success) + this.ShowInformation("与相机通信正常。"); + else + this.ShowError($"与相机通信失败,错误:{reply.Status}。"); + } } } diff --git a/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml b/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml index 0dde678..8a098bf 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml +++ b/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml @@ -5,11 +5,80 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:Views.JumpLong" mc:Ignorable="d" + xmlns:gif="http://wpfanimatedgif.codeplex.com" xmlns:hc="https://handyorg.github.io/handycontrol" Height="1080" Width="1920" Loaded="UserControl_Loaded" Unloaded="UserControl_Unloaded"> - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml.cs b/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml.cs index 09fb312..ef5a214 100644 --- a/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml.cs +++ b/Wpf_AiSportsMicrospace/Views/JumpLong/StandingLeap.xaml.cs @@ -1,5 +1,7 @@ -using Dto; +using AiSportsMicrospaceDB.DBContext; +using Dto; using Enum; +using Microsoft.Extensions.DependencyInjection; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -113,7 +115,6 @@ namespace Views.JumpLong // 获取项目根目录 string projectRoot = System.IO.Path.Combine(AppContext.BaseDirectory, @"..\..\.."); string musicPath = System.IO.Path.Combine(projectRoot, "Resources", "Music", musicFileName); - string imgPath = System.IO.Path.Combine(projectRoot, "Resources", "Img", "提示图.png"); if (!File.Exists(musicPath)) { @@ -123,31 +124,15 @@ namespace Views.JumpLong _mediaPlayer.Open(new Uri(musicPath, UriKind.Absolute)); - ShowCenterTip(imgPath, TimeSpan.FromSeconds(3)); + ShowCenterTip(TimeSpan.FromSeconds(3)); // 监听播放完成事件 _mediaPlayer.MediaEnded += MediaPlayer_MediaEnded; //_mainWin.WebcamClient.StartExtract(); _mediaPlayer.Play(); } - private void ShowCenterTip(string imagePath, TimeSpan duration) + private void ShowCenterTip(TimeSpan duration) { - var tipImage = new Image - { - Source = new BitmapImage(new Uri(imagePath, UriKind.Absolute)), - HorizontalAlignment = HorizontalAlignment.Center, - VerticalAlignment = VerticalAlignment.Center, - Opacity = 0, - Margin = new Thickness(0, -100, 0, 0), - }; - - // 增加图片的大小,调整比例 - tipImage.Width = 1920 * 0.9; // 宽度为 Canvas 宽度的 90% - tipImage.Height = 1080 * 0.6; // 高度为 Canvas 高度的 60% - - // 将图片添加到 Overlay Canvas - userBox.Children.Add(tipImage); - // 渐变出现动画 var fadeInAnimation = new DoubleAnimation { @@ -155,7 +140,7 @@ namespace Views.JumpLong To = 1, Duration = TimeSpan.FromSeconds(1.5) }; - tipImage.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation); + TipBox.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation); // 定时移除,并且渐变消失 Task.Delay(duration).ContinueWith(_ => @@ -169,13 +154,8 @@ namespace Views.JumpLong To = 0, Duration = TimeSpan.FromSeconds(1.5) }; - tipImage.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation); + TipBox.BeginAnimation(UIElement.OpacityProperty, fadeOutAnimation); - // 完成后移除图片 - fadeOutAnimation.Completed += (s, e) => - { - userBox.Children.Remove(tipImage); - }; }); }); } @@ -190,9 +170,11 @@ namespace Views.JumpLong var ts = TimeSpan.FromSeconds(times); Dispatcher.BeginInvoke(() => { - sportCounts.Content = _sport.GetFormatCounts(); //counts.ToString(); - sportTimes.Content = _sport.GetFormatTimes();//ts.ToString(@"mm\'ss\"""); - + //sportCounts.Content = _sport.GetFormatCounts(); //counts.ToString(); + //sportTimes.Content = _sport.GetFormatTimes();//ts.ToString(@"mm\'ss\"""); + count.Text = _sport.GetFormatCounts(); + time.Text = _sport.GetFormatTimes(); + ShowRope(); //触发停止 if (!_sport.IsCounting) { @@ -201,8 +183,29 @@ namespace Views.JumpLong } }); } - private bool ReactangleCalibrating(int frameWidth, int frameHeight) + + //展示成绩 + private void ShowRope() { + // 渐变出现动画 + var fadeInAnimation = new DoubleAnimation + { + From = 0, + To = 1, + Duration = TimeSpan.FromSeconds(1.5) + }; + RankingGrid.BeginAnimation(UIElement.OpacityProperty, fadeInAnimation); + + + } + private bool ReactangleCalibrating(int frameWidth, int frameHeight) + { + + var mainWin = Application.Current.MainWindow as Main; + var app = (App)Application.Current; + using var scope = App.AppHost.Services.CreateScope(); + var db = scope.ServiceProvider.GetRequiredService(); + var points = db.JumpLongPoints.FirstOrDefault(); var boxes = new List() { new BoundingBox(){ @@ -212,10 +215,10 @@ namespace Views.JumpLong Key = "begin" }, MaskLayer = new MaskLayer(){ - Contours = new List(){ - new SixLabors.ImageSharp.PointF(1722, 909), - new SixLabors.ImageSharp.PointF(1689, 724), - } + Contours = [ + new ((float)points.BottomPoint3.X, (float)points.BottomPoint3.Y), + new ((float)points.TopPoint3.X, (float)points.TopPoint3.Y), + ] } }, new BoundingBox(){ @@ -225,10 +228,10 @@ namespace Views.JumpLong Key = "end" }, MaskLayer = new MaskLayer(){ - Contours = new List(){ - new SixLabors.ImageSharp.PointF(1516, 918), - new SixLabors.ImageSharp.PointF(1498, 730) - } + Contours = [ + new((float)points.BottomPoint2.X, (float)points.BottomPoint2.Y), + new((float)points.TopPoint2.X, (float)points.TopPoint2.Y), + ] } } }; @@ -244,10 +247,10 @@ namespace Views.JumpLong }, MaskLayer = new MaskLayer() { - Contours = new List(){ - new SixLabors.ImageSharp.PointF(191, 918), - new SixLabors.ImageSharp.PointF(245, 741) - } + Contours = [ + new ((float)points.BottomPoint1.X, (float)points.BottomPoint1.Y), + new ((float)points.TopPoint1.X, (float)points.TopPoint1.Y), + ] } }); diff --git a/Wpf_AiSportsMicrospace/Views/Setting/LongSetting.xaml b/Wpf_AiSportsMicrospace/Views/Setting/LongSetting.xaml index 081aa33..af39ea8 100644 --- a/Wpf_AiSportsMicrospace/Views/Setting/LongSetting.xaml +++ b/Wpf_AiSportsMicrospace/Views/Setting/LongSetting.xaml @@ -57,10 +57,11 @@ Canvas.Left="1722" Canvas.Top="909" Tag="BottomPoint3"/> - +