Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
O
opencv
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
opencv
Commits
8b222ac0
Commit
8b222ac0
authored
Sep 06, 2016
by
Maksim Shabunin
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #7229 from catree:add_peopledetect_video_option
parents
a92aed45
aaa335b6
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
89 additions
and
27 deletions
+89
-27
peopledetect.cpp
samples/cpp/peopledetect.cpp
+89
-27
No files found.
samples/cpp/peopledetect.cpp
View file @
8b222ac0
#include <iostream>
#include <stdexcept>
#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/video.hpp>
#include <opencv2/videoio.hpp>
using
namespace
cv
;
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
=
{
"{help h||}"
"{image i| ../data/basketball2.png|input image name}"
"{directory d||images directory}"
"{ help h | | print help message }"
"{ image i | | specify input image}"
"{ 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
)
...
...
@@ -69,7 +65,12 @@ int main(int argc, char** argv)
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
;
}
...
...
@@ -78,6 +79,8 @@ int main(int argc, char** argv)
namedWindow
(
"people detector"
,
1
);
string
pattern_glob
=
""
;
string
video_filename
=
"../data/768x576.avi"
;
int
camera_id
=
-
1
;
if
(
parser
.
has
(
"directory"
))
{
pattern_glob
=
parser
.
get
<
string
>
(
"directory"
);
...
...
@@ -86,26 +89,85 @@ int main(int argc, char** argv)
{
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
;
String
folder
(
pattern_glob
);
glob
(
folder
,
filenames
);
//Read from video file
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
;
// Read current image
Mat
current_image
=
imread
(
*
it
);
String
folder
(
pattern_glob
);
glob
(
folder
,
filenames
);
}
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
())
continue
;
for
(;;)
{
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
);
int
c
=
waitKey
(
0
)
&
255
;
imshow
(
"people detector"
,
fram
e
);
int
c
=
waitKey
(
vc
.
isOpened
()
?
30
:
0
)
&
255
;
if
(
c
==
'q'
||
c
==
'Q'
||
c
==
27
)
break
;
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment