Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
2ea0fac0
提交
2ea0fac0
authored
2月 27, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
motion detect: new alg
上级
4a093a7a
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
74 行增加
和
78 行删除
+74
-78
evmlmotion.cpp
opencv-motion-detect/evmlmotion.cpp
+74
-78
没有找到文件。
opencv-motion-detect/evmlmotion.cpp
浏览文件 @
2ea0fac0
...
@@ -85,6 +85,8 @@ private:
...
@@ -85,6 +85,8 @@ private:
long
long
packetTsDelta
=
0
;
long
long
packetTsDelta
=
0
;
float
pps
=
0
,
imgScalor
=
1
;
float
pps
=
0
,
imgScalor
=
1
;
int
pktLag
=
0
;
int
pktLag
=
0
;
int
fps
=
18
;
uint64_t
pktCnt
=
0
;
//
//
int
handleCloudMsg
(
vector
<
vector
<
uint8_t
>
>
v
)
int
handleCloudMsg
(
vector
<
vector
<
uint8_t
>
>
v
)
...
@@ -520,6 +522,9 @@ private:
...
@@ -520,6 +522,9 @@ private:
return
response
;
return
response
;
}
}
static
long
long
called
=
0
;
static
int
factor
=
0
;
while
(
response
>=
0
)
{
while
(
response
>=
0
)
{
response
=
avcodec_receive_frame
(
pCodecContext
,
pFrame
);
response
=
avcodec_receive_frame
(
pCodecContext
,
pFrame
);
if
(
response
==
AVERROR
(
EAGAIN
)
||
response
==
AVERROR_EOF
)
{
if
(
response
==
AVERROR
(
EAGAIN
)
||
response
==
AVERROR_EOF
)
{
...
@@ -540,46 +545,25 @@ private:
...
@@ -540,46 +545,25 @@ private:
pFrame
->
key_frame
,
pFrame
->
key_frame
,
pFrame
->
coded_picture_number
pFrame
->
coded_picture_number
);
);
break
;
}
}
static
long
long
called
=
0
;
bool
proc
=
false
;
static
int
factor
=
0
;
if
(
pktCnt
%
(
this
->
fps
/
detPara
.
fpsProc
+
1
)
==
0
)
{
called
++
;
proc
=
true
;
bool
proc
=
true
;
}
if
(
this
->
pps
!=
0
&&
factor
==
0
)
{
// lock the value
factor
=
int
(
int
(
this
->
pps
)
/
this
->
detPara
.
fpsProc
);
// regulator to 0 if it was set inresonably high
if
(
factor
>
8
)
{
factor
=
8
;
}
}
if
(
factor
!=
0
)
{
if
(
called
%
factor
==
0
)
{
proc
=
true
;
//factor = 0; // reset it open to change
}
else
{
proc
=
false
;
}
}
if
(
!
proc
)
{
if
(
this
->
pps
!=
0
&&
(
called
%
180
)
==
0
)
{
spdlog
::
info
(
"{} pps {}, fpsFactor {}, called {}, lag {}, skip processing"
,
this
->
selfId
,
this
->
pps
,
factor
,
called
,
this
->
pktLag
);
}
// detectMotion(pCodecContext->pix_fmt, pFrame, false);
}
else
{
if
((
called
%
(
180
*
4
))
==
0
)
{
spdlog
::
info
(
"{} pps {}, fpsFactor {}, called {}, lag {}"
,
this
->
selfId
,
this
->
pps
,
factor
,
called
,
this
->
pktLag
);
}
detectMotion
(
pCodecContext
->
pix_fmt
,
pFrame
,
detect
);
factor
=
0
;
// refresh to latest value
}
break
;
if
(
!
proc
)
{
if
(
pktCnt
%
18
==
0
)
spdlog
::
info
(
"{} pps {}, lag {}, skip processing"
,
this
->
selfId
,
this
->
pps
,
this
->
pktLag
);
}
else
{
if
(
detect
)
{
detectMotion
(
pCodecContext
->
pix_fmt
,
pFrame
,
detect
);
}
}
}
}
return
0
;
return
0
;
}
}
...
@@ -651,7 +635,7 @@ private:
...
@@ -651,7 +635,7 @@ private:
}
}
cv
::
threshold
(
thresh
,
gray
,
detPara
.
thre
,
255
,
cv
::
THRESH_BINARY
);
cv
::
threshold
(
thresh
,
gray
,
detPara
.
thre
,
255
,
cv
::
THRESH_BINARY
);
cv
::
dilate
(
gray
,
thresh
,
cv
::
Mat
(),
cv
::
Point
(
-
1
,
-
1
),
2
);
//
cv::dilate(gray, thresh, cv::Mat(), cv::Point(-1,-1), 2);
#ifdef DEBUG
#ifdef DEBUG
matShow1
=
thresh
.
clone
();
matShow1
=
thresh
.
clone
();
...
@@ -686,10 +670,7 @@ private:
...
@@ -686,10 +670,7 @@ private:
// business logic for event
// business logic for event
// auto dura = chrono::duration_cast<chrono::seconds>(packetTm - evtStartTmLast).count();
// auto dura = chrono::duration_cast<chrono::seconds>(packetTm - evtStartTmLast).count();
if
(
hasEvent
){
evtStartTmLast
=
packetTm
;
}
long
long
dura
=
0
;
long
long
dura
=
0
;
if
(
evtStartTmLast
!=
0
)
{
if
(
evtStartTmLast
!=
0
)
{
dura
=
packetTm
-
evtStartTmLast
;
dura
=
packetTm
-
evtStartTmLast
;
...
@@ -700,73 +681,64 @@ private:
...
@@ -700,73 +681,64 @@ private:
if
(
hasEvent
)
{
if
(
hasEvent
)
{
evtState
=
PRE
;
evtState
=
PRE
;
spdlog
::
info
(
"{} state: NONE->PRE ({}, {})"
,
selfId
,
dura
,
evtCnt
);
spdlog
::
info
(
"{} state: NONE->PRE ({}, {})"
,
selfId
,
dura
,
evtCnt
);
evtCnt
=
0
;
evtStartTmOrig
=
packetTm
;
evtStartTmOrig
=
packetTm
;
evtStartTmLast
=
packetTm
;
}
}
break
;
break
;
}
}
case
PRE
:
{
case
PRE
:
{
if
(
hasEvent
)
{
if
(
dura
>=
detPara
.
pre
)
{
if
(
dura
>
detPara
.
pre
/*&& evtCnt < detPara.pre*/
)
{
if
(
evtCnt
<
detPara
.
fpsProc
*
dura
/
2
)
{
spdlog
::
info
(
"state: PRE->
PR
E ({}, {})"
,
dura
,
evtCnt
);
spdlog
::
info
(
"state: PRE->
NON
E ({}, {})"
,
dura
,
evtCnt
);
evtState
=
PR
E
;
evtState
=
NON
E
;
evtStartTmOrig
=
packetTm
;
evtStartTmOrig
=
packetTm
;
evtCnt
=
0
;
}
else
{
}
else
if
(
true
/*dura > detPara.pre && evtCnt >= detPara.pre*/
)
{
evtState
=
IN
;
evtState
=
IN
;
json
p
;
json
p
;
spdlog
::
info
(
"{} state: PRE->IN ({}, {})"
,
selfId
,
dura
,
evtCnt
);
spdlog
::
info
(
"{} state: PRE->IN ({}, {})"
,
selfId
,
dura
,
evtCnt
);
evtCnt
=
0
;
makeEvent
(
EV_MSG_EVENT_MOTION_START
,
evtStartTmOrig
);
makeEvent
(
EV_MSG_EVENT_MOTION_START
,
evtStartTmOrig
);
auto
tmp
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
auto
tmp
=
chrono
::
duration_cast
<
chrono
::
seconds
>
(
chrono
::
system_clock
::
now
().
time_since_epoch
()).
count
();
packetTsDelta
=
tmp
-
packetTm
;
packetTsDelta
=
tmp
-
packetTm
;
spdlog
::
info
(
"{} packet ts delta: {}"
,
selfId
,
packetTsDelta
);
spdlog
::
info
(
"{} packet ts delta: {}"
,
selfId
,
packetTsDelta
);
}
}
}
evtCnt
=
0
;
else
{
evtStartTmLast
=
packetTm
;
if
(
dura
>
detPara
.
pre
)
{
evtState
=
NONE
;
spdlog
::
info
(
"{} state: PRE->NONE ({}, {})"
,
selfId
,
dura
,
evtCnt
);
evtCnt
=
0
;
}
}
}
break
;
break
;
}
}
case
IN
:
{
case
IN
:
{
if
(
!
hasEvent
)
{
if
(
packetTm
-
evtStartTmOrig
>
60
*
detPara
.
maxDuration
)
{
if
(
dura
>
(
int
)(
detPara
.
post
/
2
))
{
evtStartTmOrig
=
packetTm
;
makeEvent
(
EV_MSG_EVENT_MOTION_END
,
packetTs
);
makeEvent
(
EV_MSG_EVENT_MOTION_START
,
packetTs
);
spdlog
::
warn
(
"{} event video continued over {} minutes, force segmenting and continue"
,
devSn
,
detPara
.
maxDuration
);
spdlog
::
debug
(
"{} state: IN->IN ({}, {})"
,
selfId
,
dura
,
evtCnt
);
evtCnt
=
0
;
evtStartTmLast
=
packetTm
;
}
else
if
(
dura
>=
detPara
.
post
/
2
){
if
(
evtCnt
<
detPara
.
fpsProc
*
dura
/
5
){
evtState
=
POST
;
evtState
=
POST
;
spdlog
::
info
(
"{} state: IN->POST ({}, {})"
,
selfId
,
dura
,
evtCnt
);
spdlog
::
info
(
"{} state: IN->POST ({}, {})"
,
selfId
,
dura
,
evtCnt
);
evtCnt
=
0
;
}
else
{
}
spdlog
::
debug
(
"{} state: IN->IN ({}, {})"
,
selfId
,
dura
,
evtCnt
);
}
else
{
if
(
(
packetTm
-
evtStartTmOrig
)
>
(
60
*
detPara
.
maxDuration
)
)
{
evtStartTmOrig
=
packetTm
;
makeEvent
(
EV_MSG_EVENT_MOTION_END
,
packetTs
);
evtCnt
=
0
;
makeEvent
(
EV_MSG_EVENT_MOTION_START
,
packetTs
);
spdlog
::
warn
(
"{} event video continued over {} minutes, force segmenting and continue"
,
devSn
,
detPara
.
maxDuration
);
}
}
spdlog
::
debug
(
"{} state: IN->IN ({}, {})"
,
selfId
,
dura
,
evtCnt
);
evtCnt
=
0
;
evtCnt
=
0
;
evtStartTmLast
=
packetTm
;
}
}
break
;
break
;
}
}
case
POST
:
{
case
POST
:
{
if
(
!
hasEvent
)
{
if
(
dura
>=
detPara
.
post
/
2
)
{
if
(
dura
>
detPara
.
post
)
{
if
(
evtCnt
<
detPara
.
fpsProc
*
dura
/
5
)
{
spdlog
::
info
(
"state: POST->NONE ({}, {})"
,
dura
,
evtCnt
);
spdlog
::
info
(
"state: POST->NONE ({}, {})"
,
dura
,
evtCnt
);
evtState
=
NONE
;
evtState
=
NONE
;
evtCnt
=
0
;
makeEvent
(
EV_MSG_EVENT_MOTION_END
,
packetTs
);
makeEvent
(
EV_MSG_EVENT_MOTION_END
,
packetTs
);
}
else
{
spdlog
::
info
(
"state: POST->IN ({}, {})"
,
dura
,
evtCnt
);
evtState
=
IN
;
}
}
}
else
{
spdlog
::
info
(
"state: POST->IN ({}, {})"
,
dura
,
evtCnt
);
evtState
=
IN
;
evtCnt
=
0
;
evtCnt
=
0
;
evtStartTmLast
=
packetTm
;
}
}
break
;
break
;
}
}
...
@@ -777,7 +749,6 @@ protected:
...
@@ -777,7 +749,6 @@ protected:
void
run
()
void
run
()
{
{
bool
bStopSig
=
false
;
bool
bStopSig
=
false
;
uint64_t
pktCnt
=
0
;
zmq_msg_t
msg
;
zmq_msg_t
msg
;
AVPacket
packet
;
AVPacket
packet
;
json
eventToSlicer
;
json
eventToSlicer
;
...
@@ -877,6 +848,31 @@ protected:
...
@@ -877,6 +848,31 @@ protected:
}
}
}
}
zmq_msg_close
(
&
msg
);
zmq_msg_close
(
&
msg
);
static
int
_fpsDetectCnt
=
0
;
static
auto
_pts
=
packet
.
pts
;
if
(
pAVFormatInput
->
streams
[
packet
.
stream_index
]
->
codecpar
->
codec_type
==
AVMEDIA_TYPE_VIDEO
){
static
auto
num
=
pAVFormatInput
->
streams
[
packet
.
stream_index
]
->
time_base
.
num
;
static
auto
den
=
pAVFormatInput
->
streams
[
packet
.
stream_index
]
->
time_base
.
den
;
_fpsDetectCnt
++
;
if
(
_fpsDetectCnt
<
20
){
if
(
_fpsDetectCnt
==
1
)
{
_pts
=
packet
.
pts
;
}
}
else
{
_pts
=
packet
.
pts
-
_pts
;
auto
ts
=
_pts
*
1.0
*
num
/
den
;
this
->
fps
=
int
(
20
/
ts
);
if
(
this
->
fps
<=
5
)
{
this
->
fps
=
18
;
}
spdlog
::
info
(
"{} calc fps in 20 frame: ts: {}, fps: {}"
,
selfId
,
ts
,
this
->
fps
);
_fpsDetectCnt
=
0
;
_pts
=
packet
.
pts
;
}
}
if
(
pktCnt
%
EV_LOG_PACKET_CNT
==
0
)
{
if
(
pktCnt
%
EV_LOG_PACKET_CNT
==
0
)
{
spdlog
::
info
(
"{} seq: {}, pts: {}, dts: {}, idx: {}"
,
selfId
,
pktCnt
,
packet
.
pts
,
packet
.
dts
,
packet
.
stream_index
);
spdlog
::
info
(
"{} seq: {}, pts: {}, dts: {}, idx: {}"
,
selfId
,
pktCnt
,
packet
.
pts
,
packet
.
dts
,
packet
.
stream_index
);
}
}
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论