Commit 6d894e9e by liulongfei

1. 安全框

2. 轴移动方向
parent 8c9bee4e
......@@ -22,8 +22,8 @@ namespace VIZ.GimbalAI.Client
AppSetup.AppendSetup(new AppSetup_InitCSV());
// 初始化 LiteDB
AppSetup.AppendSetup(new AppSetup_InitLiteDB());
// 初始化中心轴
//AppSetup.AppendSetup(new AppSetup_InitCenterAxis());
// 初始化 配置
AppSetup.AppendSetup(new AppSetup_InitConfig());
// 初始化 NDI
AppSetup.AppendSetup(new AppSetup_InitNDI());
// 初始化 UDP
......
......@@ -17,8 +17,8 @@ CLIENT_CONSOLE_LOG_MAX_LINE=500
; ============================================================
[UDP]
;客户端UDP绑定IP
CLIENT_BINDING_IP=192.168.0.124
;CLIENT_BINDING_IP=127.0.0.1
;CLIENT_BINDING_IP=192.168.0.124
CLIENT_BINDING_IP=127.0.0.1
;CLIENT_BINDING_IP=192.168.88.242
;客户端UDP绑定端口
CLIENT_BINDING_PORT=8000
......@@ -50,6 +50,14 @@ ALGORITHM_SETUP_PATH=C:\Users\admin\Desktop\object_tracker\main.py
;算法命令行窗口显示样式
;Normal | Hidden | Minimized | Maximized
ALGORITHM_CMD_WINDOW_STYLE=Minimized
;算法安全框宽度
;ALGORITHM_SAVE_WIDTH=1600
ALGORITHM_SAVE_WIDTH=400
;算法安全框高度
;ALGORITHM_SAVE_HEIGHT=900
ALGORITHM_SAVE_HEIGHT=300
;算法安全框颜色
ALGORITHM_SAVE_COLOR=#FF0000FF
; ============================================================
; === Gimbal ===
; ============================================================
......
......@@ -5,6 +5,7 @@ using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Connection;
using VIZ.Framework.Core;
using VIZ.Framework.Domain;
using VIZ.GimbalAI.Domain;
using VIZ.GimbalAI.Storage;
......@@ -22,11 +23,6 @@ namespace VIZ.GimbalAI.Connection
public string Signal { get; } = GimbalPackageSignal.center_axis;
/// <summary>
/// 云台中心轴移动速度
/// </summary>
private static readonly double GIMBAL_CENTER_AXIS_SPEED = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, double>(p => p.GIMBAL_CENTER_AXIS_SPEED);
/// <summary>
/// 执行
/// </summary>
/// <param name="packageInfo">包信息</param>
......@@ -42,11 +38,13 @@ namespace VIZ.GimbalAI.Connection
if (package.h != 0 && (Math.Abs(package.h) < 10000))
{
x += -ApplicationDomainEx.GimbalControlModel.TargetKeepSymbolHelperX.GetSymbol(package.h) * GIMBAL_CENTER_AXIS_SPEED;
int symbol = ApplicationDomainEx.GimbalControlModel.HorizontalRockerDirection == RockerDirection.Forward ? -1 : 1;
x += symbol * ApplicationDomainEx.GimbalControlModel.TargetKeepSymbolHelperX.GetSymbol(package.h) * ApplicationDomainEx.GimbalControlModel.CenterAxisSpeed;
}
if (package.v != 0 && (Math.Abs(package.v) < 10000))
{
y += -ApplicationDomainEx.GimbalControlModel.TargetKeepSymbolHelperY.GetSymbol(package.v) * GIMBAL_CENTER_AXIS_SPEED;
int symbol = ApplicationDomainEx.GimbalControlModel.VerticalRockerDirection == RockerDirection.Forward ? -1 : 1;
y += symbol * ApplicationDomainEx.GimbalControlModel.TargetKeepSymbolHelperY.GetSymbol(package.v) * ApplicationDomainEx.GimbalControlModel.CenterAxisSpeed;
}
x = MathHelper.Clip(0, 1920, x);
......
......@@ -4,7 +4,11 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
......
......@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Framework.Domain;
namespace VIZ.GimbalAI.Domain
{
......@@ -21,6 +22,8 @@ namespace VIZ.GimbalAI.Domain
this.Classes = new List<AlgorithmClassModel>();
this.Classes.Add(new AlgorithmClassModel { IsChecked = true, Label = "person", Value = 0 });
this.Classes.Add(new AlgorithmClassModel { IsChecked = true, Label = "bus", Value = 5 });
}
#region Scene -- 场景
......@@ -64,5 +67,33 @@ namespace VIZ.GimbalAI.Domain
}
#endregion
#region SaveWidth -- 安全宽度
private int saveWidth;
/// <summary>
/// 安全宽度
/// </summary>
public int SaveWidth
{
get { return saveWidth; }
set { saveWidth = value; this.RaisePropertyChanged(nameof(SaveWidth)); }
}
#endregion
#region SaveHeight -- 安全高度
private int saveHeight;
/// <summary>
/// 安全高度
/// </summary>
public int SaveHeight
{
get { return saveHeight; }
set { saveHeight = value; this.RaisePropertyChanged(nameof(SaveHeight)); }
}
#endregion
}
}
......@@ -4,6 +4,7 @@ using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.Framework.Domain;
namespace VIZ.GimbalAI.Domain
{
......@@ -43,6 +44,21 @@ namespace VIZ.GimbalAI.Domain
public KeepSymbolHelper TargetKeepSymbolHelperY { get; private set; } = new KeepSymbolHelper(3, 2);
/// <summary>
/// 操作杆水平移动方向
/// </summary>
public RockerDirection HorizontalRockerDirection { get; set; } = RockerDirection.Forward;
/// <summary>
/// 操作杆垂直移动方向
/// </summary>
public RockerDirection VerticalRockerDirection { get; set; } = RockerDirection.Forward;
/// <summary>
/// 中心轴移动速度
/// </summary>
public int CenterAxisSpeed { get; set; } = 3;
/// <summary>
/// 更新中心轴
/// </summary>
/// <returns>中心轴是否有变化</returns>
......
......@@ -4,7 +4,11 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
......
......@@ -14,7 +14,7 @@
</Grid.ColumnDefinitions>
<ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Left"></ContentPresenter>
<Image Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center"
Width="20" Height="20" Opacity="0.7"
Width="14" Height="14" Opacity="0.7"
Source="/VIZ.GimbalAI.Module.Resource;component/Icons/down_24x24.png"></Image>
</Grid>
</Border>
......
......@@ -146,5 +146,8 @@
<Name>VIZ.GimbalAI.Common.Resource</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<Resource Include="Icons\left_right_32x32.png" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
\ No newline at end of file
......@@ -6,6 +6,7 @@
xmlns:local="clr-namespace:VIZ.GimbalAI.Module"
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
xmlns:converter="clr-namespace:VIZ.Framework.Core;assembly=VIZ.Framework.Core"
xmlns:common="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
d:DataContext="{d:DesignInstance Type=local:ControlViewModel}"
mc:Ignorable="d" x:Name="uc"
d:DesignHeight="800" d:DesignWidth="300">
......@@ -25,6 +26,7 @@
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="300"></RowDefinition>
</Grid.RowDefinitions>
<Grid IsEnabled="{Binding Path=IsEnabled,Mode=OneWay}">
<Grid.RowDefinitions>
......@@ -69,8 +71,8 @@
</Grid.RowDefinitions>
<TextBlock Text="识别算法" Foreground="#aaffffff" VerticalAlignment="Center" HorizontalAlignment="Left" FontSize="20"></TextBlock>
<ComboBox Grid.Row="1" Height="50" VerticalAlignment="Center" Style="{StaticResource ComboBox_AlgorithmScene}"
ItemsSource="{Binding Path=AlgorithmSceneItems}" Foreground="White" FontSize="18"
SelectedValue="{Binding Path=AlgorithmScene,Mode=TwoWay}">
ItemsSource="{Binding Path=AlgorithmSceneItems}" Foreground="White" FontSize="18"
SelectedValue="{Binding Path=AlgorithmScene,Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Label}"></TextBlock>
......@@ -113,9 +115,98 @@
</Border>
</Grid>
<!-- 控制台输出 -->
<!--<Border Grid.Row="1">
<local:ConsoleView></local:ConsoleView>
</Border>-->
<!-- 参数设置 -->
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="3*"></RowDefinition>
<RowDefinition Height="2*"></RowDefinition>
</Grid.RowDefinitions>
<!-- 构图轴 -->
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border BorderBrush="#ff33333b" BorderThickness="1" Background="#22ffffff" Grid.ColumnSpan="2">
<TextBlock Text="构图轴摇杆移动方向" Foreground="White" Opacity="0.7" FontSize="18"
VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0"></TextBlock>
</Border>
<!-- 水平 -->
<Image Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" Width="26" Height="26"
Source="/VIZ.GimbalAI.Module.Resource;component/Icons/left_right_32x32.png"></Image>
<ComboBox Grid.Row="1" Grid.Column="1" Height="30" VerticalAlignment="Center" Margin="0,0,10,0"
Style="{StaticResource ComboBox_AlgorithmScene}"
ItemsSource="{Binding Path=RockerDirectionItems}" Foreground="White" FontSize="18"
SelectedValue="{Binding Path=HorizontalRockerDirection,Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Description}"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- 垂直 -->
<Image Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Center" Width="26" Height="26"
Source="/VIZ.GimbalAI.Module.Resource;component/Icons/left_right_32x32.png" RenderTransformOrigin="0.5 0.5">
<Image.RenderTransform>
<RotateTransform Angle="90"></RotateTransform>
</Image.RenderTransform>
</Image>
<ComboBox Grid.Row="2" Grid.Column="1" Height="30" VerticalAlignment="Center" Margin="0,0,10,0"
Style="{StaticResource ComboBox_AlgorithmScene}"
ItemsSource="{Binding Path=RockerDirectionItems}" Foreground="White" FontSize="18"
SelectedValue="{Binding Path=VerticalRockerDirection,Mode=TwoWay}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Path=Description}"></TextBlock>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<!-- 速度 -->
<TextBlock Text="速度" Grid.Row="3" HorizontalAlignment="Center" VerticalAlignment="Center"
Foreground="White" FontSize="16"></TextBlock>
<common:NumberBox Grid.Row="3" Grid.Column="1" IsShowUpAndDownButton="False" Height="30"
Foreground="White" FontSize="16" BorderBrush="#99FFFFFF"
MinValue="1" MaxValue="10" Margin="0,0,10,0"
Value="{Binding Path=CenterAxisSpeed,Mode=TwoWay}"></common:NumberBox>
</Grid>
<!-- 安全框 -->
<Grid Grid.Row="1">
<Grid.RowDefinitions>
<RowDefinition Height="30"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="80"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Border BorderBrush="#ff33333b" BorderThickness="1" Background="#22ffffff" Grid.ColumnSpan="2">
<TextBlock Text="安全框" Foreground="White" Opacity="0.7" FontSize="18"
VerticalAlignment="Center" HorizontalAlignment="Left" Margin="10,0,0,0"></TextBlock>
</Border>
<!-- 宽度 -->
<TextBlock Text="宽度" Grid.Row="1" FontSize="16" Foreground="White"
VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<common:NumberBox Grid.Column="1" Grid.Row="1" IsShowUpAndDownButton="False" Foreground="White"
BorderBrush="#99FFFFFF" FontSize="16" MinValue="100" MaxValue="1920" Interval="1"
Height="30" Margin="0,0,10,0"
Value="{Binding Path=AlgorithmSaveWidth,Mode=TwoWay}"></common:NumberBox>
<!-- 高度 -->
<TextBlock Text="高度" Grid.Row="2" FontSize="16" Foreground="White"
VerticalAlignment="Center" HorizontalAlignment="Center"></TextBlock>
<common:NumberBox Grid.Column="1" Grid.Row="2" IsShowUpAndDownButton="False" Foreground="White"
BorderBrush="#99FFFFFF" FontSize="16" MinValue="100" MaxValue="1080" Interval="1"
Height="30" Margin="0,0,10,0"
Value="{Binding Path=AlgorithmSaveHeight,Mode=TwoWay}"></common:NumberBox>
</Grid>
</Grid>
</Grid>
</UserControl>
......@@ -8,6 +8,8 @@ using VIZ.GimbalAI.Connection;
using VIZ.GimbalAI.Domain.Message;
using VIZ.GimbalAI.Domain;
using VIZ.Framework.Connection;
using VIZ.Framework.Domain;
using VIZ.GimbalAI.Storage;
namespace VIZ.GimbalAI.Module
{
......@@ -29,11 +31,6 @@ namespace VIZ.GimbalAI.Module
// 初始化消息
this.InitMessage();
// TODO: 正式删除
// 切换自动模式
//this.ChangeAutoMode();
//this.IsEnabled = true;
}
/// <summary>
......@@ -52,6 +49,14 @@ namespace VIZ.GimbalAI.Module
this.AlgorithmSceneItems = ApplicationDomainEx.AlgorithmAutoSetting.Scenes;
this.AlgorithmScene = ApplicationDomainEx.AlgorithmAutoSetting.Scene;
this.AlgorithmClassItems = ApplicationDomainEx.AlgorithmAutoSetting.Classes;
this.RockerDirectionItems = EnumHelper.GetEnumModels<RockerDirection>();
this.horizontalRockerDirection = this.RockerDirectionItems.FirstOrDefault(p => (RockerDirection)p.Key == ApplicationDomainEx.GimbalControlModel.HorizontalRockerDirection);
this.verticalRockerDirection = this.RockerDirectionItems.FirstOrDefault(p => (RockerDirection)p.Key == ApplicationDomainEx.GimbalControlModel.VerticalRockerDirection);
this.CenterAxisSpeed = ApplicationDomainEx.GimbalControlModel.CenterAxisSpeed;
this.AlgorithmSaveWidth = ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth;
this.algorithmSaveHeight = ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight;
}
/// <summary>
......@@ -232,6 +237,117 @@ namespace VIZ.GimbalAI.Module
#endregion
#region VerticalRockerDirection -- 垂直摇杆方向
private EnumModel verticalRockerDirection;
/// <summary>
/// 垂直摇杆方向
/// <see cref="RockerDirection"/>
/// </summary>
public EnumModel VerticalRockerDirection
{
get { return verticalRockerDirection; }
set
{
verticalRockerDirection = value;
this.RaisePropertyChanged(nameof(VerticalRockerDirection));
ApplicationDomainEx.GimbalControlModel.VerticalRockerDirection = (RockerDirection)value.Key;
}
}
#endregion
#region HorizontalRockerDirection -- 水平摇杆方向
private EnumModel horizontalRockerDirection;
/// <summary>
/// 水平摇杆方向
/// <see cref="RockerDirection"/>
/// </summary>
public EnumModel HorizontalRockerDirection
{
get { return horizontalRockerDirection; }
set
{
horizontalRockerDirection = value;
this.RaisePropertyChanged(nameof(HorizontalRockerDirection));
ApplicationDomainEx.GimbalControlModel.HorizontalRockerDirection = (RockerDirection)value.Key;
}
}
#endregion
#region RockerDirectionItems -- 摇杆方向列表
private List<EnumModel> rockerDirectionItems;
/// <summary>
/// 摇杆方向列表
/// </summary>
public List<EnumModel> RockerDirectionItems
{
get { return rockerDirectionItems; }
set { rockerDirectionItems = value; this.RaisePropertyChanged(nameof(RockerDirectionItems)); }
}
#endregion
#region CenterAxisSpeed -- 中心轴移动速度
private double centerAxisSpeed;
/// <summary>
/// 中心轴移动速度
/// </summary>
public double CenterAxisSpeed
{
get { return centerAxisSpeed; }
set
{
centerAxisSpeed = value;
this.RaisePropertyChanged(nameof(CenterAxisSpeed));
ApplicationDomainEx.GimbalControlModel.CenterAxisSpeed = (int)value;
}
}
#endregion
#region AlgorithmSaveWidth -- 算法安全框宽度
private double algorithmSaveWidth;
/// <summary>
/// 算法安全框宽度
/// </summary>
public double AlgorithmSaveWidth
{
get { return algorithmSaveWidth; }
set
{
algorithmSaveWidth = value;
this.RaisePropertyChanged(nameof(AlgorithmSaveWidth));
ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth = (int)value;
}
}
#endregion
#region AlgorithmSaveHeight -- 算法安全框高度
private double algorithmSaveHeight;
/// <summary>
/// 算法安全框高度
/// </summary>
public double AlgorithmSaveHeight
{
get { return algorithmSaveHeight; }
set
{
algorithmSaveHeight = value;
this.RaisePropertyChanged(nameof(AlgorithmSaveHeight));
ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight = (int)value;
}
}
#endregion
// ==============================================================================================
// === Command ===
// ==============================================================================================
......
......@@ -41,15 +41,20 @@
<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>
<Button Width="120" Height="30" Margin="10,0,10,0" Content="重启算法"
<TextBlock Text="算法FPS:" FontSize="20" Foreground="Red" Margin="0,0,10,0"
VerticalAlignment="Center"></TextBlock>
<TextBlock Text="{Binding Path=AlgorithmFPS.FPS,Mode=OneWay}" FontSize="20" Foreground="Red"
Margin="0,0,10,0" VerticalAlignment="Center"></TextBlock>
<Button Width="80" Height="30" Margin="10,0,10,0" Content="重启算法" VerticalAlignment="Center"
IsEnabled="{Binding Path=IsRestartAlgorithmEnabled,Mode=OneWay}"
Command="{Binding Path=RestartAlgorithmCommand,Mode=OneWay}"></Button>
</StackPanel>
</common:DebugBorder>
</StackPanel>
<Border Grid.Column="1" VerticalAlignment="Center" HorizontalAlignment="Center">
<common:ShowMessageControl Foreground="White" Background="#66FFFFFF"
MessageKey="{x:Static Member=module:MainView.MAIN_VIEW_TOP_MESSAGE_KEY}"></common:ShowMessageControl>
</Border>
<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}"
Foreground="{Binding Path=StatusMessageBrush,Mode=OneWay}"
......@@ -71,5 +76,6 @@
<!-- 控制区域 -->
<module:ControlView Grid.Row="1" Grid.Column="2"></module:ControlView>
<!-- 底栏 -->
</Grid>
</UserControl>
......@@ -30,5 +30,10 @@ namespace VIZ.GimbalAI.Module
WPFHelper.BindingViewModel(this, new MainViewModel());
}
/// <summary>
/// 主视图头部消息键
/// </summary>
public const string MAIN_VIEW_TOP_MESSAGE_KEY = "MAIN_VIEW_TOP_MESSAGE_KEY";
}
}
......@@ -320,6 +320,15 @@ namespace VIZ.GimbalAI.Module
/// </summary>
private void RestartAlgorithm()
{
ShowMessage msg = new ShowMessage();
msg.MessageKey = MainView.MAIN_VIEW_TOP_MESSAGE_KEY;
msg.Message = $"请在安全框范围内操作!";
ApplicationDomainEx.MessageManager.Send(msg);
return;
// ===============================================
this.IsRestartAlgorithmEnabled = false;
this.AlgorithmController.Restart();
}
......@@ -383,6 +392,7 @@ namespace VIZ.GimbalAI.Module
}
#endregion
// ======================================================================================
// === Private Function ===
// ======================================================================================
......
......@@ -8,23 +8,24 @@ using VIZ.GimbalAI.Domain;
using VIZ.GimbalAI.Connection;
using VIZ.GimbalAI.Storage;
using VIZ.Framework.Module;
using VIZ.Framework.Domain;
namespace VIZ.GimbalAI.Module
{
/// <summary>
/// 应用程序启动 -- 初始化中心轴
/// 应用程序启动 -- 初始化配置
/// </summary>
public class AppSetup_InitCenterAxis : AppSetupBase
public class AppSetup_InitConfig : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private readonly static ILog log = LogManager.GetLogger(typeof(AppSetup_InitCenterAxis));
private readonly static ILog log = LogManager.GetLogger(typeof(AppSetup_InitConfig));
/// <summary>
/// 描述
/// </summary>
public override string Detail { get; } = "应用程序启动 -- 初始化中心轴";
public override string Detail { get; } = "应用程序启动 -- 初始化配置";
/// <summary>
/// 执行启动
......@@ -33,13 +34,17 @@ namespace VIZ.GimbalAI.Module
/// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context)
{
ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, int>(p => p.GIMBAL_CENTER_AXIS_X);
ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, int>(p => p.GIMBAL_CENTER_AXIS_Y);
// 算法安全框
ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth = ApplicationDomainEx.IniStorage.GetValue<AlgorithmConfig, int>(p => p.ALGORITHM_SAVE_WIDTH);
ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight = ApplicationDomainEx.IniStorage.GetValue<AlgorithmConfig, int>(p => p.ALGORITHM_SAVE_HEIGHT);
ApplicationDomainEx.LoopManager.Register("AppSetup_InitCenterAxis.Setup", 30, () =>
{
this.WriteCenterAxis();
});
// 控制轴方向
ApplicationDomainEx.GimbalControlModel.HorizontalRockerDirection = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, string>(p => p.GIMBAL_CENTER_AXIS_HORIZONTAL_DIRECTION) == RockerDirection.Forward.ToString() ? RockerDirection.Forward : RockerDirection.Backward;
ApplicationDomainEx.GimbalControlModel.VerticalRockerDirection = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, string>(p => p.GIMBAL_CENTER_AXIS_VERTICAL_DIRECTION) == RockerDirection.Forward.ToString() ? RockerDirection.Forward : RockerDirection.Backward;
ApplicationDomainEx.GimbalControlModel.CenterAxisSpeed = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, int>(p => p.GIMBAL_CENTER_AXIS_SPEED);
// 注册参数保存循环
ApplicationDomainEx.LoopManager.Register("AppSetup_InitConfig.saveIniConfig", 60, this.saveIniConfig);
return true;
}
......@@ -50,23 +55,22 @@ namespace VIZ.GimbalAI.Module
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
this.WriteCenterAxis();
this.saveIniConfig();
}
/// <summary>
/// 写入中心轴值
/// 保存Ini配置
/// </summary>
private void WriteCenterAxis()
private void saveIniConfig()
{
try
{
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_X, ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX);
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_Y, ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY);
}
catch (Exception ex)
{
log.Error(ex);
}
// 算法安全框
ApplicationDomainEx.IniStorage.SetValue<AlgorithmConfig>(p => p.ALGORITHM_SAVE_WIDTH, ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth);
ApplicationDomainEx.IniStorage.SetValue<AlgorithmConfig>(p => p.ALGORITHM_SAVE_HEIGHT, ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight);
// 控制轴方向
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_HORIZONTAL_DIRECTION, ApplicationDomainEx.GimbalControlModel.HorizontalRockerDirection);
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_VERTICAL_DIRECTION, ApplicationDomainEx.GimbalControlModel.VerticalRockerDirection);
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_SPEED, ApplicationDomainEx.GimbalControlModel.CenterAxisSpeed);
}
}
}
......@@ -215,7 +215,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_InitConfig.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" />
......
......@@ -19,6 +19,7 @@ using OpenCvSharp.Extensions;
using SharpDX.Mathematics.Interop;
using VIZ.Framework.Storage;
using System.Windows.Interop;
using System.Web.UI.WebControls;
namespace VIZ.GimbalAI.Module
{
......@@ -46,6 +47,11 @@ namespace VIZ.GimbalAI.Module
}
/// <summary>
/// 算法安全框颜色
/// </summary>
private readonly static RawColor4 ALGORITHM_SAVE_COLOR = ApplicationDomainEx.IniStorage.GetValue<AlgorithmConfig, RawColor4>(p => p.ALGORITHM_SAVE_COLOR);
/// <summary>
/// 初始化NDI
/// </summary>
private void InitNDI()
......@@ -82,11 +88,27 @@ namespace VIZ.GimbalAI.Module
this.centerAxisPlugin = new CenterAxisPlugin(view.videoControl);
view.videoControl.AttachPlugin(this.centerAxisPlugin);
// 裁切插件 -- 用于显示安全框
this.clipBoxPlugin = new ClipBoxPlugin(view.videoControl);
view.videoControl.AttachPlugin(this.clipBoxPlugin);
// 更新中心轴
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.TargetCenterAxisX, (float)ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY);
this.centerAxisPlugin.Update(centerAxisInfo);
// 更新安全框
ClipBoxInfo clipBoxInfo = new ClipBoxInfo();
float left = (1920 - ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth) / 2f;
float top = (1080 - ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight) / 2f;
float right = left + ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth;
float bottom = top + ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight;
clipBoxInfo.SrcRect = new RawRectangleF(left, top, right, bottom);
clipBoxInfo.DrawingBorderWidth = 4;
clipBoxInfo.DrawingBorderColor = ALGORITHM_SAVE_COLOR;
this.clipBoxPlugin.Update(clipBoxInfo);
}
/// <summary>
......@@ -138,6 +160,11 @@ namespace VIZ.GimbalAI.Module
private CenterAxisPlugin centerAxisPlugin;
/// <summary>
/// 裁切框插件 -- 用于显示安全框
/// </summary>
private ClipBoxPlugin clipBoxPlugin;
/// <summary>
/// 算法矩形框宽度(单位:像素)
/// </summary>
private readonly int VIDEO_TRACKING_BOX_BORDER_WIDTH = ApplicationDomainEx.IniStorage.GetValue<VideoConfig, int>(p => p.VIDEO_TRACKING_BOX_BORDER_WIDTH);
......@@ -421,6 +448,9 @@ namespace VIZ.GimbalAI.Module
// 更新视频
view.videoControl.UpdateVideoFrame(e.Frame);
// 更新安全框
this.UpdateSaveRect(view);
// 更新中心轴
this.UpdateCenterAxis(view);
}
......@@ -448,6 +478,23 @@ namespace VIZ.GimbalAI.Module
}
/// <summary>
/// 更新安全框
/// </summary>
/// <param name="view">视图</param>
private void UpdateSaveRect(VideoView view)
{
ClipBoxInfo clipBoxInfo = new ClipBoxInfo();
float left = (1920 - ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth) / 2f;
float top = (1080 - ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight) / 2f;
float right = left + ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth;
float bottom = top + ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight;
clipBoxInfo.SrcRect = new RawRectangleF(left, top, right, bottom);
clipBoxInfo.DrawingBorderWidth = 4;
clipBoxInfo.DrawingBorderColor = ALGORITHM_SAVE_COLOR;
view.videoControl.UpdateClipBox(clipBoxInfo);
}
/// <summary>
/// 处理视频点击跟踪框事件
/// </summary>
private void TrackingBoxPlugin_TrackingBoxClick(object sender, TrackingBoxClickEventArgs e)
......@@ -455,6 +502,10 @@ namespace VIZ.GimbalAI.Module
if (!this.IsRectangleClickTrigger || e.HitTrackingBoxInfo == null)
return;
// 在安全框范围外点击不生效
if (!this.checkIsInSaveRect(e.HitTrackingBoxInfo.SrcRect))
return;
// 向算法发送 UDP 消息
UdpEndpointManager manager = ConnectionManager.UdpConnection.GetEndpointManager(UdpEndpointKeys.algorithm);
if (manager == null)
......@@ -487,6 +538,10 @@ namespace VIZ.GimbalAI.Module
if (!this.IsRectangleFrameSelectionTrigger)
return;
// 在安全框范围外点击不生效
if (!this.checkIsInSaveRect(e.SrcRect))
return;
// 向算法发送 UDP 消息
UdpEndpointManager manager = ConnectionManager.UdpConnection.GetEndpointManager(UdpEndpointKeys.algorithm);
if (manager == null)
......@@ -495,5 +550,36 @@ namespace VIZ.GimbalAI.Module
List<float> roi = new List<float> { e.SrcRect.Left, e.SrcRect.Top, e.SrcRect.Right - e.SrcRect.Left, e.SrcRect.Bottom - e.SrcRect.Top };
AlgorithmSender.ManualDetect(manager, roi);
}
/// <summary>
/// 校验是否是在安全框范围内
/// </summary>
/// <param name="rect">矩形区域</param>
/// <returns>是否是在安全框范围内</returns>
private bool checkIsInSaveRect(RawRectangleF rect)
{
// 在安全框范围外点击不生效
float center_x = rect.Left + (rect.Right - rect.Left) / 2f;
float center_y = rect.Top + (rect.Bottom - rect.Top) / 2f;
float left = (1920 - ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth) / 2f;
float top = (1080 - ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight) / 2f;
float right = left + ApplicationDomainEx.AlgorithmAutoSetting.SaveWidth;
float bottom = top + ApplicationDomainEx.AlgorithmAutoSetting.SaveHeight;
// 不处理在安全框以外的数据
if (center_x < left || center_x > right || center_y < top || center_y > bottom)
{
ShowMessage msg = new ShowMessage();
msg.MessageKey = MainView.MAIN_VIEW_TOP_MESSAGE_KEY;
msg.Message = $"请在安全框范围内操作!";
ApplicationDomainEx.MessageManager.Send(msg);
return false;
}
return true;
}
}
}
using System;
using SharpDX.Mathematics.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
......@@ -29,5 +30,23 @@ namespace VIZ.GimbalAI.Storage
/// </summary>
[Ini(Section = "Algorithm", DefaultValue = "Minimized")]
public string ALGORITHM_CMD_WINDOW_STYLE { get; set; }
/// <summary>
/// 算法安全框宽度
/// </summary>
[Ini(Section = "Algorithm", DefaultValue = "1600", Type = typeof(int))]
public string ALGORITHM_SAVE_WIDTH { get; set; }
/// <summary>
/// 算法安全框高度
/// </summary>
[Ini(Section = "Algorithm", DefaultValue = "900", Type = typeof(int))]
public string ALGORITHM_SAVE_HEIGHT { get; set; }
/// <summary>
/// 算法安全框颜色
/// </summary>
[Ini(Section = "Algorithm", DefaultValue = "#FF0000FF", Type = typeof(RawColor4))]
public string ALGORITHM_SAVE_COLOR { get; set; }
}
}
......@@ -31,15 +31,17 @@ namespace VIZ.GimbalAI.Storage
public string GIMBAL_CENTER_AXIS_SPEED { get; set; }
/// <summary>
/// 云台中心轴X位置
/// 云台中心轴水平移动方向 Forward | Backward
/// <see cref="VIZ.Framework.Domain.RockerDirection"/>
/// </summary>
[Ini(Section = "Gimbal", DefaultValue = "960", Type = typeof(int))]
public string GIMBAL_CENTER_AXIS_X { get; set; }
[Ini(Section = "Gimbal", DefaultValue = "Forward", Type = typeof(string))]
public string GIMBAL_CENTER_AXIS_HORIZONTAL_DIRECTION { get; set; }
/// <summary>
/// 云台中心轴Y位置
/// 云台中心轴垂直移动方向 Forward | Backward
/// <see cref="VIZ.Framework.Domain.RockerDirection"/>
/// </summary>
[Ini(Section = "Gimbal", DefaultValue = "540", Type = typeof(int))]
public string GIMBAL_CENTER_AXIS_Y { get; set; }
[Ini(Section = "Gimbal", DefaultValue = "Forward", Type = typeof(string))]
public string GIMBAL_CENTER_AXIS_VERTICAL_DIRECTION { get; set; }
}
}
......@@ -88,6 +88,9 @@
<Reference Include="Microsoft.Bcl.HashCode, Version=1.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\Microsoft.Bcl.HashCode.1.0.0\lib\net461\Microsoft.Bcl.HashCode.dll</HintPath>
</Reference>
<Reference Include="SharpDX, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b4dcf0f35e5521f1, processorArchitecture=MSIL">
<HintPath>..\packages\SharpDX.4.2.0\lib\net45\SharpDX.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Buffers, Version=4.0.2.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL">
<HintPath>..\packages\System.Buffers.4.4.0\lib\netstandard2.0\System.Buffers.dll</HintPath>
......
......@@ -7,6 +7,7 @@
<package id="Microsoft.Bcl.HashCode" version="1.0.0" targetFramework="net48" />
<package id="Microsoft.CSharp" version="4.3.0" targetFramework="net48" />
<package id="Portable.BouncyCastle" version="1.8.9" targetFramework="net48" />
<package id="SharpDX" version="4.2.0" targetFramework="net48" />
<package id="SharpZipLib" version="1.3.3" targetFramework="net48" />
<package id="System.Buffers" version="4.4.0" targetFramework="net48" />
<package id="System.Memory" version="4.5.0" targetFramework="net48" />
......
......@@ -7,7 +7,11 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
......
......@@ -4,7 +4,11 @@
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="System.Runtime.CompilerServices.Unsafe" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.4.1" newVersion="4.0.4.1" />
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
</dependentAssembly>
<dependentAssembly>
<assemblyIdentity name="System.Memory" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-4.0.1.1" newVersion="4.0.1.1" />
</dependentAssembly>
</assemblyBinding>
</runtime>
......
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