Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VIZ.Framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
王永辉
VIZ.Framework
Commits
8d12af08
Commit
8d12af08
authored
Sep 05, 2022
by
liulongfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 视频控件添加手动校准插件
parent
b6d7ca1a
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
351 additions
and
3 deletions
+351
-3
VIZ.Framework.Common/VIZ.Framework.Common.csproj
+4
-0
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/EventArgs/ManualCorrectionClickEventArgs.cs
+25
-0
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/Info/ManualCorrectionInfo.cs
+30
-0
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/ManualCorrectionExpand.cs
+48
-0
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/ManualCorrectionPlugin.cs
+113
-0
VIZ.Framework.Common/VideoControl/Control/VideoControlPluginNames.cs
+5
-0
VIZ.Framework.Common/VideoControl/Recording/VideoControlRecording.cs
+1
-1
VIZ.Framework.Core/Core/Converter/StringAppendConverter.cs
+29
-0
VIZ.Framework.Core/Core/Image/ImageHelper.cs
+64
-0
VIZ.Framework.Core/VIZ.Framework.Core.csproj
+1
-0
VIZ.Framework.Storage/Ini/Config/VideoConfig.cs
+7
-1
VIZ.Framework.WpfTest/MainWindow.xaml
+1
-1
VIZ.Framework.WpfTest/VideoRender/OpenCVVideoTest.xaml
+1
-0
VIZ.Framework.WpfTest/VideoRender/OpenCVVideoTest.xaml.cs
+22
-0
No files found.
VIZ.Framework.Common/VIZ.Framework.Common.csproj
View file @
8d12af08
...
...
@@ -186,6 +186,10 @@
<Compile Include="SharpDx\WIC\WicBitmapHelper.cs" />
<Compile Include="SharpDx\WPF\D2dControl.cs" />
<Compile Include="SharpDx\WPF\Dx11ImageSource.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\EventArgs\ManualCorrectionClickEventArgs.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionExpand.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\Info\ManualCorrectionInfo.cs" />
<Compile Include="VideoControl\Control\Plugin\ManualCorrection\ManualCorrectionPlugin.cs" />
<Compile Include="VideoControl\Recording\VideoControlRecordingFrame.cs" />
<Compile Include="VideoControl\Recording\VideoControlRecording.cs" />
<Compile Include="VideoControl\Sync\IVideoControlSync.cs" />
...
...
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/EventArgs/ManualCorrectionClickEventArgs.cs
0 → 100644
View file @
8d12af08
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
ManualCorrectionClickEventArgs
:
EventArgs
{
/// <summary>
/// 鼠标点击位置
/// </summary>
public
Point
MousePoint
{
get
;
set
;
}
/// <summary>
/// 源坐标位置
/// </summary>
public
Point
SrcPoint
{
get
;
set
;
}
}
}
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/Info/ManualCorrectionInfo.cs
0 → 100644
View file @
8d12af08
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
ManualCorrectionInfo
{
/// <summary>
/// 填充颜色
/// </summary>
public
RawColor4
FillColor
{
get
;
set
;
}
/// <summary>
/// 源半径
/// </summary>
public
float
SrcRadius
{
get
;
set
;
}
/// <summary>
/// 源中心点
/// </summary>
public
RawVector2
SrcCenter
{
get
;
set
;
}
}
}
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/ManualCorrectionExpand.cs
0 → 100644
View file @
8d12af08
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
static
class
ManualCorrectionExpand
{
/// <summary>
/// 更新手动校准区域
/// </summary>
/// <param name="videoControl">视频控件</param>
/// <param name="manualCorrectionInfo">手动校准区域</param>
public
static
void
UpdateManualCorrection
(
this
VideoControl
videoControl
,
ManualCorrectionInfo
manualCorrectionInfo
)
{
if
(
videoControl
.
videoRender
==
null
)
return
;
ManualCorrectionPlugin
plugin
=
videoControl
.
GetPlugin
<
ManualCorrectionPlugin
>(
VideoControlPluginNames
.
ManualCorrection
);
if
(
plugin
==
null
)
return
;
plugin
.
Update
(
manualCorrectionInfo
);
}
/// <summary>
/// 清理手动校准区域
/// </summary>
/// <param name="videoControl">视频控件</param>
public
static
void
ClearManualCorrection
(
this
VideoControl
videoControl
)
{
if
(
videoControl
.
videoRender
==
null
)
return
;
ManualCorrectionPlugin
plugin
=
videoControl
.
GetPlugin
<
ManualCorrectionPlugin
>(
VideoControlPluginNames
.
ManualCorrection
);
if
(
plugin
==
null
)
return
;
plugin
.
Update
(
null
);
}
}
}
VIZ.Framework.Common/VideoControl/Control/Plugin/ManualCorrection/ManualCorrectionPlugin.cs
0 → 100644
View file @
8d12af08
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
ManualCorrectionPlugin
:
VideoPluginBase
{
/// <summary>
/// 日志
/// </summary>
private
static
readonly
ILog
log
=
LogManager
.
GetLogger
(
typeof
(
ManualCorrectionPlugin
));
/// <summary>
/// 手动校准插件
/// </summary>
/// <param name="videoControl">视频控件</param>
public
ManualCorrectionPlugin
(
VideoControl
videoControl
)
:
base
(
videoControl
)
{
}
/// <summary>
/// 名称
/// </summary>
public
override
string
Name
=>
VideoControlPluginNames
.
ManualCorrection
;
/// <summary>
/// 点击事件
/// </summary>
public
event
EventHandler
<
ManualCorrectionClickEventArgs
>
Click
;
/// <summary>
/// 手动校准信息
/// </summary>
private
volatile
ManualCorrectionInfo
manualCorrectionInfo
;
/// <summary>
/// 更新数据
/// </summary>
/// <param name="manualCorrectionInfo">跟踪框信息</param>
public
void
Update
(
ManualCorrectionInfo
manualCorrectionInfo
)
{
this
.
manualCorrectionInfo
=
manualCorrectionInfo
;
}
/// <summary>
/// 渲染
/// </summary>
/// <param name="context">渲染上下文</param>
public
override
void
Render
(
VideoRenderContext
context
)
{
// 画面渲染区域
ManualCorrectionInfo
info
=
this
.
manualCorrectionInfo
;
if
(
info
==
null
)
return
;
SolidColorBrush
brush
=
new
SolidColorBrush
(
context
.
Target
,
info
.
FillColor
);
RawVector2
center
=
ImageHelper
.
ConvertImagePointToUiPoint
(
context
.
VideoRenderInfo
.
Frame
.
Width
,
context
.
VideoRenderInfo
.
Frame
.
Height
,
context
.
VideoRenderInfo
.
DrawingRect
,
info
.
SrcCenter
);
float
radius
=
(
float
)
ImageHelper
.
ConvertImageDistanceToUiDistanceUseX
(
context
.
VideoRenderInfo
.
Frame
.
Width
,
context
.
VideoRenderInfo
.
DrawingRect
,
info
.
SrcRadius
);
Ellipse
ellipse
=
new
Ellipse
(
center
,
radius
,
radius
);
context
.
Target
.
FillEllipse
(
ellipse
,
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
;
ManualCorrectionClickEventArgs
args
=
new
ManualCorrectionClickEventArgs
();
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
VIZ.Framework.Common/VideoControl/Control/VideoControlPluginNames.cs
View file @
8d12af08
...
...
@@ -30,5 +30,10 @@ namespace VIZ.Framework.Common
/// 边线检测多边形
/// </summary>
public
const
string
SideCheckPolygon
=
"SideCheckPolygon"
;
/// <summary>
/// 手动校准
/// </summary>
public
const
string
ManualCorrection
=
"ManualCorrection"
;
}
}
VIZ.Framework.Common/VideoControl/Recording/VideoControlRecording.cs
View file @
8d12af08
...
...
@@ -31,7 +31,7 @@ namespace VIZ.Framework.Common
/// <summary>
/// 是否正在保存
/// </summary>
public
bool
IsSaving
{
get
;
protected
set
;
}
public
bool
IsSaving
{
get
;
protected
set
;
}
=
false
;
/// <summary>
/// 录制帧队列
...
...
VIZ.Framework.Core/Core/Converter/StringAppendConverter.cs
0 → 100644
View file @
8d12af08
using
System
;
using
System.Collections.Generic
;
using
System.Globalization
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
System.Windows.Data
;
namespace
VIZ.Framework.Core
{
/// <summary>
/// 字符串拼接转化器
/// </summary>
public
class
StringAppendConverter
:
IValueConverter
{
public
object
Convert
(
object
value
,
Type
targetType
,
object
parameter
,
CultureInfo
culture
)
{
string
v1
=
value
==
null
?
string
.
Empty
:
value
.
ToString
();
string
v2
=
parameter
==
null
?
string
.
Empty
:
parameter
.
ToString
();
return
v1
+
v2
;
}
public
object
ConvertBack
(
object
value
,
Type
targetType
,
object
parameter
,
CultureInfo
culture
)
{
throw
new
NotImplementedException
();
}
}
}
VIZ.Framework.Core/Core/Image/ImageHelper.cs
View file @
8d12af08
...
...
@@ -147,6 +147,38 @@ namespace VIZ.Framework.Core
}
/// <summary>
/// 将UI距离转化为图片距离,使用X轴比例
/// </summary>
/// <param name="imgWidth">图片宽度</param>
/// <param name="uiDrawRect">图片在UI的绘制区域</param>
/// <param name="distance">UI距离</param>
/// <returns>图片距离</returns>
public
static
double
ConvertUiDistanceToImageDistanceUseX
(
int
imgWidth
,
Rect
uiDrawRect
,
double
distance
)
{
double
xp
=
uiDrawRect
.
Width
/
imgWidth
;
double
destX
=
(
distance
-
uiDrawRect
.
X
)
/
xp
;
return
destX
;
}
/// <summary>
/// 将UI距离转化为图片距离,使用Y轴比例
/// </summary>
/// <param name="imgHeight">图片高度</param>
/// <param name="uiDrawRect">图片在UI的绘制区域</param>
/// <param name="distance">UI距离</param>
/// <returns>图片距离</returns>
public
static
double
ConvertUiDistanceToImageDistanceUseY
(
int
imgHeight
,
Rect
uiDrawRect
,
double
distance
)
{
double
yp
=
uiDrawRect
.
Height
/
imgHeight
;
double
destY
=
(
distance
-
uiDrawRect
.
Y
)
/
yp
;
return
destY
;
}
/// <summary>
/// 将图片坐标点转化为UI坐标点
/// </summary>
/// <param name="imgWidth">图片宽度</param>
...
...
@@ -187,6 +219,38 @@ namespace VIZ.Framework.Core
}
/// <summary>
/// 将图片距离转化为UI距离,使用X轴比例
/// </summary>
/// <param name="imgWidth">图片宽度</param>
/// <param name="uiDrawRect">图片在UI的绘制区域</param>
/// <param name="distance">图片距离</param>
/// <returns>UI距离</returns>
public
static
double
ConvertImageDistanceToUiDistanceUseX
(
int
imgWidth
,
Rect
uiDrawRect
,
double
distance
)
{
double
xp
=
uiDrawRect
.
Width
/
imgWidth
;
double
destX
=
distance
*
xp
;
return
destX
;
}
/// <summary>
/// 将图片距离转化为UI距离,使用Y轴比例
/// </summary>
/// <param name="imgHeight">图片高度</param>
/// <param name="uiDrawRect">图片在UI的绘制区域</param>
/// <param name="distance">图片距离</param>
/// <returns>UI距离</returns>
public
static
double
ConvertImageDistanceToUiDistanceUseY
(
int
imgHeight
,
Rect
uiDrawRect
,
double
distance
)
{
double
yp
=
uiDrawRect
.
Height
/
imgHeight
;
double
destY
=
distance
*
yp
;
return
destY
;
}
/// <summary>
/// 使用bottom矩形区域裁剪top矩形区域,使top矩形区域包括在bottom矩形区域内
/// </summary>
/// <param name="topRect">top矩形区域</param>
...
...
VIZ.Framework.Core/VIZ.Framework.Core.csproj
View file @
8d12af08
...
...
@@ -90,6 +90,7 @@
<Compile Include="Core\Converter\Bool2BoolConverter.cs" />
<Compile Include="Core\Converter\ByteSizeConverter.cs" />
<Compile Include="Core\Converter\Bool2SolidColorBrushConverter.cs" />
<Compile Include="Core\Converter\StringAppendConverter.cs" />
<Compile Include="Core\Enum\EnumHelper.cs" />
<Compile Include="Core\Helper\ByteHelper.cs" />
<Compile Include="Core\Helper\ProcessHelper.cs" />
...
...
VIZ.Framework.Storage/Ini/Config/VideoConfig.cs
View file @
8d12af08
...
...
@@ -81,7 +81,13 @@ namespace VIZ.Framework.Storage
/// <summary>
/// 视频边线检测多边形区域透明度
/// </summary>
[
Ini
(
Section
=
"Video"
,
DefaultValue
=
"0.
2
"
,
Type
=
typeof
(
double
))]
[
Ini
(
Section
=
"Video"
,
DefaultValue
=
"0.
15
"
,
Type
=
typeof
(
double
))]
public
string
VIDEO_SIDE_CHECK_POLYGON_OPACITY
{
get
;
set
;
}
/// <summary>
/// 手动校准区域透明度
/// </summary>
[
Ini
(
Section
=
"Video"
,
DefaultValue
=
"0.2"
,
Type
=
typeof
(
double
))]
public
string
VIDEO_MANUAL_CORRECTION_OPACITY
{
get
;
set
;
}
}
}
VIZ.Framework.WpfTest/MainWindow.xaml
View file @
8d12af08
...
...
@@ -8,6 +8,6 @@
mc:Ignorable="d" WindowStartupLocation="CenterScreen" WindowState="Maximized" WindowStyle="None"
Title="MainWindow" Height="800" Width="1200">
<Grid>
<local:
Mouse3DTest></local:Mouse3D
Test>
<local:
OpenCVVideoTest></local:OpenCVVideo
Test>
</Grid>
</Window>
VIZ.Framework.WpfTest/VideoRender/OpenCVVideoTest.xaml
View file @
8d12af08
...
...
@@ -15,6 +15,7 @@
<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_Click2"></Button>
<Button Margin="10,0,10,0" Width="120" Height="40" Content="手动校准测试" Click="Button_Click3"></Button>
</StackPanel>
</Grid>
</UserControl>
VIZ.Framework.WpfTest/VideoRender/OpenCVVideoTest.xaml.cs
View file @
8d12af08
...
...
@@ -42,10 +42,14 @@ namespace VIZ.Framework.WpfTest
SideCheckPolygonPlugin
sideCheckPolygonPlugin
=
new
SideCheckPolygonPlugin
(
this
.
video
);
sideCheckPolygonPlugin
.
Click
+=
SideCheckPolygonPlugin_Click
;
ManualCorrectionPlugin
manualCorrectionPlugin
=
new
ManualCorrectionPlugin
(
this
.
video
);
manualCorrectionPlugin
.
Click
+=
ManualCorrectionPlugin_Click
;
this
.
video
.
AttachPlugin
(
trackingBoxPlugin
);
this
.
video
.
AttachPlugin
(
selectionBoxPlugin
);
this
.
video
.
AttachPlugin
(
clipBoxPlugin
);
this
.
video
.
AttachPlugin
(
sideCheckPolygonPlugin
);
this
.
video
.
AttachPlugin
(
manualCorrectionPlugin
);
// 接入OpenCV插件
OpenCVStreamOption
option
=
new
OpenCVStreamOption
();
...
...
@@ -99,6 +103,16 @@ namespace VIZ.Framework.WpfTest
this
.
video
.
UpdateSideCheckPolygon
(
sideCheckPolygonInfos
);
}
private
void
ManualCorrectionPlugin_Click
(
object
sender
,
ManualCorrectionClickEventArgs
e
)
{
ManualCorrectionInfo
info
=
new
ManualCorrectionInfo
();
info
.
FillColor
=
SharpDxColorHelper
.
FromString
(
"#2200FF00"
);
info
.
SrcRadius
=
200
;
info
.
SrcCenter
=
new
SharpDX
.
Mathematics
.
Interop
.
RawVector2
(
100
,
100
);
this
.
video
.
UpdateManualCorrection
(
info
);
}
private
void
SideCheckPolygonPlugin_Click
(
object
sender
,
SideCheckPolygonClickEventArgs
e
)
{
Debug
.
WriteLine
(
$"SideCheckPolygonPlugin_Click: [
{
e
.
MousePoint
.
X
}
,
{
e
.
MousePoint
.
Y
}
] [
{
e
.
SrcPoint
.
X
}
,
{
e
.
SrcPoint
.
Y
}
]"
);
...
...
@@ -142,5 +156,13 @@ namespace VIZ.Framework.WpfTest
{
this
.
video
.
ClearClipBox
();
}
/// <summary>
/// 手动校准测试
/// </summary>
private
void
Button_Click3
(
object
sender
,
RoutedEventArgs
e
)
{
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment