Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
d18c5334
提交
d18c5334
authored
12月 23, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
revert to non-object-detection
上级
9da62c6e
全部展开
显示空白字符变更
内嵌
并排
正在显示
3 个修改的文件
包含
10 行增加
和
47 行删除
+10
-47
evmlmotion.cpp
opencv-motion-detect/evmlmotion.cpp
+0
-21
yolo.hpp
opencv-motion-detect/yolo.hpp
+0
-0
main.cpp
opencv-yolo/main.cpp
+10
-26
没有找到文件。
opencv-motion-detect/evmlmotion.cpp
浏览文件 @
d18c5334
...
...
@@ -23,7 +23,6 @@ update: 2019/09/10
#include "common.hpp"
#include "avcvhelpers.hpp"
#include "database.h"
#include "yolo.hpp"
using
namespace
std
;
using
namespace
zmqhelper
;
...
...
@@ -82,7 +81,6 @@ private:
long
long
packetTsDelta
=
0
;
float
pps
=
0
;
int
pktLag
=
0
;
unique_ptr
<
YoloDectect
>
pYolo
=
nullptr
;
//
int
handleCloudMsg
(
vector
<
vector
<
uint8_t
>
>
v
)
...
...
@@ -360,9 +358,6 @@ private:
}
//ping
ret
=
ping
();
//
pYolo
=
unique_ptr
<
YoloDectect
>
(
new
YoloDectect
(
"../opencv-yolo"
));
}
catch
(
exception
&
e
)
{
spdlog
::
error
(
"evmlmotion {} exception in EvPuller.init {:s} retrying"
,
selfId
,
e
.
what
());
...
...
@@ -564,26 +559,10 @@ private:
void
detectMotion
(
AVPixelFormat
format
,
AVFrame
*
pFrame
,
bool
detect
=
true
)
{
static
bool
first
=
true
;
static
unsigned
long
detCnt
=
0
;
static
cv
::
Mat
avg
;
static
vector
<
vector
<
cv
::
Point
>
>
cnts
;
cv
::
Mat
origin
,
gray
,
thresh
;
avcvhelpers
::
frame2mat
(
format
,
pFrame
,
origin
);
if
(
detCnt
%
6
==
0
)
{
auto
objDetRes
=
pYolo
->
process
(
origin
,
nullptr
);
if
(
objDetRes
.
size
()
>
0
)
{
string
s
=
fmt
::
format
(
"{} {} object detected:
\n
"
,
selfId
,
objDetRes
.
size
());
int
i
=
0
;
for
(
auto
&
[
n
,
c
,
_
]
:
objDetRes
)
{
i
++
;
s
+=
fmt
::
format
(
"
\t\t
obj {}:{}, prob: {}, x:{}, y:{}, w: {}, h:{}
\n
"
,
i
,
n
,
c
,
_
.
x
,
_
.
y
,
_
.
width
,
_
.
height
);
}
spdlog
::
info
(
s
);
}
}
detCnt
++
;
cv
::
resize
(
origin
,
gray
,
cv
::
Size
(
FRAME_SIZE
,
FRAME_SIZE
));
cv
::
cvtColor
(
gray
,
thresh
,
cv
::
COLOR_BGR2GRAY
);
float
fent
=
avcvhelpers
::
getEntropy
(
thresh
);
...
...
opencv-motion-detect/yolo.hpp
deleted
100644 → 0
浏览文件 @
9da62c6e
差异被折叠。
点击展开。
opencv-yolo/main.cpp
浏览文件 @
d18c5334
...
...
@@ -35,9 +35,6 @@ private:
bool
bOutputIsImg
=
false
;
string
outFileBase
;
bool
cmdStop
=
false
;
unsigned
int
wrapNum
=
0
;
unsigned
long
numFrameProcessed
=
0
;
unsigned
int
numLogSkip
=
0
;
// Get the names of the output layers
vector
<
String
>
getOutputsNames
(
const
Net
&
net
)
...
...
@@ -80,7 +77,7 @@ private:
}
// post process
vector
<
tuple
<
string
,
double
,
Rect
>>
postprocess
(
Mat
&
frame
,
const
vector
<
Mat
>&
outs
,
bool
bModify
=
true
)
vector
<
tuple
<
string
,
double
,
Rect
>>
postprocess
(
Mat
&
frame
,
const
vector
<
Mat
>&
outs
)
{
vector
<
int
>
classIds
;
vector
<
float
>
confidences
;
...
...
@@ -120,7 +117,6 @@ private:
int
idx
=
indices
[
i
];
Rect
box
=
boxes
[
idx
];
ret
.
push_back
(
tuple
<
string
,
double
,
Rect
>
(
classes
[
classIds
[
idx
]],
confidences
[
idx
],
box
));
if
(
bModify
)
drawPred
(
classIds
[
idx
],
confidences
[
idx
],
box
.
x
,
box
.
y
,
box
.
x
+
box
.
width
,
box
.
y
+
box
.
height
,
frame
);
}
...
...
@@ -133,15 +129,12 @@ protected:
//
public
:
typedef
int
(
*
callback
)(
vector
<
tuple
<
string
,
double
,
Rect
>>&
,
Mat
);
YoloDectect
(
string
path
=
""
,
unsigned
int
_wrapNum
=
10
,
unsigned
int
_numLogSkip
=
380
)
YoloDectect
(
string
path
=
""
)
{
if
(
path
.
empty
())
{
path
=
"."
;
}
wrapNum
=
_wrapNum
;
numLogSkip
=
_numLogSkip
;
// Load names of classes
string
classesFile
=
path
+
"/coco.names"
;
// Give the configuration and weight files for the model
...
...
@@ -166,7 +159,7 @@ public:
spdlog
::
info
(
"{} inited"
,
selfId
);
}
vector
<
tuple
<
string
,
double
,
Rect
>>
process
(
Mat
&
inFrame
,
Mat
*
pO
utFrame
)
vector
<
tuple
<
string
,
double
,
Rect
>>
process
(
Mat
&
inFrame
,
Mat
&
o
utFrame
)
{
if
(
inFrame
.
empty
())
{
return
vector
<
tuple
<
string
,
double
,
Rect
>>
();
...
...
@@ -183,20 +176,15 @@ public:
net
.
forward
(
outs
,
getOutputsNames
(
net
));
// Remove the bounding boxes with low confidence
auto
ret
=
postprocess
(
inFrame
,
outs
,
true
);
auto
ret
=
postprocess
(
inFrame
,
outs
);
// The function getPerfProfile returns the overall time for inference(t) and the timings for each of the layers(in layersTimes)
vector
<
double
>
layersTimes
;
if
(
numLogSkip
==
0
||
numFrameProcessed
%
numLogSkip
==
0
)
{
double
freq
=
getTickFrequency
()
/
1000
;
double
t
=
net
.
getPerfProfile
(
layersTimes
)
/
freq
;
spdlog
::
info
(
"{} infer time: {} ms"
,
selfId
,
t
);
}
if
(
pOutFrame
!=
nullptr
){
inFrame
.
convertTo
(
*
pOutFrame
,
CV_8U
);
}
numFrameProcessed
++
;
inFrame
.
convertTo
(
outFrame
,
CV_8U
)
;
return
ret
;
}
...
...
@@ -229,8 +217,8 @@ public:
spdlog
::
info
(
"{} try to process video {} to {}"
,
selfId
,
inVideoUri
,
outFile
);
unsigned
long
frameCnt
=
0
;
unsigned
long
detCnt
=
0
,
skipCnt
=
0
;
long
frameCnt
=
0
;
long
detCnt
=
0
,
skipCnt
=
0
;
Mat
frame
,
outFrame
;
while
(
waitKey
(
1
)
<
0
)
{
// get frame from the video
...
...
@@ -250,11 +238,11 @@ public:
continue
;
}
vector
<
tuple
<
string
,
double
,
Rect
>>
ret
=
process
(
frame
,
&
outFrame
);
vector
<
tuple
<
string
,
double
,
Rect
>>
ret
=
process
(
frame
,
outFrame
);
if
(
cb
==
nullptr
)
{
if
(
ret
.
size
()
==
0
&&
bOutputIsImg
)
{
// no detection
if
(
numLogSkip
==
0
||
skipCnt
%
numLogSkip
==
0
)
{
if
(
skipCnt
%
100
==
0
)
{
spdlog
::
info
(
"{} no valid object detected skipped frame count {}"
,
selfId
,
skipCnt
);
}
skipCnt
++
;
...
...
@@ -262,10 +250,6 @@ public:
}
if
(
bOutputIsImg
)
{
if
(
wrapNum
>
0
)
{
detCnt
=
detCnt
%
wrapNum
;
}
string
ofname
=
outFileBase
+
to_string
(
detCnt
)
+
".jpg"
;
imwrite
(
ofname
,
outFrame
);
detCnt
++
;
...
...
@@ -288,7 +272,7 @@ public:
int
main
(
int
argc
,
char
**
argv
)
{
YoloDectect
det
;
det
.
process
(
"rtsp://admin:ZQEAAI@192.168.0.101:554/h264/ch1/main/av_stream"
,
"a.
jpg
"
);
det
.
process
(
"rtsp://admin:ZQEAAI@192.168.0.101:554/h264/ch1/main/av_stream"
,
"a.
avi
"
);
return
0
;
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论