Commit 184ebf26 by liulongfei

更新轴跟踪逻辑

parent c2b96bb8
...@@ -23,8 +23,8 @@ CLIENT_BINDING_IP=192.168.0.124 ...@@ -23,8 +23,8 @@ CLIENT_BINDING_IP=192.168.0.124
;客户端UDP绑定端口 ;客户端UDP绑定端口
CLIENT_BINDING_PORT=8000 CLIENT_BINDING_PORT=8000
;算法UDP绑定IP ;算法UDP绑定IP
ALGORITHM_BINDING_IP=192.168.0.117 ;ALGORITHM_BINDING_IP=192.168.0.117
;ALGORITHM_BINDING_IP=127.0.0.1 ALGORITHM_BINDING_IP=127.0.0.1
;算法UDP绑定端口 ;算法UDP绑定端口
ALGORITHM_BINDING_PORT=8001 ALGORITHM_BINDING_PORT=8001
;云台UDP绑定IP ;云台UDP绑定IP
...@@ -55,7 +55,7 @@ ALGORITHM_CMD_WINDOW_STYLE=Minimized ...@@ -55,7 +55,7 @@ ALGORITHM_CMD_WINDOW_STYLE=Minimized
; ============================================================ ; ============================================================
[Gimbal] [Gimbal]
;云台中心轴移动速度 ;云台中心轴移动速度
GIMBAL_CENTER_AXIS_SPEED=2 GIMBAL_CENTER_AXIS_SPEED=3
;云台中心轴X值 ;云台中心轴X值
GIMBAL_CENTER_AXIS_X=960 GIMBAL_CENTER_AXIS_X=960
;云台中心轴Y值 ;云台中心轴Y值
......
...@@ -37,22 +37,22 @@ namespace VIZ.GimbalAI.Connection ...@@ -37,22 +37,22 @@ namespace VIZ.GimbalAI.Connection
return; return;
// 更新坐标位置 // 更新坐标位置
double x = ApplicationDomainEx.GimbalControlModel.CenterAxisX + (package.h > 0 ? 1 : -1) * GIMBAL_CENTER_AXIS_SPEED; double x = ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX;
double y = ApplicationDomainEx.GimbalControlModel.CenterAxisY + (package.v > 0 ? 1 : -1) * GIMBAL_CENTER_AXIS_SPEED; double y = ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY;
x = MathHelper.Clip(0, 1920, x);
y = MathHelper.Clip(0, 1080, y);
ApplicationDomainEx.GimbalControlModel.CenterAxisX = x;
ApplicationDomainEx.GimbalControlModel.CenterAxisY = y;
// 向算法发送最新的中心轴位置 if (package.h != 0)
UdpEndpointManager manager = ConnectionManager.UdpConnection.GetEndpointManager(UdpEndpointKeys.algorithm); {
AlgorithmSender.CenterAxis(manager); x += (package.h > 0 ? -1 : 1) * GIMBAL_CENTER_AXIS_SPEED;
}
if (package.v != 0)
{
y += (package.v > 0 ? -1 : 1) * GIMBAL_CENTER_AXIS_SPEED;
}
// 向界面发送更新轴信息消息 x = MathHelper.Clip(0, 1920, x);
GimbalCenterAxisMessage message = new GimbalCenterAxisMessage(); y = MathHelper.Clip(0, 1080, y);
message.X = x; ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX = x;
message.Y = y; ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY = y;
ApplicationDomainEx.MessageManager.Send(message);
} }
} }
} }
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.GimbalAI.Domain
{
/// <summary>
/// 云台中心轴消息
/// </summary>
public class GimbalCenterAxisMessage
{
/// <summary>
/// 中心轴X坐标
/// </summary>
public double X { get; set; }
/// <summary>
/// 中心轴Y坐标
/// </summary>
public double Y { get; set; }
}
}
...@@ -13,13 +13,38 @@ namespace VIZ.GimbalAI.Domain ...@@ -13,13 +13,38 @@ namespace VIZ.GimbalAI.Domain
public class GimbalControlModel : ModelBase public class GimbalControlModel : ModelBase
{ {
/// <summary> /// <summary>
/// 目标中心轴X坐标
/// </summary>
public double TargetCenterAxisX { get; set; } = 1920 / 2;
/// <summary>
/// 中心轴X坐标 /// 中心轴X坐标
/// </summary> /// </summary>
public double CenterAxisX { get; set; } = 1920 / 2; public double CenterAxisX { get; set; } = 1920 / 2;
/// <summary> /// <summary>
/// 目标中心轴Y坐标
/// </summary>
public double TargetCenterAxisY { get; set; } = 1080 / 2;
/// <summary>
/// 中心轴Y坐标 /// 中心轴Y坐标
/// </summary> /// </summary>
public double CenterAxisY { get; set; } = 1080 / 2; public double CenterAxisY { get; set; } = 1080 / 2;
/// <summary>
/// 更新中心轴
/// </summary>
/// <returns>中心轴是否有变化</returns>
public bool UpdateCenterAxis()
{
if (this.CenterAxisX == this.TargetCenterAxisX && this.CenterAxisY == this.TargetCenterAxisY)
return false;
this.CenterAxisX = this.TargetCenterAxisX;
this.CenterAxisY = this.TargetCenterAxisY;
return true;
}
} }
} }
...@@ -85,7 +85,6 @@ ...@@ -85,7 +85,6 @@
<ItemGroup> <ItemGroup>
<Compile Include="Enum\NDIViewKeys.cs" /> <Compile Include="Enum\NDIViewKeys.cs" />
<Compile Include="Enum\ServiceKeys.cs" /> <Compile Include="Enum\ServiceKeys.cs" />
<Compile Include="Message\Gimbal\GimbalCenterAxisMessage.cs" />
<Compile Include="Message\Gimbal\GimbalInitCompleteMessage.cs" /> <Compile Include="Message\Gimbal\GimbalInitCompleteMessage.cs" />
<Compile Include="Model\Gimbal\GimbalControlModel.cs" /> <Compile Include="Model\Gimbal\GimbalControlModel.cs" />
<Compile Include="Model\NDI\NdiStreamGroupModel.cs" /> <Compile Include="Model\NDI\NdiStreamGroupModel.cs" />
......
...@@ -25,7 +25,6 @@ ...@@ -25,7 +25,6 @@
<Grid> <Grid>
<Grid.RowDefinitions> <Grid.RowDefinitions>
<RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="300"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<Grid IsEnabled="{Binding Path=IsEnabled,Mode=OneWay}"> <Grid IsEnabled="{Binding Path=IsEnabled,Mode=OneWay}">
<Grid.RowDefinitions> <Grid.RowDefinitions>
...@@ -115,8 +114,8 @@ ...@@ -115,8 +114,8 @@
</Grid> </Grid>
<!-- 控制台输出 --> <!-- 控制台输出 -->
<Border Grid.Row="1"> <!--<Border Grid.Row="1">
<local:ConsoleView></local:ConsoleView> <local:ConsoleView></local:ConsoleView>
</Border> </Border>-->
</Grid> </Grid>
</UserControl> </UserControl>
...@@ -48,8 +48,8 @@ namespace VIZ.GimbalAI.Module ...@@ -48,8 +48,8 @@ namespace VIZ.GimbalAI.Module
/// <param name="e">事件参数</param> /// <param name="e">事件参数</param>
public void MoveCenterAxis(KeyEventArgs e) public void MoveCenterAxis(KeyEventArgs e)
{ {
double x = ApplicationDomainEx.GimbalControlModel.CenterAxisX; double x = ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX;
double y = ApplicationDomainEx.GimbalControlModel.CenterAxisY; double y = ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY;
if (e.KeyCode == Keys.Left) if (e.KeyCode == Keys.Left)
{ {
...@@ -70,18 +70,8 @@ namespace VIZ.GimbalAI.Module ...@@ -70,18 +70,8 @@ namespace VIZ.GimbalAI.Module
x = MathHelper.Clip(0, 1920, x); x = MathHelper.Clip(0, 1920, x);
y = MathHelper.Clip(0, 1080, y); y = MathHelper.Clip(0, 1080, y);
ApplicationDomainEx.GimbalControlModel.CenterAxisX = x; ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX = x;
ApplicationDomainEx.GimbalControlModel.CenterAxisY = y; ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY = y;
// 向算法发送最新的中心轴位置
UdpEndpointManager manager = ConnectionManager.UdpConnection.GetEndpointManager(UdpEndpointKeys.algorithm);
AlgorithmSender.CenterAxis(manager);
// 向界面发送更新轴信息消息
GimbalCenterAxisMessage message = new GimbalCenterAxisMessage();
message.X = x;
message.Y = y;
ApplicationDomainEx.MessageManager.Send(message);
} }
} }
} }
...@@ -44,9 +44,9 @@ ...@@ -44,9 +44,9 @@
<TextBlock Text="调试信息 --" FontSize="20" Foreground="Red" Margin="0,0,10,0"></TextBlock> <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="算法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="{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> <Button Width="120" Height="30" Margin="10,0,10,0" Content="重启算法"
<TextBlock Text="{Binding Path=GimbalFPS.FPS,Mode=OneWay}" FontSize="20" Foreground="Red" Margin="0,0,10,0"></TextBlock> IsEnabled="{Binding Path=IsRestartAlgorithmEnabled,Mode=OneWay}"
<Button Width="120" Height="30" Margin="10,0,10,0" Content="重启算法" Command="{Binding Path=RestartAlgorithmCommand}"></Button> Command="{Binding Path=RestartAlgorithmCommand,Mode=OneWay}"></Button>
</StackPanel> </StackPanel>
</common:DebugBorder> </common:DebugBorder>
</StackPanel> </StackPanel>
......
...@@ -52,7 +52,6 @@ namespace VIZ.GimbalAI.Module ...@@ -52,7 +52,6 @@ namespace VIZ.GimbalAI.Module
private void InitFPS() private void InitFPS()
{ {
this.AlgorithmFPS.Start(); this.AlgorithmFPS.Start();
this.GimbalFPS.Start();
} }
/// <summary> /// <summary>
...@@ -74,7 +73,7 @@ namespace VIZ.GimbalAI.Module ...@@ -74,7 +73,7 @@ namespace VIZ.GimbalAI.Module
private void InitMessage() private void InitMessage()
{ {
ApplicationDomainEx.MessageManager.Register<VideoRenderRectangleMessage>(this, this.VideoRenderRectangle); ApplicationDomainEx.MessageManager.Register<VideoRenderRectangleMessage>(this, this.VideoRenderRectangle);
ApplicationDomainEx.MessageManager.Register<GimbalCenterAxisMessage>(this, this.GimbalCenterAxis); ApplicationDomainEx.MessageManager.Register<AlgorithmInitCompleteMessage>(this, this.AlgorithmInitComplete);
} }
/// <summary> /// <summary>
...@@ -151,30 +150,30 @@ namespace VIZ.GimbalAI.Module ...@@ -151,30 +150,30 @@ namespace VIZ.GimbalAI.Module
#endregion #endregion
#region AlgorithmFPS -- 算法FPS模型 #region IsRestartAlgorithmEnabled -- 重启算法按钮是否可用
private FPSHelper algorithmFPS = new FPSHelper(); private bool isRestartAlgorithmEnabled;
/// <summary> /// <summary>
/// 算法FPS模型 /// 重启算法按钮是否可用
/// </summary> /// </summary>
public FPSHelper AlgorithmFPS public bool IsRestartAlgorithmEnabled
{ {
get { return algorithmFPS; } get { return isRestartAlgorithmEnabled; }
set { algorithmFPS = value; this.RaisePropertyChanged(nameof(AlgorithmFPS)); } set { isRestartAlgorithmEnabled = value; this.RaisePropertySaveChanged(nameof(IsRestartAlgorithmEnabled)); }
} }
#endregion #endregion
#region GimbalFPS -- 云台FPS模型 #region AlgorithmFPS -- 算法FPS模型
private FPSHelper gimbalFPS = new FPSHelper(); private FPSHelper algorithmFPS = new FPSHelper();
/// <summary> /// <summary>
/// 云台FPS模型 /// 算法FPS模型
/// </summary> /// </summary>
public FPSHelper GimbalFPS public FPSHelper AlgorithmFPS
{ {
get { return gimbalFPS; } get { return algorithmFPS; }
set { gimbalFPS = value; this.RaisePropertyChanged(nameof(GimbalFPS)); } set { algorithmFPS = value; this.RaisePropertyChanged(nameof(AlgorithmFPS)); }
} }
#endregion #endregion
...@@ -321,6 +320,7 @@ namespace VIZ.GimbalAI.Module ...@@ -321,6 +320,7 @@ namespace VIZ.GimbalAI.Module
/// </summary> /// </summary>
private void RestartAlgorithm() private void RestartAlgorithm()
{ {
this.IsRestartAlgorithmEnabled = false;
this.AlgorithmController.Restart(); this.AlgorithmController.Restart();
} }
...@@ -371,20 +371,18 @@ namespace VIZ.GimbalAI.Module ...@@ -371,20 +371,18 @@ namespace VIZ.GimbalAI.Module
#endregion #endregion
#region GimbalCenterAxisMessage -- 云台中心轴改变消息 #region AlgorithmInitCompleteMessage -- 算法初始化完成消息
/// <summary> /// <summary>
/// 云台中心轴改变消息 /// 算法初始化完成
/// </summary> /// </summary>
/// <param name="msg">消息</param> /// <param name="msg">消息</param>
private void GimbalCenterAxis(GimbalCenterAxisMessage msg) public void AlgorithmInitComplete(AlgorithmInitCompleteMessage msg)
{ {
// 统计FPS this.IsRestartAlgorithmEnabled = true;
this.GimbalFPS.CalcFps();
} }
#endregion #endregion
// ====================================================================================== // ======================================================================================
// === Private Function === // === Private Function ===
// ====================================================================================== // ======================================================================================
......
...@@ -33,8 +33,8 @@ namespace VIZ.GimbalAI.Module ...@@ -33,8 +33,8 @@ namespace VIZ.GimbalAI.Module
/// <returns>是否成功执行</returns> /// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context) public override bool Setup(AppSetupContext context)
{ {
ApplicationDomainEx.GimbalControlModel.CenterAxisX = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, int>(p => p.GIMBAL_CENTER_AXIS_X); ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX = 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.GimbalControlModel.TargetCenterAxisY = ApplicationDomainEx.IniStorage.GetValue<GimbalConfig, int>(p => p.GIMBAL_CENTER_AXIS_Y);
ApplicationDomainEx.LoopManager.Register("AppSetup_InitCenterAxis.Setup", 30, () => ApplicationDomainEx.LoopManager.Register("AppSetup_InitCenterAxis.Setup", 30, () =>
{ {
...@@ -60,8 +60,8 @@ namespace VIZ.GimbalAI.Module ...@@ -60,8 +60,8 @@ namespace VIZ.GimbalAI.Module
{ {
try try
{ {
ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_X, ApplicationDomainEx.GimbalControlModel.CenterAxisX); 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.CenterAxisY); ApplicationDomainEx.IniStorage.SetValue<GimbalConfig>(p => p.GIMBAL_CENTER_AXIS_Y, ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY);
} }
catch (Exception ex) catch (Exception ex)
{ {
......
...@@ -18,6 +18,7 @@ using OpenCvSharp.WpfExtensions; ...@@ -18,6 +18,7 @@ using OpenCvSharp.WpfExtensions;
using OpenCvSharp.Extensions; using OpenCvSharp.Extensions;
using SharpDX.Mathematics.Interop; using SharpDX.Mathematics.Interop;
using VIZ.Framework.Storage; using VIZ.Framework.Storage;
using System.Windows.Interop;
namespace VIZ.GimbalAI.Module namespace VIZ.GimbalAI.Module
{ {
...@@ -84,7 +85,7 @@ namespace VIZ.GimbalAI.Module ...@@ -84,7 +85,7 @@ namespace VIZ.GimbalAI.Module
CenterAxisInfo centerAxisInfo = new CenterAxisInfo(); CenterAxisInfo centerAxisInfo = new CenterAxisInfo();
centerAxisInfo.AxisWidth = this.VIDEO_CENTER_AXIS_WIDTH; centerAxisInfo.AxisWidth = this.VIDEO_CENTER_AXIS_WIDTH;
centerAxisInfo.AxisColor = this.VIDEO_CENTER_AXIS_COLOR; centerAxisInfo.AxisColor = this.VIDEO_CENTER_AXIS_COLOR;
centerAxisInfo.SrcCenter = new RawVector2((float)ApplicationDomainEx.GimbalControlModel.CenterAxisX, (float)ApplicationDomainEx.GimbalControlModel.CenterAxisY); centerAxisInfo.SrcCenter = new RawVector2((float)ApplicationDomainEx.GimbalControlModel.TargetCenterAxisX, (float)ApplicationDomainEx.GimbalControlModel.TargetCenterAxisY);
this.centerAxisPlugin.Update(centerAxisInfo); this.centerAxisPlugin.Update(centerAxisInfo);
} }
...@@ -102,7 +103,6 @@ namespace VIZ.GimbalAI.Module ...@@ -102,7 +103,6 @@ namespace VIZ.GimbalAI.Module
private void InitMessage() private void InitMessage()
{ {
ApplicationDomainEx.MessageManager.Register<VideoRenderRectangleMessage>(this, this.VideoRenderRectangle); ApplicationDomainEx.MessageManager.Register<VideoRenderRectangleMessage>(this, this.VideoRenderRectangle);
ApplicationDomainEx.MessageManager.Register<GimbalCenterAxisMessage>(this, this.GimbalCenterAxis);
} }
/// <summary> /// <summary>
...@@ -342,28 +342,6 @@ namespace VIZ.GimbalAI.Module ...@@ -342,28 +342,6 @@ namespace VIZ.GimbalAI.Module
#endregion #endregion
#region GimbalCenterAxisMessage -- 中心轴更新消息
/// <summary>
/// 中心轴更新消息
/// </summary>
/// <param name="msg">消息</param>
private void GimbalCenterAxis(GimbalCenterAxisMessage msg)
{
VideoView view = this.GetView<VideoView>();
if (view == null)
return;
CenterAxisInfo info = new CenterAxisInfo();
info.SrcCenter = new RawVector2((float)msg.X, (float)msg.Y);
info.AxisWidth = this.VIDEO_CENTER_AXIS_WIDTH;
info.AxisColor = this.VIDEO_CENTER_AXIS_COLOR;
view.videoControl.UpdateCenterAxis(info);
}
#endregion
// ====================================================================================== // ======================================================================================
// === Public Function === // === Public Function ===
// ====================================================================================== // ======================================================================================
...@@ -440,7 +418,33 @@ namespace VIZ.GimbalAI.Module ...@@ -440,7 +418,33 @@ namespace VIZ.GimbalAI.Module
if (view == null) if (view == null)
return; return;
// 更新视频
view.videoControl.UpdateVideoFrame(e.Frame); view.videoControl.UpdateVideoFrame(e.Frame);
// 更新中心轴
this.UpdateCenterAxis(view);
}
/// <summary>
/// 更新中心轴
/// </summary>
/// <param name="view">视图</param>
private void UpdateCenterAxis(VideoView view)
{
if (!ApplicationDomainEx.GimbalControlModel.UpdateCenterAxis())
return;
// 界面更新
CenterAxisInfo info = new CenterAxisInfo();
info.SrcCenter = new RawVector2((float)ApplicationDomainEx.GimbalControlModel.CenterAxisX, (float)ApplicationDomainEx.GimbalControlModel.CenterAxisY);
info.AxisWidth = this.VIDEO_CENTER_AXIS_WIDTH;
info.AxisColor = this.VIDEO_CENTER_AXIS_COLOR;
view.videoControl.UpdateCenterAxis(info);
// 向算法发送最新的中心轴位置
UdpEndpointManager manager = ConnectionManager.UdpConnection.GetEndpointManager(UdpEndpointKeys.algorithm);
AlgorithmSender.CenterAxis(manager);
} }
/// <summary> /// <summary>
......
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