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
4c75872e
Commit
4c75872e
authored
Aug 22, 2016
by
Vadim Pisarevsky
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6937 from catree:add_peopledetect_sample
parents
5ee20518
42d5b1fb
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
115 additions
and
0 deletions
+115
-0
peopledetect.cpp
samples/cpp/peopledetect.cpp
+115
-0
No files found.
samples/cpp/peopledetect.cpp
0 → 100644
View file @
4c75872e
#include <opencv2/objdetect.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
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}"
};
static
void
detectAndDraw
(
const
HOGDescriptor
&
hog
,
Mat
&
img
)
{
vector
<
Rect
>
found
,
found_filtered
;
double
t
=
(
double
)
getTickCount
();
// Run the detector with default parameters. to get a higher hit-rate
// (and more false alarms, respectively), decrease the hitThreshold and
// groupThreshold (set groupThreshold to 0 to turn off the grouping completely).
hog
.
detectMultiScale
(
img
,
found
,
0
,
Size
(
8
,
8
),
Size
(
32
,
32
),
1.05
,
2
);
t
=
(
double
)
getTickCount
()
-
t
;
cout
<<
"detection time = "
<<
(
t
*
1000.
/
cv
::
getTickFrequency
())
<<
" ms"
<<
endl
;
for
(
size_t
i
=
0
;
i
<
found
.
size
();
i
++
)
{
Rect
r
=
found
[
i
];
size_t
j
;
// Do not add small detections inside a bigger detection.
for
(
j
=
0
;
j
<
found
.
size
();
j
++
)
if
(
j
!=
i
&&
(
r
&
found
[
j
])
==
r
)
break
;
if
(
j
==
found
.
size
()
)
found_filtered
.
push_back
(
r
);
}
for
(
size_t
i
=
0
;
i
<
found_filtered
.
size
();
i
++
)
{
Rect
r
=
found_filtered
[
i
];
// The HOG detector returns slightly larger rectangles than the real objects,
// so we slightly shrink the rectangles to get a nicer output.
r
.
x
+=
cvRound
(
r
.
width
*
0.1
);
r
.
width
=
cvRound
(
r
.
width
*
0.8
);
r
.
y
+=
cvRound
(
r
.
height
*
0.07
);
r
.
height
=
cvRound
(
r
.
height
*
0.8
);
rectangle
(
img
,
r
.
tl
(),
r
.
br
(),
cv
::
Scalar
(
0
,
255
,
0
),
3
);
}
}
int
main
(
int
argc
,
char
**
argv
)
{
CommandLineParser
parser
(
argc
,
argv
,
keys
);
if
(
parser
.
has
(
"help"
))
{
help
();
return
0
;
}
HOGDescriptor
hog
;
hog
.
setSVMDetector
(
HOGDescriptor
::
getDefaultPeopleDetector
());
namedWindow
(
"people detector"
,
1
);
string
pattern_glob
=
""
;
if
(
parser
.
has
(
"directory"
))
{
pattern_glob
=
parser
.
get
<
string
>
(
"directory"
);
}
else
if
(
parser
.
has
(
"image"
))
{
pattern_glob
=
parser
.
get
<
string
>
(
"image"
);
}
if
(
!
pattern_glob
.
empty
())
{
vector
<
String
>
filenames
;
String
folder
(
pattern_glob
);
glob
(
folder
,
filenames
);
for
(
vector
<
String
>::
const_iterator
it
=
filenames
.
begin
();
it
!=
filenames
.
end
();
++
it
)
{
cout
<<
"
\n
Read: "
<<
*
it
<<
endl
;
// Read current image
Mat
current_image
=
imread
(
*
it
);
if
(
current_image
.
empty
())
continue
;
detectAndDraw
(
hog
,
current_image
);
imshow
(
"people detector"
,
current_image
);
int
c
=
waitKey
(
0
)
&
255
;
if
(
c
==
'q'
||
c
==
'Q'
||
c
==
27
)
break
;
}
}
return
0
;
}
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