动态配置
This commit is contained in:
parent
3e8df48443
commit
79b9e91149
@ -18,7 +18,7 @@ namespace AiSportsMicrospaceDB.DBContext
|
||||
|
||||
public DbSet<BasicConfig> BasicConfig { get; set; }
|
||||
|
||||
public DbSet<SixGroupPoints> SixGroupPoints { get; set; }
|
||||
public DbSet<GroupPoints> GroupPoints { get; set; }
|
||||
public DbSet<JumpLongPoints> JumpLongPoints { get; set; }
|
||||
public DbSet<AppVersion> AppVersion { get; set; }
|
||||
public DbSet<DeviceAssocSchool> DeviceAssocSchool { get; set; }
|
||||
|
||||
@ -4,15 +4,16 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using System.ComponentModel.DataAnnotations.Schema;
|
||||
using System.Drawing;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace AiSportsMicrospaceDB.Entities
|
||||
{
|
||||
|
||||
[Table("SixGroupPoints")]
|
||||
public class SixGroupPoints {
|
||||
[Table("GroupPoints")]
|
||||
public class GroupPoints
|
||||
{
|
||||
[Key]
|
||||
[DatabaseGenerated(DatabaseGeneratedOption.Identity)]
|
||||
[Display(Description = "主键Id")]
|
||||
@ -37,5 +38,7 @@ namespace AiSportsMicrospaceDB.Entities
|
||||
public Point? Point8 { get; set; }
|
||||
public Point? Point9 { get; set; }
|
||||
public Point? Point10 { get; set; }
|
||||
public Point? ControlPoint { get; set; }
|
||||
public Point? AreaSize { get; set; }
|
||||
}
|
||||
}
|
||||
@ -1,12 +1,11 @@
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AiSportsMicrospaceDB.DBContext;
|
||||
using AiSportsMicrospaceDB.Entities;
|
||||
using Microsoft.Extensions.Configuration;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using System.IO;
|
||||
using System.Net.Sockets;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using Wpf_AiSportsMicrospace;
|
||||
using Wpf_AiSportsMicrospace.Common;
|
||||
|
||||
namespace Common
|
||||
{
|
||||
public static class AppSettings
|
||||
@ -16,15 +15,40 @@ namespace Common
|
||||
public static string BackendUrl;
|
||||
public static string Version;
|
||||
|
||||
public static int Resolution_X = 1920;
|
||||
public static int Resolution_Y = 1080;
|
||||
|
||||
public static Point ControlPoint { get; set; }
|
||||
public static Point AreaSize { get; set; }
|
||||
|
||||
public static void Init(IConfiguration configuration)
|
||||
{
|
||||
Code = Utils.GetMacAddress() ?? configuration["SchoolCode"] ?? "";
|
||||
|
||||
if (string.IsNullOrWhiteSpace(Code))
|
||||
{
|
||||
HandyControl.Controls.MessageBox.Show("获取设备编码失败!");
|
||||
return;
|
||||
}
|
||||
|
||||
using var scope = App.AppHost.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
var groupData = db.GroupPoints.Where(x => x.Code == Code).Select(x => new { x.ControlPoint, x.AreaSize }).FirstOrDefault();
|
||||
|
||||
if (groupData != null && groupData.ControlPoint != null && groupData.AreaSize != null)
|
||||
{
|
||||
ControlPoint = groupData.ControlPoint;
|
||||
AreaSize = groupData.AreaSize;
|
||||
}
|
||||
else
|
||||
HandyControl.Controls.MessageBox.Show("请先设置点位并重启应用!");
|
||||
|
||||
SchoolCode = configuration["SchoolCode"] ?? "";
|
||||
BackendUrl = configuration["BackendUrl"] ?? "";
|
||||
Version = configuration["Version"] ?? "";
|
||||
}
|
||||
|
||||
|
||||
public static void UpdateCodeAndSchool(string filePath, string code, string schoolCode)
|
||||
{
|
||||
if (!File.Exists(filePath))
|
||||
|
||||
@ -82,10 +82,18 @@ namespace Wpf_AiSportsMicrospace.Common
|
||||
if (rightAnkle == null)
|
||||
return false;
|
||||
|
||||
double xNorm = rightAnkle.X / 1920.0;
|
||||
double yNorm = rightAnkle.Y / 1080.0;
|
||||
double xNorm = rightAnkle.X / AppSettings.Resolution_X;
|
||||
double yNorm = rightAnkle.Y / AppSettings.Resolution_Y;
|
||||
|
||||
return xNorm >= 0.44 && xNorm <= 0.57 && yNorm >= 0.81;
|
||||
// 控制点
|
||||
double cx = AppSettings.ControlPoint.X; // 已经是归一化 0~1
|
||||
double cy = AppSettings.ControlPoint.Y;
|
||||
|
||||
double halfWidth = AppSettings.AreaSize.X;
|
||||
double halfHeight = AppSettings.AreaSize.Y;
|
||||
|
||||
return xNorm >= (cx - halfWidth) && xNorm <= (cx + halfWidth) &&
|
||||
yNorm >= (cy - halfHeight) && yNorm <= (cy + halfHeight);
|
||||
});
|
||||
|
||||
if (human != null)
|
||||
|
||||
@ -3,42 +3,20 @@ using AiSportsMicrospaceDB.Entities;
|
||||
using Common;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.ML.Runtime;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
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;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Threading;
|
||||
using Views.JumpingJack;
|
||||
using Views.JumpLong;
|
||||
using Views.JumpRope;
|
||||
using Views.SquatFu;
|
||||
using Wpf_AiSportsMicrospace;
|
||||
using Wpf_AiSportsMicrospace.Common;
|
||||
using Wpf_AiSportsMicrospace.Enum;
|
||||
using Wpf_AiSportsMicrospace.MyUserControl;
|
||||
using Wpf_AiSportsMicrospace.Views;
|
||||
using Wpf_AiSportsMicrospace.Views.JumpRope;
|
||||
using Yztob.AiSports.Inferences.Abstractions;
|
||||
using Yztob.AiSports.Inferences.Things;
|
||||
using Yztob.AiSports.Postures;
|
||||
using Yztob.AiSports.Postures.Abstractions;
|
||||
using Yztob.AiSports.Postures.Sports;
|
||||
using Yztob.AiSports.Postures.Things;
|
||||
using Yztob.AiSports.Sensors.Abstractions;
|
||||
using Yztob.AiSports.Sensors.Things;
|
||||
namespace Wpf_AiSportsMicrospace
|
||||
{
|
||||
/// <summary>
|
||||
|
||||
@ -82,7 +82,7 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
var app = (App)Application.Current;
|
||||
using var scope = App.AppHost.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
var cfg = await db.SixGroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
var cfg = await db.GroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
//var pointlist = JsonSerializer.Deserialize<List<(double, double)>>(cfg!.PointsJson);
|
||||
|
||||
List<(double XNorm, double YNorm)> pointlist =
|
||||
@ -136,8 +136,8 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
};
|
||||
|
||||
// 增加图片的大小,调整比例
|
||||
tipImage.Width = 1920 * 0.9; // 宽度为 Canvas 宽度的 90%
|
||||
tipImage.Height = 1080 * 0.6; // 高度为 Canvas 高度的 60%
|
||||
tipImage.Width = AppSettings.Resolution_X * 0.9;
|
||||
tipImage.Height = AppSettings.Resolution_Y * 0.6;
|
||||
|
||||
// 将图片添加到 Overlay Canvas
|
||||
userBox.Children.Add(tipImage);
|
||||
@ -196,10 +196,18 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
if (rightAnkle == null)
|
||||
return false;
|
||||
|
||||
double xNorm = rightAnkle.X / 1920.0;
|
||||
double yNorm = rightAnkle.Y / 1080.0;
|
||||
double xNorm = rightAnkle.X / AppSettings.Resolution_X;
|
||||
double yNorm = rightAnkle.Y / AppSettings.Resolution_Y;
|
||||
|
||||
return xNorm >= 0.44 && xNorm <= 0.57 && yNorm >= 0.81;
|
||||
// 控制点
|
||||
double cx = AppSettings.ControlPoint.X; // 已经是归一化 0~1
|
||||
double cy = AppSettings.ControlPoint.Y;
|
||||
|
||||
double halfWidth = AppSettings.AreaSize.X;
|
||||
double halfHeight = AppSettings.AreaSize.Y;
|
||||
|
||||
return xNorm >= (cx - halfWidth) && xNorm <= (cx + halfWidth) &&
|
||||
yNorm >= (cy - halfHeight) && yNorm <= (cy + halfHeight);
|
||||
});
|
||||
|
||||
if (human != null)
|
||||
@ -420,7 +428,7 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
return (int)WavingAction.Raising;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int DetectLeftHandRaise(Human human)
|
||||
{
|
||||
var calculator = PostureCalculate.CreateCalculator();
|
||||
@ -486,8 +494,8 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
}
|
||||
private void UpdateCircleCounts(List<Human> humans)
|
||||
{
|
||||
double radiusNormX = 0.07;
|
||||
double radiusNormY = 0.14;
|
||||
double radiusNormX = AppSettings.AreaSize.X;
|
||||
double radiusNormY = AppSettings.AreaSize.Y;
|
||||
|
||||
for (int i = 0; i < _groupJumpRopeContext.CirclePositions.Count; i++)
|
||||
{
|
||||
|
||||
@ -89,7 +89,7 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
||||
var app = (App)Application.Current;
|
||||
using var scope = App.AppHost.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
var cfg = await db.SixGroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
var cfg = await db.GroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
//var pointlist = JsonSerializer.Deserialize<List<(double, double)>>(cfg!.PointsJson);
|
||||
|
||||
List<(double XNorm, double YNorm)> pointlist = [(cfg.Point3.X, cfg.Point3.Y), (cfg.Point5.X, cfg.Point5.Y)];
|
||||
@ -134,8 +134,8 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
||||
};
|
||||
|
||||
// 增加图片的大小,调整比例
|
||||
tipImage.Width = 1920 * 0.9; // 宽度为 Canvas 宽度的 90%
|
||||
tipImage.Height = 1080 * 0.6; // 高度为 Canvas 高度的 60%
|
||||
tipImage.Width = AppSettings.Resolution_X * 0.9; // 宽度为 Canvas 宽度的 90%
|
||||
tipImage.Height = AppSettings.Resolution_Y * 0.6; // 高度为 Canvas 高度的 60%
|
||||
|
||||
// 将图片添加到 Overlay Canvas
|
||||
userBox.Children.Add(tipImage);
|
||||
@ -192,8 +192,8 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
||||
if (rightAnkle == null)
|
||||
return false;
|
||||
|
||||
double xNorm = rightAnkle.X / 1920.0;
|
||||
double yNorm = rightAnkle.Y / 1080.0;
|
||||
double xNorm = rightAnkle.X / AppSettings.Resolution_X;
|
||||
double yNorm = rightAnkle.Y / AppSettings.Resolution_Y;
|
||||
|
||||
return xNorm >= 0.44 && xNorm <= 0.57 && yNorm >= 0.81;
|
||||
});
|
||||
@ -599,34 +599,6 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
||||
}
|
||||
}
|
||||
|
||||
private void UpdateScore(double to, TextBlock score)
|
||||
{
|
||||
DoubleAnimation animation = new DoubleAnimation
|
||||
{
|
||||
From = double.Parse(score1.Text),
|
||||
To = to,
|
||||
Duration = TimeSpan.FromSeconds(0.2),
|
||||
EasingFunction = new QuadraticEase { EasingMode = EasingMode.EaseOut },
|
||||
FillBehavior = FillBehavior.HoldEnd
|
||||
};
|
||||
score.BeginAnimation(TextBlock.TextProperty, animation);
|
||||
}
|
||||
|
||||
//private void ChangeImgState(int index , string state)
|
||||
//{
|
||||
// if(index== 0)
|
||||
// {
|
||||
// left1.Visibility = state == "1" ? Visibility.Visible : Visibility.Hidden;
|
||||
// left2.Visibility = state == "2" ? Visibility.Visible : Visibility.Hidden;
|
||||
// left3.Visibility = state == "3" ? Visibility.Visible : Visibility.Hidden;
|
||||
// }else if (index == 1)
|
||||
// {
|
||||
// right1.Visibility = state == "1" ? Visibility.Visible : Visibility.Hidden;
|
||||
// right2.Visibility = state == "1" ? Visibility.Visible : Visibility.Hidden;
|
||||
// right3.Visibility = state == "1" ? Visibility.Visible : Visibility.Hidden;
|
||||
// }
|
||||
//}
|
||||
|
||||
public void ShowMusicAnimation()
|
||||
{
|
||||
ImageBehavior.SetRepeatBehavior(leftm, RepeatBehavior.Forever);
|
||||
@ -637,8 +609,8 @@ namespace Wpf_AiSportsMicrospace.Views.JumpRope
|
||||
|
||||
private void UpdateCircleCounts(List<Human> humans)
|
||||
{
|
||||
double radiusNormX = 0.07;
|
||||
double radiusNormY = 0.14;
|
||||
double radiusNormX = AppSettings.Resolution_X;
|
||||
double radiusNormY = AppSettings.Resolution_Y;
|
||||
|
||||
for (int i = 0; i < _musicJumpRopeContext.CirclePositions.Count; i++)
|
||||
{
|
||||
|
||||
@ -67,7 +67,7 @@ namespace Views.JumpingJack
|
||||
var app = (App)Application.Current;
|
||||
using var scope = App.AppHost.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
var cfg = await db.SixGroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
var cfg = await db.GroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
//var pointlist = JsonSerializer.Deserialize<List<(double, double)>>(cfg!.PointsJson);
|
||||
|
||||
List<(double XNorm, double YNorm)> pointlist =
|
||||
|
||||
@ -101,16 +101,6 @@ namespace Wpf_AiSportsMicrospace.Views
|
||||
{
|
||||
try
|
||||
{
|
||||
//if (frame.Number % 2 != 0)
|
||||
// return;
|
||||
|
||||
// 触发全局事件
|
||||
//Application.Current.Dispatcher.BeginInvoke(() =>
|
||||
//{
|
||||
// FacialRecognitionEvent?.Invoke(frame);
|
||||
//});
|
||||
|
||||
|
||||
var buffer = frame.GetImageBuffer(ImageFormat.Jpeg).ToArray();
|
||||
var humanResult = _humanPredictor.Predicting(buffer, frame.Number);
|
||||
|
||||
|
||||
@ -60,7 +60,7 @@ namespace Views.SquatFu
|
||||
var app = (App)Application.Current;
|
||||
using var scope = App.AppHost.Services.CreateScope();
|
||||
var db = scope.ServiceProvider.GetRequiredService<AppDbContext>();
|
||||
var cfg = await db.SixGroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
var cfg = await db.GroupPoints.FirstOrDefaultAsync(x => x.Code == AppSettings.Code);
|
||||
//var pointlist = JsonSerializer.Deserialize<List<(double, double)>>(cfg!.PointsJson);
|
||||
|
||||
List<(double XNorm, double YNorm)> pointlist =
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user