Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in
Toggle navigation
D
dlib
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
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
钟尚武
dlib
Commits
5ae170c4
Commit
5ae170c4
authored
Aug 22, 2014
by
Davis King
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added a face landmarking example program
parent
c9f24f3d
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
124 additions
and
0 deletions
+124
-0
CMakeLists.txt
examples/CMakeLists.txt
+1
-0
face_landmark_detection_ex.cpp
examples/face_landmark_detection_ex.cpp
+123
-0
No files found.
examples/CMakeLists.txt
View file @
5ae170c4
...
...
@@ -33,6 +33,7 @@ add_example(custom_trainer_ex)
add_example
(
dir_nav_ex
)
add_example
(
empirical_kernel_map_ex
)
add_example
(
face_detection_ex
)
add_example
(
face_landmark_detection_ex
)
add_example
(
fhog_ex
)
add_example
(
fhog_object_detector_ex
)
add_example
(
file_to_code_ex
)
...
...
examples/face_landmark_detection_ex.cpp
0 → 100644
View file @
5ae170c4
// The contents of this file are in the public domain. See LICENSE_FOR_EXAMPLE_PROGRAMS.txt
/*
This example program shows how to find frontal human faces in an image and
estimate their pose. The pose takes the form of 68 landmarks. These are
points on the face such as the corners of the mouth, along the eyebrows, on
the eyes, and so forth.
This face detector is made using the classic Histogram of Oriented
Gradients (HOG) feature combined with a linear classifier, an image pyramid,
and sliding window detection scheme. The pose estimator was created by
using dlib's implementation of the paper:
One Millisecond Face Alignment with an Ensemble of Regression Trees by
Vahid Kazemi and Josephine Sullivan, CVPR 2014
and was trained on the iBUG 300-W face landmark dataset.
Finally, note that the face detector is fastest when compiled with at least
SSE2 instructions enabled. So if you are using a PC with an Intel or AMD
chip then you should enable at least SSE2 instructions. If you are using
cmake to compile this program you can enable them by using one of the
following commands when you create the build project:
cmake path_to_dlib_root/examples -DUSE_SSE2_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_SSE4_INSTRUCTIONS=ON
cmake path_to_dlib_root/examples -DUSE_AVX_INSTRUCTIONS=ON
This will set the appropriate compiler options for GCC, clang, Visual
Studio, or the Intel compiler. If you are using another compiler then you
need to consult your compiler's manual to determine how to enable these
instructions. Note that AVX is the fastest but requires a CPU from at least
2011. SSE4 is the next fastest and is supported by most current machines.
*/
#include <dlib/image_processing/frontal_face_detector.h>
#include <dlib/image_processing/render_face_detections.h>
#include <dlib/image_processing.h>
#include <dlib/gui_widgets.h>
#include <dlib/image_io.h>
#include <iostream>
using
namespace
dlib
;
using
namespace
std
;
// ----------------------------------------------------------------------------------------
int
main
(
int
argc
,
char
**
argv
)
{
try
{
// This example takes in a shape model file and then a list of images to
// process. We will take these filenames in as command line arguments.
// Dlib comes with example images in the examples/faces folder so give
// those as arguments to this program.
if
(
argc
==
1
)
{
cout
<<
"Call this program like this:"
<<
endl
;
cout
<<
"./face_landmark_detection_ex shape_predictor_68_face_landmarks.dat faces/*.jpg"
<<
endl
;
cout
<<
"
\n
You can get the shape_predictor_68_face_landmarks.dat file from:
\n
"
;
cout
<<
"http://sourceforge.net/projects/dclib/files/dlib/v18.10/shape_predictor_68_face_landmarks.dat.bz2"
<<
endl
;
return
0
;
}
// We need a face detector. We will use this to get bounding boxes for
// each face in an image.
frontal_face_detector
detector
=
get_frontal_face_detector
();
// And we also need a shape_predictor. This takes as input an image and bounding
// box and outputs a fully landmarked face shape.
shape_predictor
sp
;
deserialize
(
argv
[
1
])
>>
sp
;
image_window
win
;
// Loop over all the images provided on the command line.
for
(
int
i
=
2
;
i
<
argc
;
++
i
)
{
cout
<<
"processing image "
<<
argv
[
i
]
<<
endl
;
array2d
<
rgb_pixel
>
img
;
load_image
(
img
,
argv
[
i
]);
// Make the image larger so we can detect small faces.
pyramid_up
(
img
);
// Now tell the face detector to give us a list of bounding boxes
// around all the faces in the image.
std
::
vector
<
rectangle
>
dets
=
detector
(
img
);
cout
<<
"Number of faces detected: "
<<
dets
.
size
()
<<
endl
;
// Now we will go ask the shape_predictor to tell us the pose of
// each face we detected.
std
::
vector
<
full_object_detection
>
shapes
;
for
(
unsigned
long
j
=
0
;
j
<
dets
.
size
();
++
j
)
{
full_object_detection
shape
=
sp
(
img
,
dets
[
j
]);
cout
<<
"number of parts: "
<<
shape
.
num_parts
()
<<
endl
;
cout
<<
"pixel position of first part: "
<<
shape
.
part
(
0
)
<<
endl
;
cout
<<
"pixel position of second part: "
<<
shape
.
part
(
1
)
<<
endl
;
// You get the idea, you can get all the face part locations if
// you want them. Here we just store them in shapes so we can
// put them on the screen.
shapes
.
push_back
(
shape
);
}
// Now lets view our face poses on the screen.
win
.
clear_overlay
();
win
.
set_image
(
img
);
win
.
add_overlay
(
render_face_detections
(
shapes
));
cout
<<
"Hit enter to process the next image..."
<<
endl
;
cin
.
get
();
}
}
catch
(
exception
&
e
)
{
cout
<<
"
\n
exception thrown!"
<<
endl
;
cout
<<
e
.
what
()
<<
endl
;
}
}
// ----------------------------------------------------------------------------------------
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