Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
c77153b0
提交
c77153b0
authored
8月 19, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
init
上级
377d0ee2
隐藏空白字符变更
内嵌
并排
正在显示
2 个修改的文件
包含
94 行增加
和
12 行删除
+94
-12
database.cpp
opencv-motion-detect/database.cpp
+5
-5
evmlmotion.cpp
opencv-motion-detect/evmlmotion.cpp
+89
-7
没有找到文件。
opencv-motion-detect/database.cpp
浏览文件 @
c77153b0
...
@@ -203,11 +203,11 @@ namespace DB {
...
@@ -203,11 +203,11 @@ namespace DB {
// ipc: id, user, passwd, addr, status
// ipc: id, user, passwd, addr, status
// ex: 1, admin, FWBWTU, 172.31.0.51, 0
// ex: 1, admin, FWBWTU, 172.31.0.51, 0
// evmgr: iid integer, cid <id_of_ipc>, addr text, status
// evmgr: iid integer,
sn,
cid <id_of_ipc>, addr text, status
// evpuller: iid, cid <id_of_ipc>, addr, pub, rep, status;
// evpuller: iid,
sn,
cid <id_of_ipc>, addr, pub, rep, status;
// evpusher: iid, pid <id_of_puller>, urldest, enabled, status;
// evpusher: iid,
sn,
pid <id_of_puller>, urldest, enabled, status;
// evslicer: iid, pid, urldest, days, miniutes, status;
// evslicer: iid,
sn,
pid, urldest, days, miniutes, status;
// evml:
iid
, pid, cls, enabled, status
// evml:
iid, sn
, pid, cls, enabled, status
//
//
//
//
...
...
opencv-motion-detect/evmlmotion.cpp
浏览文件 @
c77153b0
...
@@ -23,6 +23,12 @@ namespace fs = std::filesystem;
...
@@ -23,6 +23,12 @@ namespace fs = std::filesystem;
using
namespace
std
;
using
namespace
std
;
#define URLOUT_DEFAULT "frames"
#define URLOUT_DEFAULT "frames"
#define DEBUG
#ifdef DEBUG
// TODO: remove me
cv
::
Mat
matShow1
,
matShow2
,
matShow3
;
#endif
class
EvMLMotion
:
public
TinyThread
{
class
EvMLMotion
:
public
TinyThread
{
private
:
private
:
...
@@ -248,7 +254,8 @@ private:
...
@@ -248,7 +254,8 @@ private:
if
(
response
<
0
)
{
if
(
response
<
0
)
{
spdlog
::
error
(
"Error while receiving a frame from the decoder: {}"
,
av_err2str
(
response
));
spdlog
::
error
(
"Error while receiving a frame from the decoder: {}"
,
av_err2str
(
response
));
return
response
;
return
response
;
}
else
{
}
else
{
spdlog
::
info
(
spdlog
::
info
(
"Frame {} (type={}, size={} bytes) pts {} key_frame {} [DTS {}]"
,
"Frame {} (type={}, size={} bytes) pts {} key_frame {} [DTS {}]"
,
pCodecContext
->
frame_number
,
pCodecContext
->
frame_number
,
...
@@ -259,19 +266,71 @@ private:
...
@@ -259,19 +266,71 @@ private:
pFrame
->
coded_picture_number
pFrame
->
coded_picture_number
);
);
// save a grayscale frame into a .pgm file
// save a grayscale frame into a .pgm file
// string name = urlOut + "/"+ to_string(chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count()) + ".pgm";
// string name = urlOut + "/"+ to_string(chrono::duration_cast<chrono::seconds>(chrono::system_clock::now().time_since_epoch()).count()) + ".pgm";
detectMotion
(
pFrame
);
detectMotion
(
p
CodecContext
->
pix_fmt
,
p
Frame
);
}
}
spdlog
::
debug
(
"ch4"
);
spdlog
::
debug
(
"ch4"
);
}
}
return
0
;
return
0
;
}
}
void
detectMotion
(
AVFrame
*
pFrame
)
void
detectMotion
(
AV
PixelFormat
format
,
AV
Frame
*
pFrame
)
{
{
static
bool
first
=
true
;
static
cv
::
Mat
avg
;
static
vector
<
vector
<
cv
::
Point
>
>
cnts
;
cv
::
Mat
origin
,
gray
,
thresh
;
avcvhelpers
::
frame2mat
(
format
,
pFrame
,
origin
);
cv
::
resize
(
origin
,
gray
,
cv
::
Size
(
500
,
500
));
cv
::
cvtColor
(
gray
,
thresh
,
cv
::
COLOR_BGR2GRAY
);
cv
::
GaussianBlur
(
thresh
,
gray
,
cv
::
Size
(
21
,
21
),
cv
::
THRESH_BINARY
);
if
(
first
)
{
// avg = cv::Mat::zeros(gray.size(), CV_32FC3);
avg
=
gray
.
clone
();
first
=
false
;
return
;
}
#ifdef DEBUG
matShow3
=
gray
.
clone
();
#endif
// TODO: AVG
// cv::accumulateWeighted(gray, avg, 0.5);
cv
::
absdiff
(
gray
,
avg
,
thresh
);
#ifdef DEBUG
avg
=
gray
.
clone
();
#endif
// TODO:
cv
::
threshold
(
thresh
,
gray
,
25
,
255
,
cv
::
THRESH_BINARY
);
cv
::
dilate
(
gray
,
thresh
,
cv
::
Mat
(),
cv
::
Point
(
-
1
,
-
1
),
2
);
#ifdef DEBUG
matShow1
=
thresh
.
clone
();
#endif
cv
::
findContours
(
thresh
,
cnts
,
cv
::
RETR_EXTERNAL
,
cv
::
CHAIN_APPROX_SIMPLE
);
bool
hasEvent
=
false
;
for
(
int
i
=
0
;
i
<
cnts
.
size
();
i
++
)
{
// TODO:
if
(
cv
::
contourArea
(
cnts
[
i
])
<
200
)
{
// nothing
}
else
{
hasEvent
=
true
;
#ifdef DEBUG
cv
::
putText
(
origin
,
"motion detected"
,
cv
::
Point
(
10
,
20
),
cv
::
FONT_HERSHEY_SIMPLEX
,
0.75
,
cv
::
Scalar
(
0
,
0
,
255
),
2
);
#endif
break
;
}
}
#ifdef DEBUG
matShow2
=
origin
;
#endif
}
}
protected
:
protected
:
void
run
()
void
run
()
...
@@ -316,17 +375,20 @@ protected:
...
@@ -316,17 +375,20 @@ protected:
if
(
packet
.
stream_index
==
streamIdx
)
{
if
(
packet
.
stream_index
==
streamIdx
)
{
spdlog
::
debug
(
"AVPacket.pts {}"
,
packet
.
pts
);
spdlog
::
debug
(
"AVPacket.pts {}"
,
packet
.
pts
);
// TODO
if
(
pktCnt
<
18
*
5
)
{
continue
;
}
ret
=
decode_packet
(
&
packet
,
pCodecCtx
,
pFrame
);
ret
=
decode_packet
(
&
packet
,
pCodecCtx
,
pFrame
);
if
(
ret
<
0
)
break
;
}
}
av_frame_free
(
&
pFrame
);
av_packet_unref
(
&
packet
);
av_packet_unref
(
&
packet
);
if
(
ret
<
0
)
{
if
(
ret
<
0
)
{
spdlog
::
error
(
"error muxing packet"
);
spdlog
::
error
(
"error muxing packet"
);
}
}
}
}
av_frame_free
(
&
pFrame
);
}
}
public
:
public
:
EvMLMotion
()
EvMLMotion
()
...
@@ -342,6 +404,25 @@ int main(int argc, const char *argv[])
...
@@ -342,6 +404,25 @@ int main(int argc, const char *argv[])
{
{
spdlog
::
set_level
(
spdlog
::
level
::
debug
);
spdlog
::
set_level
(
spdlog
::
level
::
debug
);
EvMLMotion
es
;
EvMLMotion
es
;
#ifdef DEBUG
// TODO: remove
cv
::
namedWindow
(
"Display window"
,
cv
::
WINDOW_AUTOSIZE
);
es
.
detach
();
// TODO: remove me
this_thread
::
sleep_for
(
chrono
::
seconds
(
5
));
while
(
true
)
{
cv
::
imshow
(
"evmlmotion1"
,
matShow1
);
cv
::
imshow
(
"evmlmotion2"
,
matShow2
);
cv
::
imshow
(
"evmlmotion3"
,
matShow3
);
if
(
cv
::
waitKey
(
200
)
==
27
)
{
break
;
}
}
#else
es
.
join
();
es
.
join
();
#endif
return
0
;
return
0
;
}
}
\ No newline at end of file
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论