Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Greenplum
Opencv
提交
8b222ac0
O
Opencv
项目概览
Greenplum
/
Opencv
10 个月 前同步成功
通知
7
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
O
Opencv
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8b222ac0
编写于
9月 06, 2016
作者:
M
Maksim Shabunin
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #7229 from catree:add_peopledetect_video_option
上级
a92aed45
aaa335b6
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
89 addition
and
27 deletion
+89
-27
samples/cpp/peopledetect.cpp
samples/cpp/peopledetect.cpp
+89
-27
未找到文件。
samples/cpp/peopledetect.cpp
浏览文件 @
8b222ac0
#include <iostream>
#include <stdexcept>
#include <opencv2/objdetect.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/video.hpp>
#include <opencv2/videoio.hpp>
using
namespace
cv
;
using
namespace
cv
;
using
namespace
std
;
using
namespace
std
;
static
void
help
()
{
cout
<<
"
\n
This program demonstrates the use of the HoG descriptor using
\n
"
" HOGDescriptor::hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
\n
"
"Usage:
\n
"
"./peopledetect --i=<image_filename> | --d=<image_directory>
\n\n
"
"During execution:
\n\t
Hit q or ESC key to quit.
\n
"
"
\t
Using OpenCV version "
<<
CV_VERSION
<<
"
\n
"
<<
endl
;
}
const
char
*
keys
=
const
char
*
keys
=
{
{
"{help h||}"
"{ help h | | print help message }"
"{image i| ../data/basketball2.png|input image name}"
"{ image i | | specify input image}"
"{directory d||images directory}"
"{ camera c | | enable camera capturing }"
"{ video v | ../data/768x576.avi | use video as input }"
"{ directory d | | images directory}"
};
};
static
void
detectAndDraw
(
const
HOGDescriptor
&
hog
,
Mat
&
img
)
static
void
detectAndDraw
(
const
HOGDescriptor
&
hog
,
Mat
&
img
)
...
@@ -69,7 +65,12 @@ int main(int argc, char** argv)
...
@@ -69,7 +65,12 @@ int main(int argc, char** argv)
if
(
parser
.
has
(
"help"
))
if
(
parser
.
has
(
"help"
))
{
{
help
();
cout
<<
"
\n
This program demonstrates the use of the HoG descriptor using
\n
"
" HOGDescriptor::hog.setSVMDetector(HOGDescriptor::getDefaultPeopleDetector());
\n
"
;
parser
.
printMessage
();
cout
<<
"During execution:
\n\t
Hit q or ESC key to quit.
\n
"
"
\t
Using OpenCV version "
<<
CV_VERSION
<<
"
\n
"
"Note: camera device number must be different from -1.
\n
"
<<
endl
;
return
0
;
return
0
;
}
}
...
@@ -78,6 +79,8 @@ int main(int argc, char** argv)
...
@@ -78,6 +79,8 @@ int main(int argc, char** argv)
namedWindow
(
"people detector"
,
1
);
namedWindow
(
"people detector"
,
1
);
string
pattern_glob
=
""
;
string
pattern_glob
=
""
;
string
video_filename
=
"../data/768x576.avi"
;
int
camera_id
=
-
1
;
if
(
parser
.
has
(
"directory"
))
if
(
parser
.
has
(
"directory"
))
{
{
pattern_glob
=
parser
.
get
<
string
>
(
"directory"
);
pattern_glob
=
parser
.
get
<
string
>
(
"directory"
);
...
@@ -86,26 +89,85 @@ int main(int argc, char** argv)
...
@@ -86,26 +89,85 @@ int main(int argc, char** argv)
{
{
pattern_glob
=
parser
.
get
<
string
>
(
"image"
);
pattern_glob
=
parser
.
get
<
string
>
(
"image"
);
}
}
else
if
(
parser
.
has
(
"camera"
))
{
camera_id
=
parser
.
get
<
int
>
(
"camera"
);
}
else
if
(
parser
.
has
(
"video"
))
{
video_filename
=
parser
.
get
<
string
>
(
"video"
);
}
if
(
!
pattern_glob
.
empty
())
if
(
!
pattern_glob
.
empty
()
||
camera_id
!=
-
1
||
!
video_filename
.
empty
()
)
{
{
//Read from input image files
vector
<
String
>
filenames
;
vector
<
String
>
filenames
;
String
folder
(
pattern_glob
);
//Read from video file
glob
(
folder
,
filenames
);
VideoCapture
vc
;
Mat
frame
;
for
(
vector
<
String
>::
const_iterator
it
=
filenames
.
begin
();
it
!=
filenames
.
end
();
++
it
)
if
(
!
pattern_glob
.
empty
()
)
{
{
cout
<<
"
\n
Read: "
<<
*
it
<<
endl
;
String
folder
(
pattern_glob
);
// Read current image
glob
(
folder
,
filenames
);
Mat
current_image
=
imread
(
*
it
);
}
else
if
(
camera_id
!=
-
1
)
{
vc
.
open
(
camera_id
);
if
(
!
vc
.
isOpened
())
{
stringstream
msg
;
msg
<<
"can't open camera: "
<<
camera_id
;
throw
runtime_error
(
msg
.
str
());
}
}
else
{
vc
.
open
(
video_filename
.
c_str
());
if
(
!
vc
.
isOpened
())
throw
runtime_error
(
string
(
"can't open video file: "
+
video_filename
));
}
vector
<
String
>::
const_iterator
it_image
=
filenames
.
begin
();
if
(
current_image
.
empty
())
for
(;;)
continue
;
{
if
(
!
pattern_glob
.
empty
())
{
bool
read_image_ok
=
false
;
for
(;
it_image
!=
filenames
.
end
();
++
it_image
)
{
cout
<<
"
\n
Read: "
<<
*
it_image
<<
endl
;
// Read current image
frame
=
imread
(
*
it_image
);
if
(
!
frame
.
empty
())
{
++
it_image
;
read_image_ok
=
true
;
break
;
}
}
//No more valid images
if
(
!
read_image_ok
)
{
//Release the image in order to exit the while loop
frame
.
release
();
}
}
else
{
vc
>>
frame
;
}
if
(
frame
.
empty
())
break
;
detectAndDraw
(
hog
,
current_imag
e
);
detectAndDraw
(
hog
,
fram
e
);
imshow
(
"people detector"
,
current_imag
e
);
imshow
(
"people detector"
,
fram
e
);
int
c
=
waitKey
(
0
)
&
255
;
int
c
=
waitKey
(
vc
.
isOpened
()
?
30
:
0
)
&
255
;
if
(
c
==
'q'
||
c
==
'Q'
||
c
==
27
)
if
(
c
==
'q'
||
c
==
'Q'
||
c
==
27
)
break
;
break
;
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录