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
6c799b94
Commit
6c799b94
authored
Oct 27, 2022
by
liulongfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
1. 中心轴添加水平和垂直设置
parent
f9e08c84
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
63 additions
and
267 deletions
+63
-267
VIZ.Framework.Common/VIZ.Framework.Common.csproj
+1
-2
VIZ.Framework.Common/VideoControl/Control/Plugin/CenterAxis/CenterAxisPlugin.cs
+13
-6
VIZ.Framework.Common/VideoControl/Control/Plugin/CenterAxis/Info/CenterAxisInfo.cs
+5
-0
VIZ.Framework.Common/VideoControl/Control/Plugin/CenterAxis/Info/CenterAxisType.cs
+8
-13
VIZ.Framework.Common/VideoControl/Control/Plugin/TrackingBox/TrackingBoxPlugin.cs
+9
-0
VIZ.Framework.Common/VideoControl/Stream/IVideoFrame.cs
+0
-5
VIZ.Framework.Common/VideoControl/Stream/OpenCV/OpenCVStream.cs
+15
-184
VIZ.Framework.Common/VideoControl/Stream/OpenCV/OpenCVStreamStatus.cs
+0
-31
VIZ.Framework.Common/VideoControl/Stream/OpenCV/Task/OpenCVStreamRecvVideoTask.cs
+12
-21
VIZ.Framework.Common/VideoControl/Stream/VideoFrameBase.cs
+0
-5
No files found.
VIZ.Framework.Common/VIZ.Framework.Common.csproj
View file @
6c799b94
...
...
@@ -212,6 +212,7 @@
<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\CenterAxis\Info\CenterAxisType.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" />
...
...
@@ -274,11 +275,9 @@
<Compile Include="VideoControl\Stream\NDI\Task\NDIStreamExecuteVideoTask.cs" />
<Compile Include="VideoControl\Stream\NDI\Task\NDIStreamFindStreamTask.cs" />
<Compile Include="VideoControl\Stream\NDI\Task\NDIStreamRecvVideoTask.cs" />
<Compile Include="VideoControl\Stream\OpenCV\OpenCVPropertyInfos.cs" />
<Compile Include="VideoControl\Stream\OpenCV\OpenCVStreamTaskNames.cs" />
<Compile Include="VideoControl\Stream\OpenCV\OpenCVStream.cs" />
<Compile Include="VideoControl\Stream\OpenCV\OpenCVStreamOption.cs" />
<Compile Include="VideoControl\Stream\OpenCV\OpenCVStreamStatus.cs" />
<Compile Include="VideoControl\Stream\OpenCV\OpenCVStreamTaskBase.cs" />
<Compile Include="VideoControl\Stream\OpenCV\OpenCVStreeamVideoFrame.cs" />
<Compile Include="VideoControl\Stream\OpenCV\Task\OpenCVStreamExecuteVideoTask.cs" />
...
...
VIZ.Framework.Common/VideoControl/Control/Plugin/CenterAxis/CenterAxisPlugin.cs
View file @
6c799b94
...
...
@@ -63,14 +63,20 @@ namespace VIZ.Framework.Common
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
,
(
float
)
info
.
AxisWidth
);
if
(
info
.
AxisType
==
CenterAxisType
.
All
||
info
.
AxisType
==
CenterAxisType
.
Horizontal
)
{
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
,
(
float
)
info
.
AxisWidth
);
}
// 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
,
(
float
)
info
.
AxisWidth
);
if
(
info
.
AxisType
==
CenterAxisType
.
All
||
info
.
AxisType
==
CenterAxisType
.
Vertical
)
{
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
,
(
float
)
info
.
AxisWidth
);
}
}
}
}
\ No newline at end of file
VIZ.Framework.Common/VideoControl/Control/Plugin/CenterAxis/Info/CenterAxisInfo.cs
View file @
6c799b94
...
...
@@ -26,5 +26,10 @@ namespace VIZ.Framework.Common
/// 轴颜色
/// </summary>
public
RawColor4
AxisColor
{
get
;
set
;
}
/// <summary>
/// 安全轴类型
/// </summary>
public
CenterAxisType
AxisType
{
get
;
set
;
}
=
CenterAxisType
.
All
;
}
}
VIZ.Framework.Common/VideoControl/
Stream/OpenCV/OpenCVPropertyInfos
.cs
→
VIZ.Framework.Common/VideoControl/
Control/Plugin/CenterAxis/Info/CenterAxisType
.cs
View file @
6c799b94
...
...
@@ -7,28 +7,23 @@ using System.Threading.Tasks;
namespace
VIZ.Framework.Common
{
/// <summary>
///
OpenCV属性信息
///
中心轴类型
/// </summary>
public
class
OpenCVPropertyInfos
public
enum
CenterAxisType
{
/// <summary>
///
Fps
///
水平
/// </summary>
public
double
Fps
{
get
;
internal
set
;
}
Horizontal
,
/// <summary>
///
帧宽度
///
垂直
/// </summary>
public
double
FrameWidth
{
get
;
internal
set
;
}
Vertical
,
/// <summary>
///
帧高度
///
水平和垂直
/// </summary>
public
double
FrameHeight
{
get
;
internal
set
;
}
/// <summary>
/// 帧数
/// </summary>
public
double
FrameCount
{
get
;
internal
set
;
}
All
}
}
VIZ.Framework.Common/VideoControl/Control/Plugin/TrackingBox/TrackingBoxPlugin.cs
View file @
6c799b94
...
...
@@ -57,6 +57,15 @@ namespace VIZ.Framework.Common
}
/// <summary>
/// 获取跟踪数据
/// </summary>
/// <returns>跟踪数据</returns>
public
List
<
TrackingBoxInfo
>
GetTrackingBoxInfos
()
{
return
this
.
trackingBoxInfos
;
}
/// <summary>
/// 渲染
/// </summary>
/// <param name="context">渲染上下文</param>
...
...
VIZ.Framework.Common/VideoControl/Stream/IVideoFrame.cs
View file @
6c799b94
...
...
@@ -29,11 +29,6 @@ namespace VIZ.Framework.Common
int
Length
{
get
;
set
;
}
/// <summary>
/// 是否是最后一帧
/// </summary>
bool
IsEnd
{
get
;
set
;
}
/// <summary>
/// 画面数据
/// </summary>
DataStream
DataStream
{
get
;
set
;
}
...
...
VIZ.Framework.Common/VideoControl/Stream/OpenCV/OpenCVStream.cs
View file @
6c799b94
...
...
@@ -7,6 +7,7 @@ using System.Linq;
using
System.Text
;
using
System.Threading.Tasks
;
using
log4net
;
using
NewTek
;
namespace
VIZ.Framework.Common
{
...
...
@@ -23,9 +24,12 @@ namespace VIZ.Framework.Common
/// <summary>
/// OpenCv流
/// </summary>
/// <param name="index">设备索引</param>
/// <param name="option">设置</param>
public
OpenCVStream
(
OpenCVStreamOption
option
)
:
base
(
option
)
public
OpenCVStream
(
int
index
,
OpenCVStreamOption
option
)
:
base
(
option
)
{
this
.
Index
=
index
;
this
.
TaskDic
.
Add
(
OpenCVStreamTaskNames
.
RECV_VIDEO
,
new
OpenCVStreamRecvVideoTask
(
this
));
this
.
TaskDic
.
Add
(
OpenCVStreamTaskNames
.
EXECUTE_VIDEO
,
new
OpenCVStreamExecuteVideoTask
(
this
));
}
...
...
@@ -35,19 +39,9 @@ namespace VIZ.Framework.Common
/* ========================================================================================================= */
/// <summary>
/// 地址
/// </summary>
public
string
Uri
{
get
;
private
set
;
}
/// <summary>
/// 属性信息
/// 设备索引
/// </summary>
public
OpenCVPropertyInfos
PropertyInfos
{
get
;
private
set
;
}
/// <summary>
/// 状态
/// </summary>
public
OpenCVStreamStatus
Status
{
get
;
private
set
;
}
public
int
Index
{
get
;
private
set
;
}
/* ========================================================================================================= */
/* === Internal Field === */
...
...
@@ -58,11 +52,6 @@ namespace VIZ.Framework.Common
/// </summary>
internal
VideoCapture
VideoCapture
;
/// <summary>
/// 读取帧锁对象
/// </summary>
internal
object
read_frame_lock_object
=
new
object
();
/* ========================================================================================================= */
/* === Field === */
/* ========================================================================================================= */
...
...
@@ -77,41 +66,16 @@ namespace VIZ.Framework.Common
/* ========================================================================================================= */
/// <summary>
/// 播放
/// </summary>
public
void
Play
()
{
if
(
this
.
Status
==
OpenCVStreamStatus
.
None
||
this
.
Status
==
OpenCVStreamStatus
.
Play
)
return
;
double
frame
=
this
.
VideoCapture
.
Get
(
VideoCaptureProperties
.
PosFrames
);
if
(
frame
>=
this
.
PropertyInfos
.
FrameCount
)
{
this
.
Stop
();
}
foreach
(
var
task
in
this
.
TaskDic
.
Values
)
{
task
.
Start
();
}
this
.
Status
=
OpenCVStreamStatus
.
Play
;
}
/// <summary>
/// 暂停
/// 开始
/// </summary>
public
void
Pause
()
public
void
Start
()
{
if
(
this
.
Status
==
OpenCVStreamStatus
.
None
||
this
.
Status
==
OpenCVStreamStatus
.
Stop
)
return
;
this
.
VideoCapture
=
new
VideoCapture
(
this
.
Index
);
foreach
(
var
task
in
this
.
TaskDic
.
Values
)
{
task
.
Stop
();
}
this
.
Status
=
OpenCVStreamStatus
.
Pause
;
// 启动OpenCV视频帧接收任务
this
.
TaskDic
[
OpenCVStreamTaskNames
.
RECV_VIDEO
].
Start
();
// 启动OpenCV视频帧处理任务
this
.
TaskDic
[
OpenCVStreamTaskNames
.
EXECUTE_VIDEO
].
Start
();
}
/// <summary>
...
...
@@ -119,125 +83,11 @@ namespace VIZ.Framework.Common
/// </summary>
public
void
Stop
()
{
if
(
this
.
Status
==
OpenCVStreamStatus
.
None
)
return
;
// 停止所有任务
foreach
(
var
task
in
this
.
TaskDic
.
Values
)
{
task
.
Stop
();
}
this
.
VideoCapture
.
Set
(
VideoCaptureProperties
.
PosFrames
,
0
);
this
.
TriggerExecuteBlackVideoFrame
();
this
.
Status
=
OpenCVStreamStatus
.
Stop
;
}
/// <summary>
/// 设置位置
/// </summary>
/// <param name="position">帧位置</param>
public
void
SetPosition
(
int
position
)
{
if
(
this
.
Status
==
OpenCVStreamStatus
.
None
)
return
;
lock
(
this
.
read_frame_lock_object
)
{
this
.
VideoCapture
.
Set
(
VideoCaptureProperties
.
PosFrames
,
position
);
while
(
this
.
VideoFrameQueue
.
Count
>
0
)
{
if
(
this
.
VideoFrameQueue
.
TryDequeue
(
out
IVideoFrame
frame
))
{
frame
.
Dispose
();
}
}
}
}
/// <summary>
/// 切换源
/// </summary>
/// <param name="uri">源</param>
public
void
ChangeUri
(
string
uri
)
{
this
.
Stop
();
this
.
Uri
=
uri
;
this
.
VideoCapture
?.
Dispose
();
this
.
VideoCapture
=
null
;
if
(
string
.
IsNullOrWhiteSpace
(
uri
))
{
this
.
Status
=
OpenCVStreamStatus
.
None
;
this
.
PropertyInfos
=
null
;
return
;
}
try
{
this
.
VideoCapture
=
new
VideoCapture
(
this
.
Uri
);
this
.
InitPropertyInfos
();
}
catch
(
Exception
ex
)
{
log
.
Error
(
ex
);
this
.
Status
=
OpenCVStreamStatus
.
None
;
this
.
PropertyInfos
=
null
;
}
this
.
Status
=
OpenCVStreamStatus
.
Stop
;
}
/// <summary>
/// 触发执行黑色帧
/// </summary>
public
void
TriggerExecuteBlackVideoFrame
()
{
OpenCVStreeamVideoFrame
frame
=
new
OpenCVStreeamVideoFrame
(
Scalar
.
Black
);
this
.
TriggerExecuteVideoFrame
(
frame
);
}
/// <summary>
/// 触发执行第一帧
/// </summary>
public
void
TriggerExecuteCurrentPosVideoFrame
()
{
if
(
this
.
Status
==
OpenCVStreamStatus
.
None
)
return
;
OpenCVStreeamVideoFrame
videoFrame
=
new
OpenCVStreeamVideoFrame
();
lock
(
this
.
read_frame_lock_object
)
{
Mat
src
=
new
Mat
();
Mat
mat
=
new
Mat
();
if
(!
this
.
VideoCapture
.
Read
(
src
))
{
src
.
Dispose
();
return
;
}
Cv2
.
CvtColor
(
src
,
mat
,
ColorConversionCodes
.
BGR2BGRA
);
videoFrame
.
Width
=
mat
.
Width
;
videoFrame
.
Height
=
mat
.
Height
;
videoFrame
.
Length
=
mat
.
Width
*
mat
.
Height
*
4
;
videoFrame
.
TimeStamp
=
TimeSpan
.
FromMilliseconds
(
this
.
VideoCapture
.
PosMsec
).
Ticks
;
videoFrame
.
DataStream
=
new
SharpDX
.
DataStream
(
videoFrame
.
Length
,
true
,
true
);
unsafe
{
Buffer
.
MemoryCopy
(
mat
.
DataPointer
,
videoFrame
.
DataStream
.
DataPointer
.
ToPointer
(),
videoFrame
.
Length
,
videoFrame
.
Length
);
}
src
.
Dispose
();
mat
.
Dispose
();
}
this
.
TriggerExecuteVideoFrame
(
videoFrame
);
}
/// <summary>
...
...
@@ -261,24 +111,5 @@ namespace VIZ.Framework.Common
/* === Private Function === */
/* ========================================================================================================= */
/// <summary>
/// 初始化属性信息
/// </summary>
private
void
InitPropertyInfos
()
{
OpenCVPropertyInfos
infos
=
new
OpenCVPropertyInfos
();
// FPS
infos
.
Fps
=
this
.
VideoCapture
.
Get
(
VideoCaptureProperties
.
Fps
);
// 帧宽度
infos
.
FrameWidth
=
this
.
VideoCapture
.
Get
(
VideoCaptureProperties
.
FrameWidth
);
// 帧高度
infos
.
FrameHeight
=
this
.
VideoCapture
.
Get
(
VideoCaptureProperties
.
FrameHeight
);
// 帧数量
infos
.
FrameCount
=
this
.
VideoCapture
.
Get
(
VideoCaptureProperties
.
FrameCount
);
this
.
PropertyInfos
=
infos
;
}
}
}
VIZ.Framework.Common/VideoControl/Stream/OpenCV/OpenCVStreamStatus.cs
deleted
100644 → 0
View file @
f9e08c84
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
VIZ.Framework.Common
{
/// <summary>
/// OpenCV流状态
/// </summary>
public
enum
OpenCVStreamStatus
{
/// <summary>
/// 未指定,不可用
/// </summary>
None
,
/// <summary>
/// 播放状态
/// </summary>
Play
,
/// <summary>
/// 暂停状态
/// </summary>
Pause
,
/// <summary>
/// 停止状态
/// </summary>
Stop
}
}
VIZ.Framework.Common/VideoControl/Stream/OpenCV/Task/OpenCVStreamRecvVideoTask.cs
View file @
6c799b94
...
...
@@ -11,6 +11,7 @@ using System.Drawing;
using
System.Drawing.Imaging
;
using
OpenCvSharp
;
using
System.Diagnostics
;
using
log4net
;
namespace
VIZ.Framework.Common
{
...
...
@@ -29,46 +30,37 @@ namespace VIZ.Framework.Common
}
/// <summary>
///
任务名称
///
日志
/// </summary>
p
ublic
override
OpenCVStreamTaskNames
Name
=>
OpenCVStreamTaskNames
.
RECV_VIDEO
;
p
rivate
readonly
static
ILog
log
=
LogManager
.
GetLogger
(
typeof
(
OpenCVStreamRecvVideoTask
))
;
/// <summary>
///
计时器
///
任务名称
/// </summary>
p
rivate
readonly
Stopwatch
renderTimer
=
new
Stopwatch
()
;
p
ublic
override
OpenCVStreamTaskNames
Name
=>
OpenCVStreamTaskNames
.
RECV_VIDEO
;
/// <summary>
/// 执行
/// </summary>
protected
override
void
Execute
()
{
while
(
this
.
IsStarted
)
try
{
long
begin
=
this
.
renderTimer
.
ElapsedMilliseconds
;
this
.
renderTimer
.
Start
();
lock
(
this
.
Stream
.
read_frame_lock_object
)
while
(
this
.
IsStarted
)
{
// 处理一帧
this
.
ExecuteOne
();
}
this
.
renderTimer
.
Stop
();
long
end
=
this
.
renderTimer
.
ElapsedMilliseconds
;
int
wait
=
(
int
)((
1000d
/
this
.
Stream
.
PropertyInfos
.
Fps
)
-
(
end
-
begin
));
if
(
wait
>
0
)
{
Thread
.
Sleep
(
wait
);
}
}
catch
(
Exception
ex
)
{
log
.
Error
(
ex
);
}
}
/// <summary>
/// 执行一帧
/// </summary>
p
ublic
void
ExecuteOne
()
p
rivate
void
ExecuteOne
()
{
Mat
src
=
new
Mat
();
Mat
mat
=
new
Mat
();
...
...
@@ -87,7 +79,6 @@ namespace VIZ.Framework.Common
videoFrame
.
Length
=
mat
.
Width
*
mat
.
Height
*
4
;
videoFrame
.
TimeStamp
=
TimeSpan
.
FromMilliseconds
(
this
.
Stream
.
VideoCapture
.
PosMsec
).
Ticks
;
videoFrame
.
DataStream
=
new
SharpDX
.
DataStream
(
videoFrame
.
Length
,
true
,
true
);
videoFrame
.
IsEnd
=
this
.
Stream
.
VideoCapture
.
PosFrames
==
this
.
Stream
.
PropertyInfos
.
FrameCount
;
unsafe
{
Buffer
.
MemoryCopy
(
mat
.
DataPointer
,
videoFrame
.
DataStream
.
DataPointer
.
ToPointer
(),
videoFrame
.
Length
,
videoFrame
.
Length
);
...
...
VIZ.Framework.Common/VideoControl/Stream/VideoFrameBase.cs
View file @
6c799b94
...
...
@@ -62,11 +62,6 @@ namespace VIZ.Framework.Common
public
long
TimeStamp
{
get
;
set
;
}
/// <summary>
/// 是否是最后一帧
/// </summary>
public
bool
IsEnd
{
get
;
set
;
}
/// <summary>
/// 画面数据
/// </summary>
public
DataStream
DataStream
{
get
;
set
;
}
...
...
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