Commit 4e8c9950 by liulongfei

添加边线检测插件

parent d0e6394a
...@@ -9,16 +9,13 @@ ...@@ -9,16 +9,13 @@
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="Button"> <ControlTemplate TargetType="Button">
<Border x:Name="bd" BorderBrush="Transparent" BorderThickness="1" Background="Transparent"> <Border x:Name="bd" BorderBrush="Transparent" BorderThickness="1" Background="Transparent">
<Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="20" Height="20" RenderTransformOrigin="0.5,0.5"> <Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="18" Height="18" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform> <Rectangle x:Name="rect1" Width="18" Height="2" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<RotateTransform Angle="0"/>
</Grid.RenderTransform>
<Rectangle Width="20" Height="2" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform> <Rectangle.RenderTransform>
<RotateTransform Angle="45"/> <RotateTransform Angle="45"/>
</Rectangle.RenderTransform> </Rectangle.RenderTransform>
</Rectangle> </Rectangle>
<Rectangle Width="20" Height="2" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5"> <Rectangle x:Name="rect2" Width="18" Height="2" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5">
<Rectangle.RenderTransform> <Rectangle.RenderTransform>
<RotateTransform Angle="-45"/> <RotateTransform Angle="-45"/>
</Rectangle.RenderTransform> </Rectangle.RenderTransform>
...@@ -28,23 +25,9 @@ ...@@ -28,23 +25,9 @@
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="bd" Property="Background" Value="#22ffffff"></Setter> <Setter TargetName="bd" Property="Background" Value="#22ffffff"></Setter>
<Setter TargetName="rect1" Property="Fill" Value="#ffff0000"></Setter>
<Setter TargetName="rect2" Property="Fill" Value="#ffff0000"></Setter>
</Trigger> </Trigger>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
Duration="00:00:00.3" To="180"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
Duration="00:00:00.3" To="0"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
...@@ -59,33 +42,14 @@ ...@@ -59,33 +42,14 @@
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="Button"> <ControlTemplate TargetType="Button">
<Border x:Name="bd" BorderBrush="Transparent" BorderThickness="1" Background="Transparent"> <Border x:Name="bd" BorderBrush="Transparent" BorderThickness="1" Background="Transparent">
<Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="20" Height="20" RenderTransformOrigin="0.5,0.5"> <Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="18" Height="18" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform> <Rectangle Width="18" Height="2" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5"></Rectangle>
<RotateTransform Angle="0"/>
</Grid.RenderTransform>
<Rectangle Width="20" Height="2" Fill="White" HorizontalAlignment="Center" VerticalAlignment="Center" RenderTransformOrigin="0.5,0.5"></Rectangle>
</Grid> </Grid>
</Border> </Border>
<ControlTemplate.Triggers> <ControlTemplate.Triggers>
<Trigger Property="IsMouseOver" Value="True"> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="bd" Property="Background" Value="#22ffffff"></Setter> <Setter TargetName="bd" Property="Background" Value="#22ffffff"></Setter>
</Trigger> </Trigger>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
Duration="00:00:00.3" To="180"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
Duration="00:00:00.3" To="0"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
...@@ -100,11 +64,8 @@ ...@@ -100,11 +64,8 @@
<Setter.Value> <Setter.Value>
<ControlTemplate TargetType="Button"> <ControlTemplate TargetType="Button">
<Border x:Name="bd" BorderBrush="Transparent" BorderThickness="1" Background="Transparent"> <Border x:Name="bd" BorderBrush="Transparent" BorderThickness="1" Background="Transparent">
<Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="20" Height="20" RenderTransformOrigin="0.5,0.5"> <Grid x:Name="grid" HorizontalAlignment="Center" VerticalAlignment="Center" Width="18" Height="18" RenderTransformOrigin="0.5,0.5">
<Grid.RenderTransform> <Image Width="18" Height="18" HorizontalAlignment="Center" VerticalAlignment="Center"
<RotateTransform Angle="0"/>
</Grid.RenderTransform>
<Image Width="20" Height="20" HorizontalAlignment="Center" VerticalAlignment="Center"
Source="/VIZ.Framework.Common.Resource;component/Icons/setting_32x32.png"></Image> Source="/VIZ.Framework.Common.Resource;component/Icons/setting_32x32.png"></Image>
</Grid> </Grid>
</Border> </Border>
...@@ -112,22 +73,6 @@ ...@@ -112,22 +73,6 @@
<Trigger Property="IsMouseOver" Value="True"> <Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="bd" Property="Background" Value="#22ffffff"></Setter> <Setter TargetName="bd" Property="Background" Value="#22ffffff"></Setter>
</Trigger> </Trigger>
<EventTrigger RoutedEvent="MouseEnter">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
Duration="00:00:00.3" To="180"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
<EventTrigger RoutedEvent="MouseLeave">
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="grid" Storyboard.TargetProperty="(UIElement.RenderTransform).(RotateTransform.Angle)"
Duration="00:00:00.3" To="0"></DoubleAnimation>
</Storyboard>
</BeginStoryboard>
</EventTrigger>
</ControlTemplate.Triggers> </ControlTemplate.Triggers>
</ControlTemplate> </ControlTemplate>
</Setter.Value> </Setter.Value>
......
...@@ -194,6 +194,10 @@ ...@@ -194,6 +194,10 @@
<Compile Include="VideoControl\Control\Plugin\SelectionBox\Info\SelectionBoxInfo.cs" /> <Compile Include="VideoControl\Control\Plugin\SelectionBox\Info\SelectionBoxInfo.cs" />
<Compile Include="VideoControl\Control\Plugin\SelectionBox\SelectionBoxExpand.cs" /> <Compile Include="VideoControl\Control\Plugin\SelectionBox\SelectionBoxExpand.cs" />
<Compile Include="VideoControl\Control\Plugin\SelectionBox\SelectionBoxPlugin.cs" /> <Compile Include="VideoControl\Control\Plugin\SelectionBox\SelectionBoxPlugin.cs" />
<Compile Include="VideoControl\Control\Plugin\SideCheckPolygon\EventArgs\SideCheckPolygonClickEventArgs.cs" />
<Compile Include="VideoControl\Control\Plugin\SideCheckPolygon\Info\SideCheckPolygonInfo.cs" />
<Compile Include="VideoControl\Control\Plugin\SideCheckPolygon\SideCheckPolygonExpand.cs" />
<Compile Include="VideoControl\Control\Plugin\SideCheckPolygon\SideCheckPolygonPlugin.cs" />
<Compile Include="VideoControl\Control\Plugin\TrackingBox\EventArgs\TrackingBoxClickEventArgs.cs" /> <Compile Include="VideoControl\Control\Plugin\TrackingBox\EventArgs\TrackingBoxClickEventArgs.cs" />
<Compile Include="VideoControl\Control\Plugin\TrackingBox\TrackingBoxExpand.cs" /> <Compile Include="VideoControl\Control\Plugin\TrackingBox\TrackingBoxExpand.cs" />
<Compile Include="VideoControl\Control\Plugin\TrackingBox\Info\TrackingBoxInfo.cs" /> <Compile Include="VideoControl\Control\Plugin\TrackingBox\Info\TrackingBoxInfo.cs" />
...@@ -240,6 +244,7 @@ ...@@ -240,6 +244,7 @@
<Compile Include="Widgets\HotkeyBox\HotkeyBox.cs" /> <Compile Include="Widgets\HotkeyBox\HotkeyBox.cs" />
<Compile Include="Widgets\HotkeyBox\HotkeyHelper.cs" /> <Compile Include="Widgets\HotkeyBox\HotkeyHelper.cs" />
<Compile Include="Widgets\HotkeyBox\HotkeyPropertyAttribute.cs" /> <Compile Include="Widgets\HotkeyBox\HotkeyPropertyAttribute.cs" />
<Compile Include="Widgets\LabelValue\LabelValue2.cs" />
<Compile Include="Widgets\LabelValue\LabelValue.cs" /> <Compile Include="Widgets\LabelValue\LabelValue.cs" />
<Compile Include="Widgets\NavigationControl\NavigationConfig.cs" /> <Compile Include="Widgets\NavigationControl\NavigationConfig.cs" />
<Compile Include="Widgets\NavigationControl\NavigationControl.cs" /> <Compile Include="Widgets\NavigationControl\NavigationControl.cs" />
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
namespace VIZ.Framework.Common
{
/// <summary>
/// 边线检测点击事件参数
/// </summary>
public class SideCheckPolygonClickEventArgs : EventArgs
{
/// <summary>
/// 鼠标点击位置
/// </summary>
public Point MousePoint { get; set; }
/// <summary>
/// 源坐标位置
/// </summary>
public Point SrcPoint { get; set; }
}
}
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 SideCheckPolygonInfo
{
/// <summary>
/// 编号
/// </summary>
public string ID { get; set; }
/// <summary>
/// 源点集合
/// </summary>
public List<RawVector2> SrcPoints { get; set; }
/// <summary>
/// 填充颜色
/// </summary>
public RawColor4 FillColor { get; set; }
}
}
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 SideCheckPolygonExpand
{
/// <summary>
/// 更新边线检测多边形
/// </summary>
/// <param name="videoControl">视频控件</param>
/// <param name="sideCheckPolygonInfos">边线检测多边形信息</param>
public static void UpdateSideCheckPolygon(this VideoControl videoControl, List<SideCheckPolygonInfo> sideCheckPolygonInfos)
{
if (videoControl.videoRender == null)
return;
SideCheckPolygonPlugin plugin = videoControl.GetPlugin<SideCheckPolygonPlugin>(VideoControlPluginNames.SideCheckPolygon);
if (plugin == null)
return;
plugin.Update(sideCheckPolygonInfos);
}
/// <summary>
/// 清理边线检测多边形
/// </summary>
/// <param name="videoControl">视频控件</param>
public static void ClearSideCheckPolygon(this VideoControl videoControl)
{
if (videoControl.videoRender == null)
return;
SideCheckPolygonPlugin plugin = videoControl.GetPlugin<SideCheckPolygonPlugin>(VideoControlPluginNames.SideCheckPolygon);
if (plugin == null)
return;
plugin.Update(null);
}
}
}
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 SideCheckPolygonPlugin : VideoPluginBase
{
/// <summary>
/// 框选框插件
/// </summary>
/// <param name="videoControl">视频控件</param>
public SideCheckPolygonPlugin(VideoControl videoControl) : base(videoControl)
{
}
/// <summary>
/// 名称
/// </summary>
public override string Name => VideoControlPluginNames.SideCheckPolygon;
/// <summary>
/// 鼠标点击时触发
/// </summary>
public event EventHandler<SideCheckPolygonClickEventArgs> Click;
/// <summary>
/// 边线检测框信息
/// </summary>
private volatile List<SideCheckPolygonInfo> sideCheckPolygonInfos;
/// <summary>
/// 更新数据
/// </summary>
/// <param name="sideCheckPolygonInfos">边线检测框信息</param>
public void Update(List<SideCheckPolygonInfo> sideCheckPolygonInfos)
{
this.sideCheckPolygonInfos = sideCheckPolygonInfos;
}
/// <summary>
/// 渲染
/// </summary>
/// <param name="context">渲染上下文</param>
public override void Render(VideoRenderContext context)
{
List<SideCheckPolygonInfo> sideCheckPolygonInfos = this.sideCheckPolygonInfos;
if (sideCheckPolygonInfos == null || sideCheckPolygonInfos.Count == 0)
return;
foreach (SideCheckPolygonInfo info in sideCheckPolygonInfos)
{
if (info.SrcPoints == null || info.SrcPoints.Count <= 1)
continue;
SolidColorBrush brush = new SolidColorBrush(context.Target, info.FillColor);
PathGeometry geometry = new PathGeometry(context.Target.Factory);
GeometrySink sink = geometry.Open();
if (context.Mode == VideoRenderMode.UI)
{
RawVector2 first_point = ImageHelper.ConvertImagePointToUiPoint(context.VideoRenderInfo.Frame.Width, context.VideoRenderInfo.Frame.Height, context.VideoRenderInfo.DrawingRect, info.SrcPoints[0]);
sink.BeginFigure(first_point, FigureBegin.Filled);
for (int i = 1; i < info.SrcPoints.Count; ++i)
{
RawVector2 point = ImageHelper.ConvertImagePointToUiPoint(context.VideoRenderInfo.Frame.Width, context.VideoRenderInfo.Frame.Height, context.VideoRenderInfo.DrawingRect, info.SrcPoints[i]);
sink.AddLine(point);
}
sink.EndFigure(FigureEnd.Closed);
}
else
{
sink.BeginFigure(info.SrcPoints[0], FigureBegin.Filled);
for (int i = 1; i < info.SrcPoints.Count - 1; ++i)
{
sink.AddLine(info.SrcPoints[i]);
}
sink.EndFigure(FigureEnd.Closed);
}
sink.Close();
context.Target.FillGeometry(geometry, brush);
}
}
/// <summary>
/// 附加
/// </summary>
public override void Attach()
{
this.VideoRender.PreviewMouseLeftButtonDown -= VideoRender_PreviewMouseLeftButtonDown;
this.VideoRender.PreviewMouseLeftButtonDown += VideoRender_PreviewMouseLeftButtonDown;
}
/// <summary>
/// 卸载
/// </summary>
public override void Detach()
{
this.VideoRender.PreviewMouseLeftButtonDown -= VideoRender_PreviewMouseLeftButtonDown;
}
/// <summary>
/// 鼠标左键点击
/// </summary>
private void VideoRender_PreviewMouseLeftButtonDown(object sender, System.Windows.Input.MouseButtonEventArgs e)
{
if (!this.IsEnabled || this.Click == null)
return;
VideoRenderInfo renderInfo = this.VideoRender.RenderInfo;
if (renderInfo == null)
return;
SideCheckPolygonClickEventArgs args = new SideCheckPolygonClickEventArgs();
args.MousePoint = e.GetPosition(this.VideoRender);
args.SrcPoint = ImageHelper.ConvertUiPointToImagePoint(renderInfo.Frame.Width, renderInfo.Frame.Height, renderInfo.DrawingRect, args.MousePoint);
this.Click.Invoke(this, args);
}
}
}
\ No newline at end of file
...@@ -25,5 +25,10 @@ namespace VIZ.Framework.Common ...@@ -25,5 +25,10 @@ namespace VIZ.Framework.Common
/// 裁剪框 /// 裁剪框
/// </summary> /// </summary>
public const string ClipBox = "ClipBox"; public const string ClipBox = "ClipBox";
/// <summary>
/// 边线检测多边形
/// </summary>
public const string SideCheckPolygon = "SideCheckPolygon";
} }
} }
...@@ -25,4 +25,27 @@ ...@@ -25,4 +25,27 @@
</Setter> </Setter>
</Style> </Style>
<Style TargetType="local:LabelValue2">
<Setter Property="FocusVisualStyle" Value="{x:Null}"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:LabelValue2">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock VerticalAlignment="Center" Foreground="#aa000000"
Text="{TemplateBinding Label}" Width="{TemplateBinding LabelWidth}"></TextBlock>
<TextBox Grid.Column="1" AcceptsReturn="False" IsReadOnly="True" TextWrapping="NoWrap"
Text="{TemplateBinding Text1}" VerticalContentAlignment="Center" Style="{StaticResource TextBox_None}"></TextBox>
<TextBox Grid.Column="2" AcceptsReturn="False" IsReadOnly="True" TextWrapping="NoWrap"
Text="{TemplateBinding Text2}" VerticalContentAlignment="Center" Style="{StaticResource TextBox_None}"></TextBox>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary> </ResourceDictionary>
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
namespace VIZ.Framework.Common
{
/// <summary>
/// 标签和值
/// </summary>
public class LabelValue2 : Control
{
static LabelValue2()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(LabelValue2), new FrameworkPropertyMetadata(typeof(LabelValue2)));
}
#region LabelWidth -- 标签宽度
/// <summary>
/// 标签宽度
/// </summary>
public double LabelWidth
{
get { return (double)GetValue(LabelWidthProperty); }
set { SetValue(LabelWidthProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for LabelWidth. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty LabelWidthProperty =
DependencyProperty.Register("LabelWidth", typeof(double), typeof(LabelValue2), new PropertyMetadata(120d));
#endregion
#region Label -- 标签
/// <summary>
/// 标签
/// </summary>
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for Label. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty LabelProperty =
DependencyProperty.Register("Label", typeof(string), typeof(LabelValue2), new PropertyMetadata(null));
#endregion
#region Text1 -- 文本1
/// <summary>
/// 文本1
/// </summary>
public string Text1
{
get { return (string)GetValue(Text1Property); }
set { SetValue(Text1Property, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for Text1. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty Text1Property =
DependencyProperty.Register("Text1", typeof(string), typeof(LabelValue2), new PropertyMetadata(null));
#endregion
#region Text2 -- 文本2
/// <summary>
/// 文本2
/// </summary>
public string Text2
{
get { return (string)GetValue(Text2Property); }
set { SetValue(Text2Property, value); }
}
/// <summary>
/// Using a DependencyProperty as the backing store for Text2. This enables animation, styling, binding, etc...
/// </summary>
public static readonly DependencyProperty Text2Property =
DependencyProperty.Register("Text2", typeof(string), typeof(LabelValue2), new PropertyMetadata(null));
#endregion
}
}
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
using System.Windows.Media;
namespace VIZ.Framework.Core
{
/// <summary>
/// Bool -> SolidColorBrush 转化器
/// </summary>
public class Bool2SolidColorBrushConverter : IValueConverter
{
/// <summary>
/// 值为None时的画刷
/// </summary>
public Brush NoneBrush { get; set; } = new SolidColorBrush(Colors.White);
/// <summary>
/// 值为False时的画刷
/// </summary>
public Brush FalseBrush { get; set; } = new SolidColorBrush(Colors.White);
/// <summary>
/// 值为True时的画刷
/// </summary>
public Brush TrueBrush { get; set; } = new SolidColorBrush(Colors.Red);
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value is bool?)
{
bool? b = (bool?)value;
if (b == null)
return this.NoneBrush;
return b.Value ? this.TrueBrush : this.FalseBrush;
}
else if (value is bool)
{
bool b = (bool)value;
return b ? this.TrueBrush : this.FalseBrush;
}
else
{
return this.NoneBrush;
}
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Management;
using System.Text;
using System.Threading.Tasks;
namespace VIZ.Framework.Core
{
/// <summary>
/// 进程辅助类
/// </summary>
public static class ProcessHelper
{
/// <summary>
/// 获取进程的启动命令行
/// </summary>
/// <param name="process">进程对象</param>
/// <returns>启动命令行</returns>
public static string GetCommandLine(Process process)
{
using (ManagementObjectSearcher searcher = new ManagementObjectSearcher("SELECT CommandLine FROM Win32_Process WHERE ProcessId = " + process.Id))
using (ManagementObjectCollection objects = searcher.Get())
{
return objects.Cast<ManagementBaseObject>().SingleOrDefault()?["CommandLine"]?.ToString() ?? string.Empty;
}
}
}
}
...@@ -4,6 +4,7 @@ using System.Windows; ...@@ -4,6 +4,7 @@ using System.Windows;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
using SharpDX.Mathematics.Interop;
namespace VIZ.Framework.Core namespace VIZ.Framework.Core
{ {
...@@ -153,7 +154,7 @@ namespace VIZ.Framework.Core ...@@ -153,7 +154,7 @@ namespace VIZ.Framework.Core
/// <param name="uiDrawRect">图片在UI的绘制区域</param> /// <param name="uiDrawRect">图片在UI的绘制区域</param>
/// <param name="imgPoint">图片坐标点</param> /// <param name="imgPoint">图片坐标点</param>
/// <returns>UI坐标点</returns> /// <returns>UI坐标点</returns>
public static Point ConvertImagePointToUiPoint(int imgWidth, int imgHeight, Rect uiDrawRect, Rect imgPoint) public static RawVector2 ConvertImagePointToUiPoint(int imgWidth, int imgHeight, Rect uiDrawRect, RawVector2 imgPoint)
{ {
double xp = uiDrawRect.Width / imgWidth; double xp = uiDrawRect.Width / imgWidth;
double yp = uiDrawRect.Height / imgHeight; double yp = uiDrawRect.Height / imgHeight;
...@@ -161,7 +162,7 @@ namespace VIZ.Framework.Core ...@@ -161,7 +162,7 @@ namespace VIZ.Framework.Core
double destX = uiDrawRect.X + imgPoint.X * xp; double destX = uiDrawRect.X + imgPoint.X * xp;
double destY = uiDrawRect.Y + imgPoint.Y * yp; double destY = uiDrawRect.Y + imgPoint.Y * yp;
return new Point(destX, destY); return new RawVector2((float)destX, (float)destY);
} }
/// <summary> /// <summary>
......
...@@ -34,5 +34,15 @@ namespace VIZ.Framework.Core ...@@ -34,5 +34,15 @@ namespace VIZ.Framework.Core
{ {
return new RawRectangleF((float)rect.Left, (float)rect.Top, (float)rect.Right, (float)rect.Bottom); return new RawRectangleF((float)rect.Left, (float)rect.Top, (float)rect.Right, (float)rect.Bottom);
} }
/// <summary>
/// 将Point转化为RawVector2
/// </summary>
/// <param name="point">点</param>
/// <returns>RawVector2</returns>
public static RawVector2 ToRawVector2(this System.Windows.Point point)
{
return new RawVector2((float)point.X, (float)point.Y);
}
} }
} }
...@@ -89,7 +89,9 @@ ...@@ -89,7 +89,9 @@
<ItemGroup> <ItemGroup>
<Compile Include="Core\Converter\Bool2BoolConverter.cs" /> <Compile Include="Core\Converter\Bool2BoolConverter.cs" />
<Compile Include="Core\Converter\ByteSizeConverter.cs" /> <Compile Include="Core\Converter\ByteSizeConverter.cs" />
<Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" />
<Compile Include="Core\Enum\EnumHelper.cs" /> <Compile Include="Core\Enum\EnumHelper.cs" />
<Compile Include="Core\Helper\ProcessHelper.cs" />
<Compile Include="Expand\GPI\GPIManager.cs" /> <Compile Include="Expand\GPI\GPIManager.cs" />
<Compile Include="Expand\GPI\GPI_USB2GPI_DEVICE.cs" /> <Compile Include="Expand\GPI\GPI_USB2GPI_DEVICE.cs" />
<Compile Include="Expand\GPI\GPI_USB_DEVICE.cs" /> <Compile Include="Expand\GPI\GPI_USB_DEVICE.cs" />
......
...@@ -8,6 +8,6 @@ ...@@ -8,6 +8,6 @@
mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="None" mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="None"
Title="MainWindow" Height="800" Width="1200"> Title="MainWindow" Height="800" Width="1200">
<Grid> <Grid>
<local:HotkeyBoxTest></local:HotkeyBoxTest> <local:OpenCVVideoTest></local:OpenCVVideoTest>
</Grid> </Grid>
</Window> </Window>
...@@ -39,9 +39,13 @@ namespace VIZ.Framework.WpfTest ...@@ -39,9 +39,13 @@ namespace VIZ.Framework.WpfTest
ClipBoxPlugin clipBoxPlugin = new ClipBoxPlugin(this.video); ClipBoxPlugin clipBoxPlugin = new ClipBoxPlugin(this.video);
SideCheckPolygonPlugin sideCheckPolygonPlugin = new SideCheckPolygonPlugin(this.video);
sideCheckPolygonPlugin.Click += SideCheckPolygonPlugin_Click;
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);
// 接入OpenCV插件 // 接入OpenCV插件
OpenCVStreamOption option = new OpenCVStreamOption(); OpenCVStreamOption option = new OpenCVStreamOption();
...@@ -51,31 +55,53 @@ namespace VIZ.Framework.WpfTest ...@@ -51,31 +55,53 @@ namespace VIZ.Framework.WpfTest
stream.Play(); stream.Play();
// 更新矩形框信息 // 更新矩形框信息
List<TrackingBoxInfo> list = new List<TrackingBoxInfo>(); //List<TrackingBoxInfo> list = new List<TrackingBoxInfo>();
list.Add(new TrackingBoxInfo //list.Add(new TrackingBoxInfo
{ //{
DrawingBorderColor = SharpDxColorHelper.FromString("#FFFF0000"), // DrawingBorderColor = SharpDxColorHelper.FromString("#FFFF0000"),
ID = "1", // ID = "1",
DrawingBorderWidth = 4, // DrawingBorderWidth = 4,
SrcRect = new SharpDX.Mathematics.Interop.RawRectangleF(0, 0, 200, 120) // SrcRect = new SharpDX.Mathematics.Interop.RawRectangleF(0, 0, 200, 120)
}); //});
list.Add(new TrackingBoxInfo //list.Add(new TrackingBoxInfo
//{
// DrawingBorderColor = SharpDxColorHelper.FromString("#FFFF0000"),
// ID = "1",
// DrawingBorderWidth = 4,
// SrcRect = new SharpDX.Mathematics.Interop.RawRectangleF(400, 300, 600, 420)
//});
//this.video.UpdateTrackingBox(list);
// 裁剪
//ClipBoxInfo clipBoxInfo = new ClipBoxInfo();
//clipBoxInfo.DrawingBorderWidth = 8;
//clipBoxInfo.DrawingBorderColor = SharpDxColorHelper.FromString("#AA0000FF");
//clipBoxInfo.MaskColor = SharpDxColorHelper.FromString("#66000000");
//clipBoxInfo.SrcRect = new SharpDX.Mathematics.Interop.RawRectangleF(200, 0, 800, 1080);
//this.video.UpdateClipBox(clipBoxInfo);
// 边线检测
List<SideCheckPolygonInfo> sideCheckPolygonInfos = new List<SideCheckPolygonInfo>();
sideCheckPolygonInfos.Add(new SideCheckPolygonInfo
{ {
DrawingBorderColor = SharpDxColorHelper.FromString("#FFFF0000"), FillColor = SharpDxColorHelper.FromString("#66FF000000"),
ID = "1", SrcPoints = new List<SharpDX.Mathematics.Interop.RawVector2>()
DrawingBorderWidth = 4, {
SrcRect = new SharpDX.Mathematics.Interop.RawRectangleF(400, 300, 600, 420) new SharpDX.Mathematics.Interop.RawVector2(100, 100),
new SharpDX.Mathematics.Interop.RawVector2(300, 100),
new SharpDX.Mathematics.Interop.RawVector2(500, 300),
new SharpDX.Mathematics.Interop.RawVector2(600, 500),
new SharpDX.Mathematics.Interop.RawVector2(100, 100)
}
}); });
this.video.UpdateTrackingBox(list);
// 裁剪 this.video.UpdateSideCheckPolygon(sideCheckPolygonInfos);
ClipBoxInfo clipBoxInfo = new ClipBoxInfo(); }
clipBoxInfo.DrawingBorderWidth = 8;
clipBoxInfo.DrawingBorderColor = SharpDxColorHelper.FromString("#AA0000FF");
clipBoxInfo.MaskColor = SharpDxColorHelper.FromString("#66000000");
clipBoxInfo.SrcRect = new SharpDX.Mathematics.Interop.RawRectangleF(200, 0, 800, 1080);
this.video.UpdateClipBox(clipBoxInfo); private void SideCheckPolygonPlugin_Click(object sender, SideCheckPolygonClickEventArgs e)
{
Debug.WriteLine($"SideCheckPolygonPlugin_Click: [{e.MousePoint.X}, {e.MousePoint.Y}] [{e.SrcPoint.X}, {e.SrcPoint.Y}]");
} }
private void Stream_ExecuteVideoFrame(object sender, VideoFrameEventArgs e) private void Stream_ExecuteVideoFrame(object sender, VideoFrameEventArgs e)
......
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