Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
8739ca71
提交
8739ca71
authored
1月 11, 2020
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
evml: crop image
上级
15a6e622
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
44 行增加
和
1 行删除
+44
-1
evmlmotion.cpp
opencv-motion-detect/evmlmotion.cpp
+44
-1
没有找到文件。
opencv-motion-detect/evmlmotion.cpp
浏览文件 @
8739ca71
...
@@ -47,6 +47,7 @@ struct DetectParam {
...
@@ -47,6 +47,7 @@ struct DetectParam {
int
post
;
int
post
;
float
entropy
;
float
entropy
;
int
maxDuration
;
// max event video length in minutes
int
maxDuration
;
// max event video length in minutes
cv
::
Point2f
region
[
2
];
};
};
enum
EventState
{
enum
EventState
{
...
@@ -64,7 +65,7 @@ private:
...
@@ -64,7 +65,7 @@ private:
int
iid
;
int
iid
;
AVFormatContext
*
pAVFormatInput
=
nullptr
;
AVFormatContext
*
pAVFormatInput
=
nullptr
;
AVCodecContext
*
pCodecCtx
=
nullptr
;
AVCodecContext
*
pCodecCtx
=
nullptr
;
DetectParam
detPara
=
{
25
,
500
,
-
1
,
3
,
3
,
30
,
0.3
,
25
};
DetectParam
detPara
=
{
25
,
500
,
-
1
,
3
,
3
,
30
,
0.3
,
25
,
{{
0
,
0
},{
0
,
0
}}
};
EventState
evtState
=
EventState
::
NONE
;
EventState
evtState
=
EventState
::
NONE
;
// chrono::system_clock::time_point packetTm, evtStartTmLast, evtStartTmOrig;
// chrono::system_clock::time_point packetTm, evtStartTmLast, evtStartTmOrig;
long
long
packetTm
=
0
,
evtStartTmLast
=
0
,
evtStartTmOrig
=
0
,
evtStartTmPre
=
0
;
long
long
packetTm
=
0
,
evtStartTmLast
=
0
,
evtStartTmOrig
=
0
,
evtStartTmPre
=
0
;
...
@@ -308,6 +309,34 @@ private:
...
@@ -308,6 +309,34 @@ private:
detPara
.
maxDuration
=
evmlmotion
[
"maxDuration"
];
detPara
.
maxDuration
=
evmlmotion
[
"maxDuration"
];
}
}
if
(
evmlmotion
.
count
(
"region"
)
==
0
||
!
evmlmotion
[
"maxDuration"
].
is_object
())
{
json
&
region
=
evmlmotion
[
"region"
];
if
((
region
.
count
(
"center"
)
==
0
||
!
region
[
"center"
].
is_array
())
||
(
region
.
count
(
"wh"
)
==
0
||!
region
[
"wh"
].
is_array
())){
spdlog
::
error
(
"evmlmotion {} invalid region config: format. ignored"
,
selfId
);
}
else
{
cv
::
Point2f
p1
,
p2
;
const
float
EVML_MARGIN_F
=
0.0001
;
try
{
p1
.
x
=
region
[
"center"
][
0
];
p1
.
y
=
region
[
"center"
][
1
];
p2
.
x
=
region
[
"wh"
][
0
];
p2
.
y
=
region
[
"wh"
][
1
];
if
((
p1
.
x
-
p2
.
x
/
2
)
<
EVML_MARGIN_F
||
(
p1
.
x
+
p2
.
x
/
2
)
>
(
1
-
EVML_MARGIN_F
)
||
(
p1
.
y
-
p2
.
y
/
2
)
<
EVML_MARGIN_F
||
(
p1
.
y
+
p2
.
y
/
2
)
>
(
1
-
EVML_MARGIN_F
))
{
spdlog
::
error
(
"evmlmotion {} invalid region config: valid exceeding. ignored"
,
selfId
);
}
else
{
detPara
.
region
[
0
]
=
p1
;
detPara
.
region
[
1
]
=
p2
;
}
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evmlmotion {} failed to parse regoin config: {}. ignored"
,
selfId
,
e
.
what
());
}
}
}
else
{
detPara
.
maxDuration
=
evmlmotion
[
"maxDuration"
];
}
spdlog
::
info
(
"evmlmotion {} detection params: entropy {}, area {}, thresh {}, fpsProc {}"
,
selfId
,
detPara
.
entropy
,
detPara
.
area
,
detPara
.
thre
,
detPara
.
fpsProc
);
spdlog
::
info
(
"evmlmotion {} detection params: entropy {}, area {}, thresh {}, fpsProc {}"
,
selfId
,
detPara
.
entropy
,
detPara
.
area
,
detPara
.
thre
,
detPara
.
fpsProc
);
// setup sub
// setup sub
...
@@ -567,6 +596,20 @@ private:
...
@@ -567,6 +596,20 @@ private:
static
vector
<
vector
<
cv
::
Point
>
>
cnts
;
static
vector
<
vector
<
cv
::
Point
>
>
cnts
;
cv
::
Mat
origin
,
gray
,
thresh
;
cv
::
Mat
origin
,
gray
,
thresh
;
avcvhelpers
::
frame2mat
(
format
,
pFrame
,
origin
);
avcvhelpers
::
frame2mat
(
format
,
pFrame
,
origin
);
// check region
if
(
detPara
.
region
[
0
].
x
==
0
)
{
// do nothing
}
else
{
// crop
auto
w
=
origin
.
size
().
width
;
auto
h
=
origin
.
size
().
height
;
auto
x
=
(
int
)(
w
*
(
detPara
.
region
[
0
].
x
-
detPara
.
region
[
1
].
x
/
2
));
auto
y
=
(
int
)(
h
*
(
detPara
.
region
[
0
].
y
-
detPara
.
region
[
1
].
y
/
2
));
w
=
w
*
detPara
.
region
[
1
].
x
;
h
=
h
*
detPara
.
region
[
1
].
y
;
cv
::
Rect
crop
(
x
,
y
,
w
,
h
);
origin
=
origin
(
crop
);
}
cv
::
resize
(
origin
,
gray
,
cv
::
Size
(
FRAME_SIZE
,
FRAME_SIZE
));
cv
::
resize
(
origin
,
gray
,
cv
::
Size
(
FRAME_SIZE
,
FRAME_SIZE
));
cv
::
cvtColor
(
gray
,
thresh
,
cv
::
COLOR_BGR2GRAY
);
cv
::
cvtColor
(
gray
,
thresh
,
cv
::
COLOR_BGR2GRAY
);
float
fent
=
avcvhelpers
::
getEntropy
(
thresh
);
float
fent
=
avcvhelpers
::
getEntropy
(
thresh
);
...
...
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论