Skip to content
项目
群组
代码片段
帮助
正在加载...
登录
切换导航
E
evsuits
项目
项目
详情
活动
周期分析
仓库
仓库
文件
提交
分支
标签
贡献者
分枝图
比较
统计图
议题
0
议题
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
CI / CD
CI / CD
流水线
作业
日程
统计图
Wiki
Wiki
代码片段
代码片段
成员
成员
折叠边栏
关闭边栏
活动
分枝图
统计图
创建新议题
作业
提交
议题看板
打开侧边栏
OpsTeam
evsuits
Commits
1d6152aa
提交
1d6152aa
authored
12月 18, 2019
作者:
blu
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
yolo
上级
ef4edde0
隐藏空白字符变更
内嵌
并排
正在显示
1 个修改的文件
包含
27 行增加
和
35 行删除
+27
-35
main.cpp
opencv-yolo/main.cpp
+27
-35
没有找到文件。
opencv-yolo/main.cpp
浏览文件 @
1d6152aa
...
@@ -19,16 +19,6 @@ using namespace cv;
...
@@ -19,16 +19,6 @@ using namespace cv;
using
namespace
dnn
;
using
namespace
dnn
;
using
namespace
std
;
using
namespace
std
;
// Remove the bounding boxes with low confidence using non-maxima suppression
int
postprocess
(
Mat
&
frame
,
const
vector
<
Mat
>&
out
);
// Draw the predicted bounding box
void
drawPred
(
int
classId
,
float
conf
,
int
left
,
int
top
,
int
right
,
int
bottom
,
Mat
&
frame
);
// Get the names of the output layers
vector
<
String
>
getOutputsNames
(
const
Net
&
net
);
class
YoloDectect
{
class
YoloDectect
{
private
:
private
:
// Initialize the parameters
// Initialize the parameters
...
@@ -138,7 +128,7 @@ protected:
...
@@ -138,7 +128,7 @@ protected:
//
//
public
:
public
:
typedef
int
(
*
callback
)(
vector
<
tuple
<
string
,
double
,
Rect
>>
,
Mat
);
typedef
int
(
*
callback
)(
vector
<
tuple
<
string
,
double
,
Rect
>>
&
,
Mat
);
YoloDectect
(
string
path
=
""
)
YoloDectect
(
string
path
=
""
)
{
{
if
(
path
.
empty
())
{
if
(
path
.
empty
())
{
...
@@ -198,13 +188,17 @@ public:
...
@@ -198,13 +188,17 @@ public:
return
ret
;
return
ret
;
}
}
int
process
(
string
inVideoUri
,
string
outFile
=
"processed.jpg"
,
callback
cb
=
nullptr
)
int
process
(
string
inVideoUri
,
callback
cb
=
nullptr
,
string
outFile
=
"processed.jpg"
)
{
{
if
(
inVideoUri
.
empty
())
{
if
(
inVideoUri
.
empty
())
{
inVideoUri
=
"0"
;
inVideoUri
=
"0"
;
}
}
if
(
!
cap
.
open
(
inVideoUri
))
{
spdlog
::
error
(
"{} failed to open input video {}"
,
selfId
,
inVideoUri
);
return
-
1
;
}
ghc
::
filesystem
::
path
p
(
outFile
);
ghc
::
filesystem
::
path
p
(
outFile
);
auto
dir
=
p
.
parent_path
();
auto
dir
=
p
.
parent_path
();
...
@@ -216,16 +210,11 @@ public:
...
@@ -216,16 +210,11 @@ public:
else
{
else
{
bOutputIsImg
=
false
;
bOutputIsImg
=
false
;
if
(
!
video
.
open
(
outFile
,
VideoWriter
::
fourcc
(
'M'
,
'J'
,
'P'
,
'G'
),
28
,
Size
(
cap
.
get
(
CAP_PROP_FRAME_WIDTH
),
cap
.
get
(
CAP_PROP_FRAME_HEIGHT
))))
{
if
(
!
video
.
open
(
outFile
,
VideoWriter
::
fourcc
(
'M'
,
'J'
,
'P'
,
'G'
),
28
,
Size
(
cap
.
get
(
CAP_PROP_FRAME_WIDTH
),
cap
.
get
(
CAP_PROP_FRAME_HEIGHT
))))
{
spdlog
::
error
(
"{} failed to open output video {}"
,
selfId
,
inVideoUri
);
spdlog
::
error
(
"{} failed to open output video {}"
,
selfId
,
outFile
);
return
-
1
;
return
-
1
;
}
}
}
}
if
(
!
cap
.
open
(
inVideoUri
))
{
spdlog
::
error
(
"{} failed to open input video {}"
,
selfId
,
inVideoUri
);
return
-
1
;
}
spdlog
::
info
(
"{} try to process video {} to {}"
,
selfId
,
inVideoUri
,
outFile
);
spdlog
::
info
(
"{} try to process video {} to {}"
,
selfId
,
inVideoUri
,
outFile
);
long
frameCnt
=
0
;
long
frameCnt
=
0
;
...
@@ -250,24 +239,27 @@ public:
...
@@ -250,24 +239,27 @@ public:
}
}
vector
<
tuple
<
string
,
double
,
Rect
>>
ret
=
process
(
frame
,
outFrame
);
vector
<
tuple
<
string
,
double
,
Rect
>>
ret
=
process
(
frame
,
outFrame
);
if
(
ret
.
size
()
==
0
&&
bOutputIsImg
)
{
if
(
cb
==
nullptr
)
{
// no detection
if
(
ret
.
size
()
==
0
&&
bOutputIsImg
)
{
if
(
skipCnt
%
100
==
0
)
{
// no detection
spdlog
::
info
(
"{} no valid object detected skipped frame count {}"
,
selfId
,
skipCnt
);
if
(
skipCnt
%
100
==
0
)
{
spdlog
::
info
(
"{} no valid object detected skipped frame count {}"
,
selfId
,
skipCnt
);
}
skipCnt
++
;
continue
;
}
}
skipCnt
++
;
continue
;
}
if
(
bOutputIsImg
)
{
if
(
bOutputIsImg
)
{
string
ofname
=
outFileBase
+
to_string
(
detCnt
)
+
".jpg"
;
string
ofname
=
outFileBase
+
to_string
(
detCnt
)
+
".jpg"
;
imwrite
(
ofname
,
outFrame
);
imwrite
(
ofname
,
outFrame
);
detCnt
++
;
detCnt
++
;
}
}
else
{
else
{
video
.
write
(
outFrame
);
video
.
write
(
outFrame
);
}
}
else
{
cb
(
ret
,
outFrame
);
}
}
}
}
cap
.
release
();
cap
.
release
();
...
@@ -280,7 +272,7 @@ public:
...
@@ -280,7 +272,7 @@ public:
int
main
(
int
argc
,
char
**
argv
)
int
main
(
int
argc
,
char
**
argv
)
{
{
YoloDectect
det
;
YoloDectect
det
;
det
.
process
(
"rtsp://admin:ZQEAAI@192.168.0.101:554/h264/ch1/main/av_stream"
);
det
.
process
(
"rtsp://admin:ZQEAAI@192.168.0.101:554/h264/ch1/main/av_stream"
,
"a.avi"
);
return
0
;
return
0
;
}
}
编写
预览
Markdown
格式
0%
重试
或
添加新文件
添加附件
取消
您添加了
0
人
到此讨论。请谨慎行事。
请先完成此评论的编辑!
取消
请
注册
或者
登录
后发表评论