Commit d46b8ca0 by liulongfei

添加算法控制器

parent e828ccee
......@@ -22,6 +22,8 @@ namespace VIZ.GimbalAI.Client
AppSetup.AppendSetup(new AppSetup_InitCSV());
// 初始化 LiteDB
AppSetup.AppendSetup(new AppSetup_InitLiteDB());
// 初始化中心轴
AppSetup.AppendSetup(new AppSetup_InitCenterAxis());
// 初始化 NDI
AppSetup.AppendSetup(new AppSetup_InitNDI());
// 初始化 UDP
......
; ============================================================
; === Application ===
; ============================================================
[Application]
;是否是调试模式
APPLICATION_IS_DEBUG=true
; ============================================================
; === Client ===
; ============================================================
[Client]
......@@ -36,9 +42,11 @@ NDI_STREAM_NAME=LAPTOP-6ESNHBU6 (Test Pattern)
; === Algorithm ===
; ============================================================
[Algorithm]
;python.exe 进程路径 或 python命令
ALGORITHM_PYTHON_PATH=python
;算法启动 绝对路径 或 相对路径(相对于智能云台跟踪系统EXE文件的路径)
;ALGORITHM_SETUP_PATH=..\python\python.bat
ALGORITHM_SETUP_PATH=C:\Users\admin\Desktop\object_tracker\start.bat
ALGORITHM_SETUP_PATH=C:\Users\admin\Desktop\object_tracker\main.py
;算法命令行窗口显示样式
;Normal | Hidden | Minimized | Maximized
ALGORITHM_CMD_WINDOW_STYLE=Minimized
......@@ -46,13 +54,12 @@ ALGORITHM_CMD_WINDOW_STYLE=Minimized
; === Gimbal ===
; ============================================================
[Gimbal]
;云台启动 绝对路径 或 相对路径(相对于智能云台跟踪系统EXE文件的路径)
GIMBAL_SETUP_PATH=..\python\python.bat
;云台命令行窗口显示样式
;Normal | Hidden | Minimized | Maximized
GIMBAL_CMD_WINDOW_STYLE=Minimized
;云台中心轴移动速度
GIMBAL_CENTER_AXIS_SPEED=1
;云台中心轴X值
GIMBAL_CENTER_AXIS_X=960
;云台中心轴Y值
GIMBAL_CENTER_AXIS_Y=540
; ============================================================
; === Video ===
; ============================================================
......@@ -88,6 +95,6 @@ VIDEO_SIDE_CHECK_POLYGON_OPACITY=0.15
;视频人工校准区域透明度
VIDEO_MANUAL_CORRECTION_OPACITY=0.2
;中心轴宽度
VIDEO_CENTER_AXIS_WIDTH=2
VIDEO_CENTER_AXIS_WIDTH=3
;中心轴颜色
VIDEO_CENTER_AXIS_COLOR=#44000000
\ No newline at end of file
......@@ -13,6 +13,11 @@ namespace VIZ.GimbalAI.Module
public interface IControlViewService : IService
{
/// <summary>
/// 面板是否可用
/// </summary>
bool IsEnabled { get; set; }
/// <summary>
/// 是否是手动模式
/// </summary>
bool IsManualModeChecked { get; }
......
using log4net;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Common;
using VIZ.Framework.Domain;
using VIZ.GimbalAI.Domain;
using VIZ.GimbalAI.Storage;
namespace VIZ.GimbalAI.Module
{
/// <summary>
/// 算法控制器
/// </summary>
public class AlgorithmController
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(AlgorithmController));
/// <summary>
/// 算法那控制器
/// </summary>
/// <param name="support">支持</param>
public AlgorithmController(IAlgorithmSupport support)
{
this.Support = support;
}
/// <summary>
/// 支持
/// </summary>
public IAlgorithmSupport Support { get; private set; }
/// <summary>
/// python.exe 进程路径 或 python命令
/// </summary>
private readonly string ALGORITHM_PYTHON_PATH = ApplicationDomainEx.IniStorage.GetValue<AlgorithmConfig, string>(p => p.ALGORITHM_PYTHON_PATH);
/// <summary>
/// 算法启动 绝对路径 或 相对路径(相对于智能云台跟踪系统EXE文件的路径)
/// </summary>
private readonly string ALGORITHM_SETUP_PATH = ApplicationDomainEx.IniStorage.GetValue<AlgorithmConfig, string>(p => p.ALGORITHM_SETUP_PATH);
/// <summary>
/// 算法进程
/// </summary>
private Process Process;
/// <summary>
/// 重启算法
/// </summary>
public void Restart()
{
// 停止算法
this.Stop();
// 启动算法
this.Start();
}
/// <summary>
/// 启动算法
/// </summary>
private void Start()
{
IControlViewService service = ApplicationDomainEx.ServiceManager.GetService<IControlViewService>(ServiceKeys.ControlView);
if (service == null)
return;
service.IsEnabled = false;
Task.Run(() =>
{
// 算法启动路径
string fullPath = null;
Uri uri = new Uri(this.ALGORITHM_SETUP_PATH, UriKind.RelativeOrAbsolute);
if (uri.IsAbsoluteUri)
{
fullPath = uri.LocalPath;
}
else
{
fullPath = new Uri(new Uri(AppDomain.CurrentDomain.BaseDirectory), uri).LocalPath;
}
Process proc = new Process();
proc.StartInfo.UseShellExecute = true;
proc.StartInfo.FileName = this.ALGORITHM_PYTHON_PATH;
proc.StartInfo.Arguments = $"\"{fullPath}\"";
proc.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
if (!proc.Start())
{
log.Error($"算法启动失败!");
MessageBoxEx.ShowDialog($"算法启动失败!");
}
this.Process = proc;
});
}
/// <summary>
/// 停止算法
/// </summary>
public void Stop()
{
try
{
if (this.Process == null)
return;
this.Process.Kill();
}
catch (Exception ex)
{
log.Error(ex);
}
}
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Module
{
/// <summary>
/// 算法控制器支持
/// </summary>
public interface IAlgorithmSupport
{
}
}
......@@ -5,10 +5,11 @@
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
xmlns:module="clr-namespace:VIZ.GimbalAI.Module"
xmlns:common="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
d:DataContext="{d:DesignInstance Type=module:MainViewModel}"
Background="Black"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="1200">
d:DesignHeight="800" d:DesignWidth="1900">
<UserControl.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
......@@ -38,6 +39,16 @@
<!-- 标题 & 状态 -->
<StackPanel Orientation="Horizontal" Grid.ColumnSpan="3" Margin="10,0,0,10">
<TextBlock Text="智能云台跟拍系统" VerticalAlignment="Top" HorizontalAlignment="Left" FontSize="36" Foreground="White" ></TextBlock>
<common:DebugBorder Margin="20,0,20,10">
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
<TextBlock Text="调试信息 --" FontSize="20" Foreground="Red" Margin="0,0,10,0"></TextBlock>
<TextBlock Text="算法FPS:" FontSize="20" Foreground="Red" Margin="0,0,10,0"></TextBlock>
<TextBlock Text="{Binding Path=AlgorithmFPS.FPS,Mode=OneWay}" FontSize="20" Foreground="Red" Margin="0,0,10,0"></TextBlock>
<TextBlock Text="云台FPS:" FontSize="20" Foreground="Red" Margin="0,0,10,0"></TextBlock>
<TextBlock Text="{Binding Path=GimbalFPS.FPS,Mode=OneWay}" FontSize="20" Foreground="Red" Margin="0,0,10,0"></TextBlock>
<Button Width="120" Height="30" Margin="10,0,10,0" Content="重启算法" Command="{Binding Path=RestartAlgorithmCommand}"></Button>
</StackPanel>
</common:DebugBorder>
</StackPanel>
<Border HorizontalAlignment="Right" VerticalAlignment="Center" Height="50" Width="240" Background="#22ffffff" Grid.Column="1" Margin="0,0,30,0">
<TextBlock Text="{Binding Path=StatusMessage,Mode=OneWay}"
......
......@@ -18,15 +18,30 @@ namespace VIZ.GimbalAI.Module
/// <summary>
/// 主视图模型
/// </summary>
public class MainViewModel : ViewModelBase
public class MainViewModel : ViewModelBase, IAlgorithmSupport
{
public MainViewModel()
{
// 初始化命令
this.InitCommand();
// 初始化控制器
this.InitController();
// 初始化消息
this.InitMessage();
// 初始化FPS
this.InitFPS();
}
/// <summary>
/// 初始化FPS
/// </summary>
private void InitFPS()
{
this.AlgorithmFPS.Start();
this.GimbalFPS.Start();
}
/// <summary>
......@@ -39,6 +54,7 @@ namespace VIZ.GimbalAI.Module
this.MinCommand = new VCommand(this.Min);
this.ChangeNdiCommand = new VCommand(this.ChangeNdi);
this.ChangeNdiVideoDelayCommand = new VCommand(this.ChangeNdiVideoDelay);
this.RestartAlgorithmCommand = new VCommand(this.RestartAlgorithm);
}
/// <summary>
......@@ -47,9 +63,27 @@ namespace VIZ.GimbalAI.Module
private void InitMessage()
{
ApplicationDomainEx.MessageManager.Register<VideoRenderRectangleMessage>(this, this.VideoRenderRectangle);
ApplicationDomainEx.MessageManager.Register<GimbalCenterAxisMessage>(this, this.GimbalCenterAxis);
}
/// <summary>
/// 初始化控制器
/// </summary>
private void InitController()
{
this.AlgorithmController = new AlgorithmController(this);
}
// ======================================================================================
// === Controller ===
// ======================================================================================
/// <summary>
/// 算法控制器
/// </summary>
private AlgorithmController AlgorithmController;
// ======================================================================================
// === Property ===
// ======================================================================================
......@@ -81,6 +115,34 @@ namespace VIZ.GimbalAI.Module
#endregion
#region AlgorithmFPS -- 算法FPS模型
private FPSHelper algorithmFPS = new FPSHelper();
/// <summary>
/// 算法FPS模型
/// </summary>
public FPSHelper AlgorithmFPS
{
get { return algorithmFPS; }
set { algorithmFPS = value; this.RaisePropertyChanged(nameof(AlgorithmFPS)); }
}
#endregion
#region GimbalFPS -- 云台FPS模型
private FPSHelper gimbalFPS = new FPSHelper();
/// <summary>
/// 云台FPS模型
/// </summary>
public FPSHelper GimbalFPS
{
get { return gimbalFPS; }
set { gimbalFPS = value; this.RaisePropertyChanged(nameof(GimbalFPS)); }
}
#endregion
// ======================================================================================
// === Command ===
// ======================================================================================
......@@ -97,17 +159,16 @@ namespace VIZ.GimbalAI.Module
/// </summary>
private void Loaded()
{
// 加载完成后3秒执行加载流程
ApplicationDomainEx.DelayManager.Wait("VIZ.GimbalAI.Module.MainViewModel.Loaded", 3, () =>
// 执行加载流程
AppSetupContext context = AppSetup.Load(this.GetWindow());
if (!context.IsSuccess)
{
// 执行加载流程
AppSetupContext context = AppSetup.Load(this.GetWindow());
MessageBoxEx.ShowDialog($"执行 {context.ProviderDetail} 失败");
}
if (!context.IsSuccess)
{
MessageBoxEx.ShowDialog($"执行 {context.ProviderDetail} 失败");
}
});
// 启动算法
this.AlgorithmController.Restart();
}
#endregion
......@@ -212,6 +273,23 @@ namespace VIZ.GimbalAI.Module
#endregion
#region RestartAlgorithmCommand -- 重启算法命令
/// <summary>
/// 重启算法命令
/// </summary>
public VCommand RestartAlgorithmCommand { get; set; }
/// <summary>
/// 重启算法
/// </summary>
private void RestartAlgorithm()
{
this.AlgorithmController.Restart();
}
#endregion
// ======================================================================================
// === Message ===
// ======================================================================================
......@@ -250,9 +328,25 @@ namespace VIZ.GimbalAI.Module
break;
}
});
// 统计FPS
this.AlgorithmFPS.CalcFps();
}
#endregion
#region GimbalCenterAxisMessage -- 云台中心轴改变消息
/// <summary>
/// 云台中心轴改变消息
/// </summary>
/// <param name="msg">消息</param>
private void GimbalCenterAxis(GimbalCenterAxisMessage msg)
{
// 统计FPS
this.GimbalFPS.CalcFps();
}
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using VIZ.GimbalAI.Domain;
using VIZ.GimbalAI.Connection;
using VIZ.GimbalAI.Storage;
using VIZ.Framework.Module;
namespace VIZ.GimbalAI.Module
{
/// <summary>
/// 应用程序启动 -- 初始化中心轴
/// </summary>
public class AppSetup_InitCenterAxis : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(AppSetup_InitCenterAxis));
/// <summary>
/// 描述
/// </summary>
public override string Detail { get; } = "应用程序启动 -- 初始化中心轴";
/// <summary>
/// 执行启动
/// </summary>
/// <param name="context">应用程序启动上下文</param>
/// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context)
{
ApplicationDomainEx.GimbalControlModel.CenterAxisX = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, int>(p => p.GIMBAL_CENTER_AXIS_X);
ApplicationDomainEx.GimbalControlModel.CenterAxisY = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, int>(p => p.GIMBAL_CENTER_AXIS_Y);
ApplicationDomainEx.LoopManager.Register("AppSetup_InitCenterAxis.Setup", 30, () =>
{
this.WriteCenterAxis();
});
return true;
}
/// <summary>
/// 执行关闭
/// </summary>
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
this.WriteCenterAxis();
}
/// <summary>
/// 写入中心轴值
/// </summary>
private void WriteCenterAxis()
{
try
{
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_X, ApplicationDomainEx.GimbalControlModel.CenterAxisX);
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_Y, ApplicationDomainEx.GimbalControlModel.CenterAxisY);
}
catch (Exception ex)
{
log.Error(ex);
}
}
}
}
......@@ -184,6 +184,8 @@
<Compile Include="ControlView\View\ControlView.xaml.cs">
<DependentUpon>ControlView.xaml</DependentUpon>
</Compile>
<Compile Include="MainView\Controller\Algorithm\AlgorithmController.cs" />
<Compile Include="MainView\Controller\Algorithm\IAlgorithmSupport.cs" />
<Compile Include="MainView\ViewModel\MainViewModel.cs" />
<Compile Include="MainView\View\MainView.xaml.cs">
<DependentUpon>MainView.xaml</DependentUpon>
......@@ -207,6 +209,7 @@
</Compile>
<Compile Include="Setup\Provider\Load\AppSetup_SetupGimbal.cs" />
<Compile Include="Setup\Provider\Load\AppSetup_SetupAlgorithm.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_InitCenterAxis.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_InitNDI.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_InitCSV.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_InitUDP.cs" />
......
......@@ -78,7 +78,14 @@ namespace VIZ.GimbalAI.Module
view.videoControl.AttachPlugin(this.selectionBoxPlugin);
// 中心轴位置插件
// TODO : 中心轴位置插件
this.centerAxisPlugin = new CenterAxisPlugin(view.videoControl);
view.videoControl.AttachPlugin(this.centerAxisPlugin);
CenterAxisInfo centerAxisInfo = new CenterAxisInfo();
centerAxisInfo.AxisWidth = this.VIDEO_CENTER_AXIS_WIDTH;
centerAxisInfo.AxisColor = this.VIDEO_CENTER_AXIS_COLOR;
centerAxisInfo.SrcCenter = new RawVector2((float)ApplicationDomainEx.GimbalControlModel.CenterAxisX, (float)ApplicationDomainEx.GimbalControlModel.CenterAxisY);
this.centerAxisPlugin.Update(centerAxisInfo);
}
/// <summary>
......@@ -126,6 +133,11 @@ namespace VIZ.GimbalAI.Module
private SelectionBoxPlugin selectionBoxPlugin;
/// <summary>
/// 中心轴插件
/// </summary>
private CenterAxisPlugin centerAxisPlugin;
/// <summary>
/// 算法矩形框宽度(单位:像素)
/// </summary>
private readonly int VIDEO_TRACKING_BOX_BORDER_WIDTH = ApplicationDomainEx.IniStorage.GetValue<VideoConfig, int>(p => p.VIDEO_TRACKING_BOX_BORDER_WIDTH);
......
......@@ -13,7 +13,13 @@ namespace VIZ.GimbalAI.Storage
public class AlgorithmConfig : IniConfigBase
{
/// <summary>
/// 算法启动相对路径
/// python.exe 进程路径 或 python命令
/// </summary>
[Ini(Section = "Algorithm", DefaultValue = "python")]
public string ALGORITHM_PYTHON_PATH { get; set; }
/// <summary>
/// 算法启动 绝对路径 或 相对路径(相对于智能云台跟踪系统EXE文件的路径)
/// </summary>
[Ini(Section = "Algorithm", DefaultValue = @"..\python\python.bat")]
public string ALGORITHM_SETUP_PATH { get; set; }
......
......@@ -29,5 +29,17 @@ namespace VIZ.GimbalAI.Storage
/// </summary>
[Ini(Section = "Gimbal", DefaultValue = "1", Type = typeof(int))]
public string GIMBAL_CENTER_AXIS_SPEED { get; set; }
/// <summary>
/// 云台中心轴X位置
/// </summary>
[Ini(Section = "Gimbal", DefaultValue = "960", Type = typeof(int))]
public string GIMBAL_CENTER_AXIS_X { get; set; }
/// <summary>
/// 云台中心轴Y位置
/// </summary>
[Ini(Section = "Gimbal", DefaultValue = "540", Type = typeof(int))]
public string GIMBAL_CENTER_AXIS_Y { get; set; }
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment