Commit 06f6305b by liulongfei

1. 添加视频中心轴插件

parent 8d12af08
...@@ -186,6 +186,9 @@ ...@@ -186,6 +186,9 @@
<Compile Include="SharpDx\WIC\WicBitmapHelper.cs" /> <Compile Include="SharpDx\WIC\WicBitmapHelper.cs" />
<Compile Include="SharpDx\WPF\D2dControl.cs" /> <Compile Include="SharpDx\WPF\D2dControl.cs" />
<Compile Include="SharpDx\WPF\Dx11ImageSource.cs" /> <Compile Include="SharpDx\WPF\Dx11ImageSource.cs" />
<Compile Include="VideoControl\Control\Plugin\CenterAxis\CenterAxisPlugin.cs" />
<Compile Include="VideoControl\Control\Plugin\CenterAxis\CenterAxisPluginExpand.cs" />
<Compile Include="VideoControl\Control\Plugin\CenterAxis\Info\CenterAxisInfo.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\EventArgs\ManualCorrectionClickEventArgs.cs" /> <Compile Include="VideoControl\Control\Plugin\ManualCorrection\EventArgs\ManualCorrectionClickEventArgs.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionExpand.cs" /> <Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionExpand.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\Info\ManualCorrectionInfo.cs" /> <Compile Include="VideoControl\Control\Plugin\ManualCorrection\Info\ManualCorrectionInfo.cs" />
......
using log4net;
using SharpDX.Direct2D1;
using SharpDX.Mathematics.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
namespace VIZ.Framework.Common
{
/// <summary>
/// 中心轴插件
/// </summary>
public class CenterAxisPlugin : VideoPluginBase
{
/// <summary>
/// 日志
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(CenterAxisPlugin));
/// <summary>
/// 中心轴插件
/// </summary>
/// <param name="videoControl">视频控件</param>
public CenterAxisPlugin(VideoControl videoControl) : base(videoControl)
{
}
/// <summary>
/// 名称
/// </summary>
public override string Name => VideoControlPluginNames.CenterAxis;
/// <summary>
/// 中心轴信息
/// </summary>
private volatile CenterAxisInfo centerAxisInfo;
/// <summary>
/// 更新数据
/// </summary>
/// <param name="centerAxisInfo">中心轴信息</param>
public void Update(CenterAxisInfo centerAxisInfo)
{
this.centerAxisInfo = centerAxisInfo;
}
/// <summary>
/// 渲染
/// </summary>
/// <param name="context">渲染上下文</param>
public override void Render(VideoRenderContext context)
{
CenterAxisInfo info = this.centerAxisInfo;
if (info == null)
return;
// 绘制轴心
RawVector2 drawCenter = ImageHelper.ConvertImagePointToUiPoint(context.VideoRenderInfo.Frame.Width, context.VideoRenderInfo.Frame.Height, context.VideoRenderInfo.DrawingRect, info.SrcCenter);
SolidColorBrush brush = new SolidColorBrush(context.Target, info.AxisColor);
// X轴
RawVector2 x1 = new RawVector2((float)context.VideoRenderInfo.DrawingRect.Left, drawCenter.Y);
RawVector2 x2 = new RawVector2((float)context.VideoRenderInfo.DrawingRect.Right, drawCenter.Y);
context.Target.DrawLine(x1, x2, brush);
// Y轴
RawVector2 y1 = new RawVector2(drawCenter.X, (float)context.VideoRenderInfo.DrawingRect.Top);
RawVector2 y2 = new RawVector2(drawCenter.X, (float)context.VideoRenderInfo.DrawingRect.Bottom);
context.Target.DrawLine(y1, y2, brush);
}
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Common
{
/// <summary>
/// 中心轴插件扩展
/// </summary>
public static class CenterAxisPluginExpand
{
/// <summary>
/// 更新中心轴
/// </summary>
/// <param name="videoControl">视频控件</param>
/// <param name="centerAxisInfo">中心轴信息</param>
public static void UpdateCenterAxis(this VideoControl videoControl, CenterAxisInfo centerAxisInfo)
{
if (videoControl.videoRender == null)
return;
CenterAxisPlugin plugin = videoControl.GetPlugin<CenterAxisPlugin>(VideoControlPluginNames.CenterAxis);
if (plugin == null)
return;
plugin.Update(centerAxisInfo);
}
/// <summary>
/// 清理中心轴
/// </summary>
/// <param name="videoControl">视频控件</param>
public static void ClearCenterAxis(this VideoControl videoControl)
{
if (videoControl.videoRender == null)
return;
CenterAxisPlugin plugin = videoControl.GetPlugin<CenterAxisPlugin>(VideoControlPluginNames.CenterAxis);
if (plugin == null)
return;
plugin.Update(null);
}
}
}
using SharpDX.Mathematics.Interop;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Common
{
/// <summary>
/// 中心轴信息
/// </summary>
public class CenterAxisInfo
{
/// <summary>
/// 源中心
/// </summary>
public RawVector2 SrcCenter { get; set; }
/// <summary>
/// 轴宽度
/// </summary>
public double AxisWidth { get; set; }
/// <summary>
/// 轴颜色
/// </summary>
public RawColor4 AxisColor { get; set; }
}
}
using SharpDX.Direct2D1; using SharpDX.Direct2D1;
using SharpDX.DirectWrite;
using SharpDX.Mathematics.Interop;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
...@@ -7,6 +9,7 @@ using System.Text; ...@@ -7,6 +9,7 @@ using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using System.Windows; using System.Windows;
using VIZ.Framework.Core; using VIZ.Framework.Core;
using VIZ.Framework.Domain;
namespace VIZ.Framework.Common namespace VIZ.Framework.Common
{ {
...@@ -40,6 +43,11 @@ namespace VIZ.Framework.Common ...@@ -40,6 +43,11 @@ namespace VIZ.Framework.Common
private volatile List<TrackingBoxInfo> trackingBoxInfos; private volatile List<TrackingBoxInfo> trackingBoxInfos;
/// <summary> /// <summary>
/// 格式
/// </summary>
private TextFormat textFormat;
/// <summary>
/// 更新数据 /// 更新数据
/// </summary> /// </summary>
/// <param name="trackingBoxInfos">跟踪框信息</param> /// <param name="trackingBoxInfos">跟踪框信息</param>
...@@ -76,6 +84,22 @@ namespace VIZ.Framework.Common ...@@ -76,6 +84,22 @@ namespace VIZ.Framework.Common
// 绘制跟踪框 // 绘制跟踪框
SolidColorBrush brush = new SolidColorBrush(context.Target, info.DrawingBorderColor); SolidColorBrush brush = new SolidColorBrush(context.Target, info.DrawingBorderColor);
context.Target.DrawRectangle(rect, brush, info.DrawingBorderWidth); context.Target.DrawRectangle(rect, brush, info.DrawingBorderWidth);
// 在调试模式下绘制目标框面积占比
if (!ApplicationDomain.IS_DEBUG)
continue;
double all = context.VideoRenderInfo.Frame.Width * context.VideoRenderInfo.Frame.Height;
double use = (info.SrcRect.Right - info.SrcRect.Left) * (info.SrcRect.Bottom - info.SrcRect.Top);
double p = use / all;
if (this.textFormat == null)
{
this.textFormat = new TextFormat(context.DirectWriteFactory, "Microsoft YaHei", 14);
}
TextLayout textLayout = new TextLayout(context.DirectWriteFactory, p.ToString("P2"), this.textFormat, 100, 20);
context.Target.DrawTextLayout(new RawVector2(rect.Left, rect.Top - 20), textLayout, brush);
} }
} }
......
...@@ -35,5 +35,10 @@ namespace VIZ.Framework.Common ...@@ -35,5 +35,10 @@ namespace VIZ.Framework.Common
/// 手动校准 /// 手动校准
/// </summary> /// </summary>
public const string ManualCorrection = "ManualCorrection"; public const string ManualCorrection = "ManualCorrection";
/// <summary>
/// 中心轴
/// </summary>
public const string CenterAxis = "CenterAxis";
} }
} }
...@@ -70,6 +70,11 @@ namespace VIZ.Framework.Common ...@@ -70,6 +70,11 @@ namespace VIZ.Framework.Common
/// </summary> /// </summary>
private object render_lock_object = new object(); private object render_lock_object = new object();
/// <summary>
/// DirectWrite 工厂
/// </summary>
private SharpDX.DirectWrite.Factory directWriteFactory = new SharpDX.DirectWrite.Factory(SharpDX.DirectWrite.FactoryType.Isolated);
// ======================================================================================================== // ========================================================================================================
// === Public Function === // === Public Function ===
// ======================================================================================================== // ========================================================================================================
...@@ -118,6 +123,7 @@ namespace VIZ.Framework.Common ...@@ -118,6 +123,7 @@ namespace VIZ.Framework.Common
VideoRenderContext context = new VideoRenderContext(); VideoRenderContext context = new VideoRenderContext();
context.Target = target; context.Target = target;
context.Mode = VideoRenderMode.UI; context.Mode = VideoRenderMode.UI;
context.DirectWriteFactory = this.directWriteFactory;
this.Render(context); this.Render(context);
} }
...@@ -155,6 +161,9 @@ namespace VIZ.Framework.Common ...@@ -155,6 +161,9 @@ namespace VIZ.Framework.Common
plugin.Render(context); plugin.Render(context);
} }
// 渲染未裁切区域
this.RenderUncutArea(context);
} }
} }
...@@ -180,5 +189,46 @@ namespace VIZ.Framework.Common ...@@ -180,5 +189,46 @@ namespace VIZ.Framework.Common
bmp.Dispose(); bmp.Dispose();
} }
/// <summary>
/// 渲染未裁切区域
/// </summary>
/// <param name="context">渲染上下文</param>
private void RenderUncutArea(VideoRenderContext context)
{
SolidColorBrush brush = new SolidColorBrush(context.Target, this.BackgroundColor);
float c_width = (float)context.VideoRenderInfo.ControlRect.Width;
float c_height = (float)context.VideoRenderInfo.ControlRect.Height;
float d_left = (float)context.VideoRenderInfo.DrawingRect.Left;
float d_top = (float)context.VideoRenderInfo.DrawingRect.Top;
float d_right = (float)context.VideoRenderInfo.DrawingRect.Right;
float d_bottom = (float)context.VideoRenderInfo.DrawingRect.Bottom;
// left
if (d_left > 0)
{
RawRectangleF left = new RawRectangleF(0, 0, d_left, c_height);
context.Target.FillRectangle(left, brush);
}
// right
if (d_right < c_width)
{
RawRectangleF right = new RawRectangleF(d_right, 0, c_width, c_height);
context.Target.FillRectangle(right, brush);
}
// top
if (d_top > 0)
{
RawRectangleF top = new RawRectangleF(d_left, 0, d_right, d_top);
context.Target.FillRectangle(top, brush);
}
// bottom
if (d_bottom < c_height)
{
RawRectangleF bottom = new RawRectangleF(d_left, d_bottom, d_right, c_height);
context.Target.FillRectangle(bottom, brush);
}
}
} }
} }
...@@ -31,5 +31,10 @@ namespace VIZ.Framework.Common ...@@ -31,5 +31,10 @@ namespace VIZ.Framework.Common
/// 需要渲染至图片的插件 /// 需要渲染至图片的插件
/// </summary> /// </summary>
public List<string> RenderImagePlugins { get; set; } public List<string> RenderImagePlugins { get; set; }
/// <summary>
/// DirectWrite 工厂
/// </summary>
public SharpDX.DirectWrite.Factory DirectWriteFactory { get; set; }
} }
} }
...@@ -33,10 +33,11 @@ namespace VIZ.Framework.Core ...@@ -33,10 +33,11 @@ namespace VIZ.Framework.Core
/// 初始化 /// 初始化
/// </summary> /// </summary>
/// <param name="window">关联的额窗口</param> /// <param name="window">关联的额窗口</param>
public static void Init(Window window) /// <returns>是否初始化成功</returns>
public static bool Init(Window window)
{ {
if (window == null) if (window == null)
return; return false;
try try
{ {
...@@ -45,13 +46,20 @@ namespace VIZ.Framework.Core ...@@ -45,13 +46,20 @@ namespace VIZ.Framework.Core
// 初始化3D鼠标 // 初始化3D鼠标
bool init_result = Navigation3DHelper.init_3D_Mouse(windowInteropHelper.Handle); bool init_result = Navigation3DHelper.init_3D_Mouse(windowInteropHelper.Handle);
if (!init_result)
return false;
// 注册窗口消息 // 注册窗口消息
HwndSource source = HwndSource.FromHwnd(windowInteropHelper.Handle); HwndSource source = HwndSource.FromHwnd(windowInteropHelper.Handle);
source.AddHook(Hook); source.AddHook(Hook);
return true;
} }
catch (Exception ex) catch (Exception ex)
{ {
log.Error(ex); log.Error(ex);
return false;
} }
} }
......
...@@ -34,9 +34,7 @@ namespace VIZ.Framework.Module ...@@ -34,9 +34,7 @@ namespace VIZ.Framework.Module
/// <returns>是否成功执行</returns> /// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context) public override bool Setup(AppSetupContext context)
{ {
Navigation3DManager.Init(context.Window); return Navigation3DManager.Init(context.Window);
return true;
} }
/// <summary> /// <summary>
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using log4net;
using System.Threading;
using VIZ.Framework.Domain;
using System.Diagnostics;
namespace VIZ.Framework.Module
{
/// <summary>
/// 应用程序启动 -- 计算机资源
/// </summary>
public class AppSetup_ComputerResource : AppSetupBase
{
/// <summary>
/// 日志
/// </summary>
private static ILog log = LogManager.GetLogger(typeof(AppSetup_ComputerResource));
/// <summary>
/// 描述
/// </summary>
public override string Detail { get; } = "应用程序启动 -- 计算机资源";
/// <summary>
/// 执行启动
/// </summary>
/// <param name="context">应用程序启动上下文</param>
/// <returns>是否成功执行</returns>
public override bool Setup(AppSetupContext context)
{
Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.High;
return true;
}
/// <summary>
/// 执行关闭
/// </summary>
/// <param name="context">应用程序启动上下文</param>
public override void Shutdown(AppSetupContext context)
{
}
}
}
...@@ -106,6 +106,7 @@ ...@@ -106,6 +106,7 @@
<Compile Include="Setup\Provider\Setup\AppSetup_DelayInit.cs" /> <Compile Include="Setup\Provider\Setup\AppSetup_DelayInit.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_LogInit.cs" /> <Compile Include="Setup\Provider\Setup\AppSetup_LogInit.cs" />
<Compile Include="Setup\Provider\Load\AppSetup_Monitor.cs" /> <Compile Include="Setup\Provider\Load\AppSetup_Monitor.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_ComputerResource.cs" />
<Compile Include="Setup\Provider\Setup\AppSetup_Single.cs" /> <Compile Include="Setup\Provider\Setup\AppSetup_Single.cs" />
<Compile Include="ThreeDMouse\TCP\Navigation3DCommandProvider.cs" /> <Compile Include="ThreeDMouse\TCP\Navigation3DCommandProvider.cs" />
<Compile Include="ThreeDMouse\TCP\Navigation3DTcpListener.cs" /> <Compile Include="ThreeDMouse\TCP\Navigation3DTcpListener.cs" />
......
...@@ -89,5 +89,17 @@ namespace VIZ.Framework.Storage ...@@ -89,5 +89,17 @@ namespace VIZ.Framework.Storage
/// </summary> /// </summary>
[Ini(Section = "Video", DefaultValue = "0.2", Type = typeof(double))] [Ini(Section = "Video", DefaultValue = "0.2", Type = typeof(double))]
public string VIDEO_MANUAL_CORRECTION_OPACITY { get; set; } public string VIDEO_MANUAL_CORRECTION_OPACITY { get; set; }
/// <summary>
/// 中心轴宽度
/// </summary>
[Ini(Section = "Video", DefaultValue = "2", Type = typeof(int))]
public string VIDEO_CENTER_AXIS_WIDTH { get; set; }
/// <summary>
/// 中心轴颜色
/// </summary>
[Ini(Section = "Video", DefaultValue = "#44000000", Type = typeof(RawColor4))]
public string VIDEO_CENTER_AXIS_COLOR { get; set; }
} }
} }
...@@ -53,9 +53,11 @@ namespace VIZ.Framework.UnitTest ...@@ -53,9 +53,11 @@ namespace VIZ.Framework.UnitTest
// //
// 2022-08-26 16-41-36.2820000 // 2022-08-26 16-41-36.2820000
// 2022-08-26 16:41:36,370 // 2022-08-26 16:41:36,370
DateTime time = new DateTime(16615032962820000 + begin); //DateTime time = new DateTime(16615032962820000 + begin);
string str = time.ToString("yyyy-MM-dd HH-mm-ss.fffffff"); // string str = time.ToString("yyyy-MM-dd HH-mm-ss.fffffff");
string str = 1.123456789d.ToString("P2");
} }
} }
} }
...@@ -5,7 +5,7 @@ ...@@ -5,7 +5,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:VIZ.Framework.WpfTest" xmlns:local="clr-namespace:VIZ.Framework.WpfTest"
xmlns:fcommon="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common" xmlns:fcommon="clr-namespace:VIZ.Framework.Common;assembly=VIZ.Framework.Common"
mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="None" mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowState="Maximized"
Title="MainWindow" Height="800" Width="1200"> Title="MainWindow" Height="800" Width="1200">
<Grid> <Grid>
<local:OpenCVVideoTest></local:OpenCVVideoTest> <local:OpenCVVideoTest></local:OpenCVVideoTest>
......
...@@ -11,11 +11,12 @@ ...@@ -11,11 +11,12 @@
<RowDefinition Height="*"></RowDefinition> <RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="60"></RowDefinition> <RowDefinition Height="60"></RowDefinition>
</Grid.RowDefinitions> </Grid.RowDefinitions>
<common:VideoControl x:Name="video" IsShowFPS="True" Height="800" Margin="40,0,40,0"></common:VideoControl> <common:VideoControl x:Name="video" IsShowFPS="True" Height="400" Margin="40,0,40,0"></common:VideoControl>
<StackPanel Orientation="Horizontal" Grid.Row="1"> <StackPanel Orientation="Horizontal" Grid.Row="1">
<Button Margin="10,0,10,0" Width="120" Height="40" Content="图片测试" Click="Button_Click"></Button> <Button Margin="10,0,10,0" Width="120" Height="40" Content="图片测试" Click="Button_Click"></Button>
<Button Margin="10,0,10,0" Width="120" Height="40" Content="清理裁剪框" Click="Button_Click2"></Button> <Button Margin="10,0,10,0" Width="120" Height="40" Content="清理裁剪框" Click="Button_Click2"></Button>
<Button Margin="10,0,10,0" Width="120" Height="40" Content="手动校准测试" Click="Button_Click3"></Button> <Button Margin="10,0,10,0" Width="120" Height="40" Content="手动校准测试" Click="Button_Click3"></Button>
<Button Margin="10,0,10,0" Width="120" Height="40" Content="中心轴测试" Click="Button_Click4"></Button>
</StackPanel> </StackPanel>
</Grid> </Grid>
</UserControl> </UserControl>
...@@ -45,11 +45,14 @@ namespace VIZ.Framework.WpfTest ...@@ -45,11 +45,14 @@ namespace VIZ.Framework.WpfTest
ManualCorrectionPlugin manualCorrectionPlugin = new ManualCorrectionPlugin(this.video); ManualCorrectionPlugin manualCorrectionPlugin = new ManualCorrectionPlugin(this.video);
manualCorrectionPlugin.Click += ManualCorrectionPlugin_Click; manualCorrectionPlugin.Click += ManualCorrectionPlugin_Click;
CenterAxisPlugin centerAxisPlugin = new CenterAxisPlugin(this.video);
this.video.AttachPlugin(trackingBoxPlugin); this.video.AttachPlugin(trackingBoxPlugin);
this.video.AttachPlugin(selectionBoxPlugin); this.video.AttachPlugin(selectionBoxPlugin);
this.video.AttachPlugin(clipBoxPlugin); this.video.AttachPlugin(clipBoxPlugin);
this.video.AttachPlugin(sideCheckPolygonPlugin); this.video.AttachPlugin(sideCheckPolygonPlugin);
this.video.AttachPlugin(manualCorrectionPlugin); this.video.AttachPlugin(manualCorrectionPlugin);
this.video.AttachPlugin(centerAxisPlugin);
// 接入OpenCV插件 // 接入OpenCV插件
OpenCVStreamOption option = new OpenCVStreamOption(); OpenCVStreamOption option = new OpenCVStreamOption();
...@@ -107,7 +110,7 @@ namespace VIZ.Framework.WpfTest ...@@ -107,7 +110,7 @@ namespace VIZ.Framework.WpfTest
{ {
ManualCorrectionInfo info = new ManualCorrectionInfo(); ManualCorrectionInfo info = new ManualCorrectionInfo();
info.FillColor = SharpDxColorHelper.FromString("#2200FF00"); info.FillColor = SharpDxColorHelper.FromString("#2200FF00");
info.SrcRadius = 200; info.SrcRadius = 2000;
info.SrcCenter = new SharpDX.Mathematics.Interop.RawVector2(100, 100); info.SrcCenter = new SharpDX.Mathematics.Interop.RawVector2(100, 100);
this.video.UpdateManualCorrection(info); this.video.UpdateManualCorrection(info);
...@@ -164,5 +167,18 @@ namespace VIZ.Framework.WpfTest ...@@ -164,5 +167,18 @@ namespace VIZ.Framework.WpfTest
{ {
} }
/// <summary>
/// 中心轴测试
/// </summary>
private void Button_Click4(object sender, RoutedEventArgs e)
{
CenterAxisInfo info = new CenterAxisInfo();
info.AxisWidth = 2;
info.AxisColor = SharpDxColorHelper.FromString("#44000000");
info.SrcCenter = new SharpDX.Mathematics.Interop.RawVector2(100, 100);
this.video.UpdateCenterAxis(info);
}
} }
} }
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